MCPcopy Create free account
hub / github.com/angular/dev-infra / run

Function run

github-actions/branch-manager/lib/main.ts:11–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9const targetLabelNames = new Set(Object.values(targetLabels).map((t) => t.name));
10
11async function run() {
12 if (context.eventName === 'push') {
13 const {ref} = context.payload as PushEvent;
14 if (!ref.startsWith('refs/heads/')) {
15 core.info('No evaluation needed as push is not to a branch');
16 return;
17 }
18
19 const branchName = ref.substring('refs/heads/'.length);
20
21 core.info(`Evaluating pull requests as a result of a push to branch '${branchName}'`);
22
23 const prs = await github().then((api) =>
24 api.paginate(
25 api.pulls.list,
26 {
27 repo: context.repo.repo,
28 owner: context.repo.owner,
29 state: 'open',
30 per_page: 100,
31 },
32 (pulls) => {
33 return pulls.data
34 .filter(({labels, base}) => {
35 return (
36 // Whether the pull request is slated to merge into the same branch as the triggering push.
37 base.ref === branchName &&
38 // Whether the pull request has the action: merge label.
39 labels.some(({name}) => name === actionLabels.ACTION_MERGE.name)
40 );
41 })
42 .map(({number}) => `${number}`);
43 },
44 ),
45 );
46 core.info(`Triggering ${prs.length} prs to be evaluated`);
47
48 // Invoke sequentially to avoid github secondary rate limits
49 // https://docs.github.com/en/rest/guides/best-practices-for-integrators?apiVersion=2022-11-28#dealing-with-secondary-rate-limits
50 for (const pr of prs) {
51 await createWorkflowForPullRequest({
52 repo: context.issue.repo,
53 owner: context.issue.owner,
54 pr,
55 });
56 }
57 }
58
59 if (context.eventName === 'pull_request_target') {
60 if (
61 ['opened', 'synchronize', 'reopened', 'ready_for_review'].includes(context.payload.action!)
62 ) {
63 const payload = context.payload as PullRequestEvent;
64 const hasMergeLabel = payload.pull_request.labels.some(
65 ({name}) => name === actionLabels.ACTION_MERGE.name,
66 );
67 if (hasMergeLabel) {
68 await createWorkflowForPullRequest({

Callers 1

main.tsFile · 0.70

Calls 3

githubFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected