Skip to content

Commit

Permalink
optimise Integrated label managenent logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Yegoroff committed Oct 27, 2022
1 parent 3d6e995 commit c85b19c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pr-integration-action",
"version": "1.0.0",
"version": "1.0.1",
"description": "GitHub action that integrates approved PRs into specified branch",
"author": "Brokermint",
"license": "MIT",
Expand Down
20 changes: 10 additions & 10 deletions src/integration-merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ async function integrationMerge({octokit, token, integrationBranch, approveLabel
await git.push(path, true, integrationBranch, integrationBranch);

// clear labels from not merged PRs and set labels to merged ones
await clearIntegratedLabels({octokit, pullRequests: openRequests, integratedLabel, repo, owner});
await setIntegratedLabels({octokit, pullRequests: mergedPrs, integratedLabel, repo, owner});
await updateIntegratedLabels({octokit, integratedRequests: mergedPrs, allRequests: openRequests, integratedLabel, repo, owner});

core.info('Integration merge complete');
return true;
Expand Down Expand Up @@ -243,9 +242,12 @@ async function writeIntegrationVersion(path) {
}


async function clearIntegratedLabels({octokit, pullRequests, integratedLabel, repo, owner}) {
core.info("Clear integration labels");
for (const pullRequest of pullRequests) {
async function updateIntegratedLabels({octokit, integratedRequests, allRequests, integratedLabel, repo, owner}) {
core.info("Update Integrated labels");

// remove IntegratedLabel for allRequests that's not in integratedRequests
const nonIntegratedPrs = allRequests.filter(pr => !integratedRequests.includes(pr));
for (const pullRequest of nonIntegratedPrs) {
try {
await octokit.issues.removeLabel({ owner, repo, issue_number: pullRequest.number, name: integratedLabel});
}
Expand All @@ -254,14 +256,12 @@ async function clearIntegratedLabels({octokit, pullRequests, integratedLabel, re
core.debug(e);
}
}
}


async function setIntegratedLabels({octokit, pullRequests, integratedLabel, repo, owner}) {
core.info("Set integration labels");
for (const pullRequest of pullRequests) {
// add IntegratedLabel for allRequests that are in integratedRequests
for (const pullRequest of integratedRequests) {
await octokit.issues.addLabels({ owner, repo, issue_number: pullRequest.number, labels: [integratedLabel]});
}
}


export default integrationMerge;

0 comments on commit c85b19c

Please sign in to comment.