bitbucket-v2
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -21,2 +21,12 @@ const Request = require('./request').Request; | ||
this.constants = { | ||
pullRequest: { | ||
states: { | ||
DECLINED: 'DECLINED', | ||
MERGED: 'MERGED', | ||
OPEN: 'OPEN' | ||
} | ||
} | ||
}; | ||
this.repositories = new (require('./repositories'))(this); | ||
@@ -123,2 +133,6 @@ this.user = new (require('./user'))(this); | ||
getNextPage(response, callback) { | ||
if (!this.hasNextPage(response)) { | ||
throw new Error('getNextPage: argument has no next page url. Call hasNextPage first to guard this method call.'); | ||
} | ||
this.request.doPrebuiltSend(response.next, callback); | ||
@@ -136,2 +150,6 @@ } | ||
getPreviousPage(response, callback) { | ||
if (!this.hasPreviousPage(response)) { | ||
throw new Error('getPreviousPage: argument has no next page url. Call hasPreviousPage first to guard this method call.'); | ||
} | ||
this.request.doPrebuiltSend(response.previous, callback); | ||
@@ -138,0 +156,0 @@ } |
@@ -0,1 +1,3 @@ | ||
const _ = require('lodash'); | ||
const AbstractApi = require('./abstract_api'); | ||
@@ -26,2 +28,35 @@ | ||
/** | ||
* Get the pull requests for a single repo | ||
* | ||
* @param {String} repo owner | ||
* @param {String} slug (name) of the repo. | ||
* @param {$api.constants.pullRequest.states or Array thereof} The PR state. If invalid or undefined, defaults to OPEN | ||
*/ | ||
getPullRequests(username, repoSlug, state, callback) { | ||
const { constants } = this.$api; | ||
let stateArray = state; | ||
if (!stateArray) { | ||
stateArray = [constants.pullRequest.states.OPEN]; | ||
} | ||
else if (!_.isArray(stateArray)) { | ||
stateArray = [stateArray]; | ||
} | ||
const hasInvalidState = _.find(state, (stateElement) => !_.contains(constants.pullRequest.states, stateElement)); | ||
if (hasInvalidState) { | ||
stateArray = [constants.pullRequest.states.OPEN]; | ||
} | ||
const apiParameters = { | ||
state: stateArray.join(',') | ||
}; | ||
this.$api.get( | ||
'repositories/' + encodeURI(username) + '/' + encodeURI(repoSlug) + '/pullrequests', | ||
apiParameters, null, | ||
this.$createListener(callback) | ||
); | ||
} | ||
/** | ||
* Get the repositories of a user | ||
@@ -91,3 +126,3 @@ * | ||
getParentFromResponse(response, callback) { | ||
const prebuiltURL = response && response.parent && response.parent.links && response.parent.links.self && response.parent.links.self.href; | ||
const prebuiltURL = _.get(response, 'parent.links.self.href'); | ||
@@ -94,0 +129,0 @@ if (!prebuiltURL) { |
@@ -29,2 +29,12 @@ 'use strict'; | ||
this.constants = { | ||
pullRequest: { | ||
states: { | ||
DECLINED: 'DECLINED', | ||
MERGED: 'MERGED', | ||
OPEN: 'OPEN' | ||
} | ||
} | ||
}; | ||
this.repositories = new (require('./repositories'))(this); | ||
@@ -145,2 +155,6 @@ this.user = new (require('./user'))(this); | ||
value: function getNextPage(response, callback) { | ||
if (!this.hasNextPage(response)) { | ||
throw new Error('getNextPage: argument has no next page url. Call hasNextPage first to guard this method call.'); | ||
} | ||
this.request.doPrebuiltSend(response.next, callback); | ||
@@ -161,2 +175,6 @@ } | ||
value: function getPreviousPage(response, callback) { | ||
if (!this.hasPreviousPage(response)) { | ||
throw new Error('getPreviousPage: argument has no next page url. Call hasPreviousPage first to guard this method call.'); | ||
} | ||
this.request.doPrebuiltSend(response.previous, callback); | ||
@@ -163,0 +181,0 @@ } |
@@ -11,2 +11,4 @@ 'use strict'; | ||
var _ = require('lodash'); | ||
var AbstractApi = require('./abstract_api'); | ||
@@ -41,2 +43,36 @@ | ||
/** | ||
* Get the pull requests for a single repo | ||
* | ||
* @param {String} repo owner | ||
* @param {String} slug (name) of the repo. | ||
* @param {$api.constants.pullRequest.states or Array thereof} The PR state. If invalid or undefined, defaults to OPEN | ||
*/ | ||
}, { | ||
key: 'getPullRequests', | ||
value: function getPullRequests(username, repoSlug, state, callback) { | ||
var constants = this.$api.constants; | ||
var stateArray = state; | ||
if (!stateArray) { | ||
stateArray = [constants.pullRequest.states.OPEN]; | ||
} else if (!_.isArray(stateArray)) { | ||
stateArray = [stateArray]; | ||
} | ||
var hasInvalidState = _.find(state, function (stateElement) { | ||
return !_.contains(constants.pullRequest.states, stateElement); | ||
}); | ||
if (hasInvalidState) { | ||
stateArray = [constants.pullRequest.states.OPEN]; | ||
} | ||
var apiParameters = { | ||
state: stateArray.join(',') | ||
}; | ||
this.$api.get('repositories/' + encodeURI(username) + '/' + encodeURI(repoSlug) + '/pullrequests', apiParameters, null, this.$createListener(callback)); | ||
} | ||
/** | ||
* Get the repositories of a user | ||
@@ -106,3 +142,3 @@ * | ||
value: function getParentFromResponse(response, callback) { | ||
var prebuiltURL = response && response.parent && response.parent.links && response.parent.links.self && response.parent.links.self.href; | ||
var prebuiltURL = _.get(response, 'parent.links.self.href'); | ||
@@ -109,0 +145,0 @@ if (!prebuiltURL) { |
{ | ||
"name" : "bitbucket-v2", | ||
"version" : "0.1.1", | ||
"description" : "Wrapper for the BitBucket API v2", | ||
"author": "Jordan Wallet <jjwallet@gmail.com>", | ||
"homepage": "https://github.com/Mr-Wallet/node-bitbucket-v2.git", | ||
"main" : "dist/index.js", | ||
"scripts": { | ||
"compile": "babel --presets es2015 -d ./dist ./bitbucket", | ||
"lint": "eslint ./bitbucket --quiet", | ||
"prepublish": "npm run compile" | ||
}, | ||
"repository" : { | ||
"type" : "git", | ||
"url" : "http://github.com/Mr-Wallet/node-bitbucket-v2.git" | ||
}, | ||
"engine" : ["node >=5.5.0"], | ||
"dependencies": { | ||
"asyncjs": "~0.0.10", | ||
"oauth": "~0.9.14" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.2.0", | ||
"babel-preset-es2015": "^6.1.18", | ||
"eslint": "^1.10.3", | ||
"eslint-config-airbnb": "^2.0.0", | ||
"eslint-plugin-react": "^3.11.2" | ||
}, | ||
"licenses": [{ | ||
"type": "The MIT License", | ||
"url": "http://www.opensource.org/licenses/mit-license.php" | ||
}] | ||
"name": "bitbucket-v2", | ||
"version": "0.1.2", | ||
"description": "Wrapper for the BitBucket API v2", | ||
"author": "Jordan Wallet <jjwallet@gmail.com>", | ||
"homepage": "https://github.com/Mr-Wallet/node-bitbucket-v2.git", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"compile": "babel --presets es2015 -d ./dist ./bitbucket", | ||
"lint": "eslint ./bitbucket --quiet", | ||
"prepublish": "npm run compile" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "http://github.com/Mr-Wallet/node-bitbucket-v2.git" | ||
}, | ||
"engine": [ | ||
"node >=5.5.0" | ||
], | ||
"dependencies": { | ||
"asyncjs": "~0.0.10", | ||
"lodash": "^3.10.1", | ||
"oauth": "~0.9.14" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.2.0", | ||
"babel-preset-es2015": "^6.1.18", | ||
"eslint": "^1.10.3", | ||
"eslint-config-airbnb": "^2.0.0", | ||
"eslint-plugin-react": "^3.11.2" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "The MIT License", | ||
"url": "http://www.opensource.org/licenses/mit-license.php" | ||
} | ||
] | ||
} |
55678
1453
3
+ Addedlodash@^3.10.1
+ Addedlodash@3.10.1(transitive)