bitbucket-v2
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -14,2 +14,19 @@ const _ = require('lodash'); | ||
/** | ||
* Create a new pull request | ||
* | ||
* @param {String} repo owner | ||
* @param {String} slug (name) of the repo. | ||
* @param {Object} pullRequest The PR POST body as specified by Bitbucket's API documentation | ||
*/ | ||
createPullRequest(username, repoSlug, pullRequest, callback) { | ||
this.$api.post( | ||
// This may be the only API call in the entire Bitbucket specs that has a / at the end. | ||
// It probably doesn't matter, but the docs will be strictly followed just in case. | ||
'repositories/' + encodeURI(username) + '/' + encodeURI(repoSlug) + '/pullrequests/', | ||
pullRequest, null, | ||
this.$createListener(callback) | ||
); | ||
} | ||
/** | ||
* Get the info for a single repo | ||
@@ -29,2 +46,17 @@ * | ||
/** | ||
* Get the branch info for a single repo | ||
* | ||
* @param {String} repo owner | ||
* @param {String} slug (name) of the repo. | ||
*/ | ||
//TODO confirm this works | ||
getBranches(username, repoSlug, callback) { | ||
this.$api.get( | ||
'repositories/' + encodeURI(username) + '/' + encodeURI(repoSlug) + '/refs/branches', | ||
null, null, | ||
this.$createListener(callback) | ||
); | ||
} | ||
/** | ||
* Get the pull requests for a single repo | ||
@@ -31,0 +63,0 @@ * |
@@ -32,3 +32,3 @@ const querystring = require('querystring'); | ||
this.$options = {}; | ||
for (let key in this.$defaults) { | ||
for (const key in this.$defaults) { | ||
this.$options[key] = options[key] !== undefined ? options[key] : this.$defaults[key]; | ||
@@ -60,4 +60,4 @@ } | ||
*/ | ||
this.getOption = function getOption(name, defaultValue) { | ||
defaultValue = defaultValue === undefined ? null: defaultValue; | ||
this.getOption = function getOption(name, _defaultValue) { | ||
const defaultValue = _defaultValue === undefined ? null : _defaultValue; | ||
return this.$options[name] ? this.$options[name] : defaultValue; | ||
@@ -98,3 +98,3 @@ }; | ||
this.doSend(apiPath, parameters, httpMethod, (err, response) => { | ||
this.doSend(apiPath, parameters, httpMethod, (err, _response) => { | ||
if (err) { | ||
@@ -107,3 +107,3 @@ if (callback) { | ||
response = this.decodeResponse(response); | ||
const response = this.decodeResponse(_response); | ||
@@ -120,7 +120,7 @@ if (initialOptions) { | ||
/** | ||
* Send a request to the server using a URL received from the API directly, receive a response | ||
* | ||
* @param {String} $prebuiltURL Request URL given by a previous API call | ||
*/ | ||
/** | ||
* Send a request to the server using a URL received from the API directly, receive a response | ||
* | ||
* @param {String} $prebuiltURL Request URL given by a previous API call | ||
*/ | ||
this.doPrebuiltSend = function doPrebuiltSend(prebuiltURL, callback) { | ||
@@ -207,6 +207,6 @@ const port = this.$options.proxy_host ? this.$options.proxy_port || 3128 : this.$options.http_port || 443; | ||
*/ | ||
this.doSend = function doSend(apiPath, parameters, httpMethod, callback) { | ||
httpMethod = httpMethod.toUpperCase(); | ||
const host = this.$options.proxy_host ? this.$options.proxy_host: this.$options.hostname; | ||
const port = this.$options.proxy_host ? this.$options.proxy_port || 3128: this.$options.http_port || 443; | ||
this.doSend = function doSend(apiPath, parameters, _httpMethod, callback) { | ||
const httpMethod = _httpMethod.toUpperCase(); | ||
const host = this.$options.proxy_host ? this.$options.proxy_host : this.$options.hostname; | ||
const port = this.$options.proxy_host ? this.$options.proxy_port || 3128 : this.$options.http_port || 443; | ||
@@ -220,16 +220,13 @@ const headers = { | ||
}; | ||
const getParams = httpMethod !== 'POST' ? parameters : {}; | ||
const postParams = httpMethod === 'POST' ? parameters : {}; | ||
const getQuery = querystring.stringify(getParams); | ||
const postQuery = querystring.stringify(postParams); | ||
let query; | ||
let path = this.$options.path + '/' + apiPath.replace(/\/*$/, ''); | ||
if (getQuery) { | ||
path += '?' + getQuery; | ||
if (httpMethod === 'POST') { | ||
query = JSON.stringify(parameters); | ||
headers['Content-Type'] = 'application/json'; | ||
headers['Content-Length'] = query.length; | ||
} | ||
if (postQuery) { | ||
headers['Content-Length'] = postQuery.length; | ||
else { | ||
query = querystring.stringify(parameters); | ||
path += '?' + query; | ||
} | ||
@@ -297,3 +294,3 @@ | ||
if (httpMethod === 'POST') { | ||
request.write(postQuery); | ||
request.write(query); | ||
} | ||
@@ -300,0 +297,0 @@ |
@@ -29,9 +29,26 @@ 'use strict'; | ||
/** | ||
* Get the info for a single repo | ||
* Create a new pull request | ||
* | ||
* @param {String} repo owner | ||
* @param {String} slug (name) of the repo. | ||
* @param {Object} pullRequest The PR POST body as specified by Bitbucket's API documentation | ||
*/ | ||
_createClass(RepositoriesApi, [{ | ||
key: 'createPullRequest', | ||
value: function createPullRequest(username, repoSlug, pullRequest, callback) { | ||
this.$api.post( | ||
// This may be the only API call in the entire Bitbucket specs that has a / at the end. | ||
// It probably doesn't matter, but the docs will be strictly followed just in case. | ||
'repositories/' + encodeURI(username) + '/' + encodeURI(repoSlug) + '/pullrequests/', pullRequest, null, this.$createListener(callback)); | ||
} | ||
/** | ||
* Get the info for a single repo | ||
* | ||
* @param {String} repo owner | ||
* @param {String} slug (name) of the repo. | ||
*/ | ||
}, { | ||
key: 'get', | ||
@@ -43,2 +60,16 @@ value: function get(username, repoSlug, callback) { | ||
/** | ||
* Get the branch info for a single repo | ||
* | ||
* @param {String} repo owner | ||
* @param {String} slug (name) of the repo. | ||
*/ | ||
//TODO confirm this works | ||
}, { | ||
key: 'getBranches', | ||
value: function getBranches(username, repoSlug, callback) { | ||
this.$api.get('repositories/' + encodeURI(username) + '/' + encodeURI(repoSlug) + '/refs/branches', null, null, this.$createListener(callback)); | ||
} | ||
/** | ||
* Get the pull requests for a single repo | ||
@@ -45,0 +76,0 @@ * |
@@ -63,4 +63,4 @@ 'use strict'; | ||
*/ | ||
this.getOption = function getOption(name, defaultValue) { | ||
defaultValue = defaultValue === undefined ? null : defaultValue; | ||
this.getOption = function getOption(name, _defaultValue) { | ||
var defaultValue = _defaultValue === undefined ? null : _defaultValue; | ||
return this.$options[name] ? this.$options[name] : defaultValue; | ||
@@ -108,3 +108,3 @@ }; | ||
this.doSend(apiPath, parameters, httpMethod, function (err, response) { | ||
this.doSend(apiPath, parameters, httpMethod, function (err, _response) { | ||
if (err) { | ||
@@ -117,3 +117,3 @@ if (callback) { | ||
response = _this.decodeResponse(response); | ||
var response = _this.decodeResponse(_response); | ||
@@ -216,4 +216,4 @@ if (initialOptions) { | ||
*/ | ||
this.doSend = function doSend(apiPath, parameters, httpMethod, callback) { | ||
httpMethod = httpMethod.toUpperCase(); | ||
this.doSend = function doSend(apiPath, parameters, _httpMethod, callback) { | ||
var httpMethod = _httpMethod.toUpperCase(); | ||
var host = this.$options.proxy_host ? this.$options.proxy_host : this.$options.hostname; | ||
@@ -229,17 +229,14 @@ var port = this.$options.proxy_host ? this.$options.proxy_port || 3128 : this.$options.http_port || 443; | ||
}; | ||
var getParams = httpMethod !== 'POST' ? parameters : {}; | ||
var postParams = httpMethod === 'POST' ? parameters : {}; | ||
var getQuery = querystring.stringify(getParams); | ||
var postQuery = querystring.stringify(postParams); | ||
var query = undefined; | ||
var path = this.$options.path + '/' + apiPath.replace(/\/*$/, ''); | ||
if (getQuery) { | ||
path += '?' + getQuery; | ||
if (httpMethod === 'POST') { | ||
query = JSON.stringify(parameters); | ||
headers['Content-Type'] = 'application/json'; | ||
headers['Content-Length'] = query.length; | ||
} else { | ||
query = querystring.stringify(parameters); | ||
path += '?' + query; | ||
} | ||
if (postQuery) { | ||
headers['Content-Length'] = postQuery.length; | ||
} | ||
var getOptions = { | ||
@@ -304,3 +301,3 @@ host: host, | ||
if (httpMethod === 'POST') { | ||
request.write(postQuery); | ||
request.write(query); | ||
} | ||
@@ -307,0 +304,0 @@ |
{ | ||
"name": "bitbucket-v2", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Wrapper for the BitBucket API v2", | ||
@@ -5,0 +5,0 @@ "author": "Jordan Wallet <jjwallet@gmail.com>", |
57784
1509