diff --git a/src/github.js b/src/github.js index 431047a760ce0506003d0d08cebd5b7b00c60ff6..1d726856ba51e3610f8699986639f88e19ab283d 100644 --- a/src/github.js +++ b/src/github.js @@ -56,14 +56,9 @@ module.exports = { console.error('Error checking if PR already existed'); }); }, - getFile: function(filePath, branchName) { - branchName = branchName || config.baseBranch; - return ghGot(`repos/${config.repoName}/contents/${filePath}?ref=${branchName}`, { - token: config.token, - }); - }, + getFile: getFile, getFileContents: function(filePath, branchName) { - return this.getFile(filePath, branchName).then(res => { + return getFile(filePath, branchName).then(res => { return JSON.parse(new Buffer(res.body.content, 'base64').toString()); }); }, @@ -98,3 +93,10 @@ module.exports = { }); }, }; + +function getFile(filePath, branchName) { + branchName = branchName || config.baseBranch; + return ghGot(`repos/${config.repoName}/contents/${filePath}?ref=${branchName}`, { + token: config.token, + }); +} diff --git a/src/index.js b/src/index.js index e2dfe0f6509b8b3055cb2397eb0fdad1c7c69856..1dcc25649ff1bd4a828764609987f1632e302256 100644 --- a/src/index.js +++ b/src/index.js @@ -22,18 +22,25 @@ if (process.argv.length < 3 || process.argv.length > 4) { // Process command line arguments const repoName = process.argv[2]; const userName = repoName.split('/')[0]; -const packageFile = process.argv[3] || 'package.json'; +const packageFile = process.argv[3] || 'package.json';; npm.init(config.verbose); let basePackageJson; -github.init(token, repoName, config.baseBranch, config.verbose).then(() => { - // Get the base package.json - return github.getFileContents(packageFile); -}) +github.init(token, repoName, config.baseBranch, config.verbose) +.then(getPackageFile) .then(npm.getAllDependencyUpgrades) -.then((upgrades) => { +.then(processUpgradesSequentially) +.catch(err => { + console.log('updateDependency error: ' + err); +}); + +function getPackageFile() { + return github.getFileContents(packageFile); +} + +function processUpgradesSequentially(upgrades) { if (config.verbose) { console.log('All upgrades: ' + JSON.stringify(upgrades)); } @@ -45,9 +52,7 @@ github.init(token, repoName, config.baseBranch, config.verbose).then(() => { return updateDependency(upgrade.depType, upgrade.depName, upgrade.currentVersion, upgrade.nextVersion); }); }, Promise.resolve()); -}).catch(err => { - console.log('updateDependency error: ' + err); -}); +} function updateDependency(depType, depName, currentVersion, nextVersion) { const nextVersionMajor = semver.major(nextVersion);