Skip to content
Snippets Groups Projects
Commit 1896512b authored by Rhys Arkins's avatar Rhys Arkins
Browse files

Refactor promise chains

parent 7723e860
No related branches found
No related tags found
No related merge requests found
......@@ -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,
});
}
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment