Skip to content

Commit 4e42427

Browse files
committed
feat(github-actions): only request branch manager checks for prs that need it
Only request the branch manager to check the pull requests that target the same branch as the branch that was updated for `push` events.
1 parent 4425eed commit 4e42427

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

github-actions/branch-manager/lib/main.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,29 @@ async function run() {
1616
return;
1717
}
1818

19-
if (ref !== 'refs/heads/main') {
20-
// TODO: support pushes to all releasable branches rather than just main.
21-
core.info('Skipping evaluation as the push does not affect the main branch');
22-
return;
23-
}
24-
2519
core.info(`Evaluating pull requests as a result of a push to '${ref}'`);
2620

27-
const mergeReadyPrQuery =
28-
`repo:${context.repo.owner}/${context.repo.repo} ` +
29-
`is:pr ` +
30-
`is:open ` +
31-
`label:"${actionLabels.ACTION_MERGE.name}"`;
32-
3321
const prs = await github().then((api) =>
3422
api.paginate(
35-
api.search.issuesAndPullRequests,
23+
api.pulls.list,
3624
{
37-
q: mergeReadyPrQuery,
25+
repo: context.repo.repo,
26+
owner: context.repo.owner,
27+
state: 'open',
28+
per_page: 100,
29+
},
30+
(pulls) => {
31+
return pulls.data
32+
.filter(({labels, base}) => {
33+
return (
34+
// Whether the pull request is slated to merge into the same branch as the triggering push.
35+
base.ref === ref &&
36+
// Whether the pull request has the action: merge label.
37+
labels.some(({name}) => name === actionLabels.ACTION_MERGE.name)
38+
);
39+
})
40+
.map(({number}) => `${number}`);
3841
},
39-
(issues) => issues.data.map((i) => `${i.number}`),
4042
),
4143
);
4244
core.info(`Triggering ${prs.length} prs to be evaluated`);

github-actions/branch-manager/main.js

Lines changed: 15 additions & 9 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)