diff --git a/package.json b/package.json index 0bc8822..41c75ee 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/integration-merge.js b/src/integration-merge.js index 8446c95..2a9563e 100644 --- a/src/integration-merge.js +++ b/src/integration-merge.js @@ -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; @@ -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}); } @@ -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;