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

Simplify check for closed pr

parent 887ccfd2
Branches
No related tags found
No related merge requests found
......@@ -45,29 +45,13 @@ module.exports = {
}
});
},
checkPrExists(branchName, prTitle) {
if (config.verbose) {
console.log(`Checking if branch/PR exists: ${branchName} / ${prTitle}`);
}
return ghGot(`repos/${config.repoName}/pulls?state=closed&head=${config.userName}:${branchName}`, { token: config.token })
.then(res => {
if (config.verbose) {
console.log(`Got ${res.body.length} results for ${branchName}`);
}
let prAlreadyExists = false;
res.body.forEach(function(result) {
if (result.title === prTitle && result.head.label === `${config.userName}:${branchName}`) {
prAlreadyExists = true;
}
checkForClosedPr(branchName, prTitle) {
return ghGot(`repos/${config.repoName}/pulls?state=closed&head=${config.userName}:${branchName}`, {
token: config.token
}).then(res => {
return res.body.some((pr) => {
return pr.title === prTitle && pr.head.label === `${config.userName}:${branchName}`;
});
if (config.verbose) {
if (prAlreadyExists) {
console.log(`PR already exists for ${branchName}`);
} else {
console.log(`PR doesn't exist for ${branchName}`);
}
}
return prAlreadyExists;
}).catch((err) => {
console.error('Error checking if PR already existed');
});
......@@ -83,8 +67,8 @@ module.exports = {
return JSON.parse(new Buffer(res.body.content, 'base64').toString());
});
},
getPrNo: function(branchName) {
return ghGot(`repos/${config.repoName}/pulls?base=${config.baseBranch}&head=${config.userName}:${branchName}`, {
getPrNo: function(branchName, state = 'open') {
return ghGot(`repos/${config.repoName}/pulls?state=${state}&base=${config.baseBranch}&head=${config.userName}:${branchName}`, {
token: config.token,
}).then(res => {
let prNo = 0;
......
......@@ -60,7 +60,7 @@ function updateDependency(depType, depName, currentVersion, nextVersion) {
prTitle = config.templates.prTitleMinor({ depType, depName, currentVersion, nextVersion, nextVersionMajor });
}
// Check if same PR already exists or existed
return github.checkPrExists(branchName, prTitle).then((prExisted) => {
return github.checkForClosedPr(branchName, prTitle).then((prExisted) => {
if (!prExisted) {
return writeUpdates(depType, depName, branchName, prTitle, currentVersion, nextVersion);
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment