sync-to-github
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -44,3 +44,2 @@ var GitHubApi = require('github'); | ||
var pathParts = _.compact(options.repoPath.split('/')); | ||
var branch = options.branch || 'master'; | ||
@@ -53,3 +52,3 @@ return Promise.resolve().then(function() { | ||
}).then(function(newTargetTree) { | ||
return getLatestCommit(gitData, branch).then(function(commit) { | ||
return getLatestCommit(gitData, options.branch).then(function(commit) { | ||
var treeCache = {}; | ||
@@ -63,3 +62,3 @@ return gitData('getTree', { sha: commit.tree.sha }).then(function(rootTree) { | ||
return gitData('createCommit', { | ||
message: 'xcxc', | ||
message: options.message, | ||
tree: newRootTree.sha, | ||
@@ -70,3 +69,3 @@ parents: [commit.sha] | ||
return gitData('updateReference', { | ||
ref: 'heads/' + branch, | ||
ref: 'heads/' + options.branch, | ||
sha: newCommit.sha | ||
@@ -76,13 +75,3 @@ }); | ||
if (options.pullToBranch) { | ||
var lines = options.message.split('\n'); | ||
var pullRequestsAsync = Promise.promisify( | ||
github.pullRequests.create, github.pullRequests); | ||
return pullRequestsAsync({ | ||
user: options.user, | ||
repo: options.repo, | ||
title: lines[0], | ||
body: lines.slice(1).join('\n'), | ||
base: options.pullToBranch, | ||
head: branch | ||
}); | ||
return createPullRequest(github, options); | ||
} | ||
@@ -102,2 +91,4 @@ }); | ||
function validateOptions(options) { | ||
options.branch = options.branch || 'master'; | ||
if (typeof(options.user) !== 'string') { | ||
@@ -119,3 +110,3 @@ throw new Error('Must pass owner of repo in `user`'); | ||
if (typeof(options.pullToBranch) !== 'string') { | ||
if (options.pullToBranch === (options.branch || 'master')) { | ||
if (options.pullToBranch === options.branch) { | ||
throw new Error( | ||
@@ -185,5 +176,5 @@ 'Pull request to branch named in `pullToBranch` must be' + | ||
var loggedParams = _.merge({}, params); | ||
if (typeof(loggedParams.contents) === 'string') { | ||
loggedParams.contents = | ||
'[' + loggedParams.contents.length + ' characters]'; | ||
if (typeof(loggedParams.content) === 'string') { | ||
loggedParams.content = | ||
'[' + loggedParams.content.length + ' characters]'; | ||
} | ||
@@ -354,2 +345,30 @@ debug(options, 'gitdata', name, loggedParams); | ||
/** | ||
* @param github {GitHubApi} | ||
* @param options {Object} options for sync request | ||
* @returns {Promise} Complete once the pull request is created | ||
*/ | ||
function createPullRequest(github, options) { | ||
var lines = options.message.split('\n'); | ||
var pullRequestsAsync = Promise.promisify( | ||
github.pullRequests.create, github.pullRequests); | ||
return pullRequestsAsync({ | ||
user: options.user, | ||
repo: options.repo, | ||
title: lines[0], | ||
body: lines.slice(1).join('\n'), | ||
base: options.pullToBranch, | ||
head: options.branch | ||
}).catch(function(err) { | ||
if (typeof(err.errors) === 'object' && | ||
/already exists/.test(err.errors[0].message)) { | ||
// This is ok, it's a legitimate way to fail if we've already got | ||
// an outstanding pull request. | ||
// TODO: update pull request with new message | ||
console.log('Pull request for branch already exists, ignoring.'); | ||
} else { | ||
throw err; | ||
} | ||
}); | ||
} | ||
@@ -356,0 +375,0 @@ module.exports = { |
{ | ||
"name": "sync-to-github", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Easily sync a directory of files to a GitHub repo using the GitHub API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15022
344