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
Tags 34.150.0
No related merge requests found
...@@ -56,14 +56,9 @@ module.exports = { ...@@ -56,14 +56,9 @@ module.exports = {
console.error('Error checking if PR already existed'); console.error('Error checking if PR already existed');
}); });
}, },
getFile: function(filePath, branchName) { getFile: getFile,
branchName = branchName || config.baseBranch;
return ghGot(`repos/${config.repoName}/contents/${filePath}?ref=${branchName}`, {
token: config.token,
});
},
getFileContents: function(filePath, branchName) { 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()); return JSON.parse(new Buffer(res.body.content, 'base64').toString());
}); });
}, },
...@@ -98,3 +93,10 @@ module.exports = { ...@@ -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) { ...@@ -22,18 +22,25 @@ if (process.argv.length < 3 || process.argv.length > 4) {
// Process command line arguments // Process command line arguments
const repoName = process.argv[2]; const repoName = process.argv[2];
const userName = repoName.split('/')[0]; const userName = repoName.split('/')[0];
const packageFile = process.argv[3] || 'package.json'; const packageFile = process.argv[3] || 'package.json';;
npm.init(config.verbose); npm.init(config.verbose);
let basePackageJson; let basePackageJson;
github.init(token, repoName, config.baseBranch, config.verbose).then(() => { github.init(token, repoName, config.baseBranch, config.verbose)
// Get the base package.json .then(getPackageFile)
return github.getFileContents(packageFile);
})
.then(npm.getAllDependencyUpgrades) .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) { if (config.verbose) {
console.log('All upgrades: ' + JSON.stringify(upgrades)); console.log('All upgrades: ' + JSON.stringify(upgrades));
} }
...@@ -45,9 +52,7 @@ github.init(token, repoName, config.baseBranch, config.verbose).then(() => { ...@@ -45,9 +52,7 @@ github.init(token, repoName, config.baseBranch, config.verbose).then(() => {
return updateDependency(upgrade.depType, upgrade.depName, upgrade.currentVersion, upgrade.nextVersion); return updateDependency(upgrade.depType, upgrade.depName, upgrade.currentVersion, upgrade.nextVersion);
}); });
}, Promise.resolve()); }, Promise.resolve());
}).catch(err => { }
console.log('updateDependency error: ' + err);
});
function updateDependency(depType, depName, currentVersion, nextVersion) { function updateDependency(depType, depName, currentVersion, nextVersion) {
const nextVersionMajor = semver.major(nextVersion); const nextVersionMajor = semver.major(nextVersion);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment