1- name : PR Size Enforcement
1+ name : PR Size Enforcement - Check
22
33on :
44 pull_request :
55 types : [labeled, unlabeled, opened, edited, synchronize]
66
77permissions :
88 contents : read
9- pull-requests : write
109
1110jobs :
12- enforce -xl-justification :
13- name : Enforce XL PR Justification
11+ check -xl-justification :
12+ name : Check XL PR Justification
1413 runs-on : ubuntu-latest
15- if : contains(github.event.pull_request.labels.*.name, 'size/XL')
1614 steps :
17- - name : Checkout repository
18- uses : actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5
19-
20- - name : Check for justification
21- id : check
22- uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
23- with :
24- script : |
25- const prBody = context.payload.pull_request.body || '';
26-
27- // Look for the justification section header
28- const hasJustification = /##\s*Large PR Justification/i.test(prBody);
29-
30- console.log('PR Body length:', prBody.length);
31- console.log('Has justification section:', hasJustification);
32-
33- return hasJustification;
34-
35- - name : Request changes if no justification
36- if : steps.check.outputs.result == 'false'
15+ - name : Get PR details
16+ id : pr
3717 uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
3818 with :
3919 script : |
40- const prNumber = context.payload.pull_request.number;
41-
42- // Check if we already have a review requesting changes
43- const reviews = await github.rest.pulls.listReviews({
44- owner: context.repo.owner,
45- repo: context.repo.repo,
46- pull_number: prNumber
47- });
48-
49- const botReview = reviews.data.find(review =>
50- review.user.login === 'github-actions[bot]' &&
51- review.state === 'CHANGES_REQUESTED'
52- );
53-
54- if (botReview) {
55- console.log('Already requested changes in review:', botReview.id);
56- return;
57- }
58-
59- // Read the message template from file
60- const fs = require('fs');
61- const template = fs.readFileSync('.github/workflows/pr-size-justification-template.md', 'utf8');
62- const contributingLink = `https://github.com/${context.repo.owner}/${context.repo.repo}/blob/main/CONTRIBUTING.md#code-quality-expectations`;
63- const message = template.replace('CONTRIBUTING_LINK', contributingLink);
64-
65- // Request changes with explanation
66- await github.rest.pulls.createReview({
20+ const pr = await github.rest.pulls.get({
6721 owner: context.repo.owner,
6822 repo: context.repo.repo,
69- pull_number: prNumber,
70- event: 'REQUEST_CHANGES',
71- body: message
23+ pull_number: context.issue.number
7224 });
7325
74- console.log('Created review requesting changes');
26+ const labels = pr.data.labels.map(l => l.name);
27+ const hasXLLabel = labels.includes('size/XL');
28+ const prBody = pr.data.body || '';
29+ const hasJustification = /##\s*Large PR Justification/i.test(prBody);
7530
76- - name : Dismiss review if justification added
77- if : steps.check.outputs.result == 'true'
78- uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
31+ console.log('PR Number:', context.issue.number);
32+ console.log('Has XL label:', hasXLLabel);
33+ console.log('Has justification:', hasJustification);
34+
35+ return {
36+ prNumber: context.issue.number,
37+ hasXLLabel: hasXLLabel,
38+ hasJustification: hasJustification,
39+ needsEnforcement: hasXLLabel && !hasJustification,
40+ shouldDismiss: hasXLLabel && hasJustification
41+ };
42+
43+ - name : Save enforcement result to artifact
44+ run : |
45+ mkdir -p pr-enforcement
46+ echo '${{ steps.pr.outputs.result }}' > pr-enforcement/result.json
47+ cat pr-enforcement/result.json
48+
49+ - name : Upload artifact
50+ uses : actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4
7951 with :
80- script : |
81- const prNumber = context.payload.pull_request.number;
82-
83- // Find our previous review requesting changes
84- const reviews = await github.rest.pulls.listReviews({
85- owner: context.repo.owner,
86- repo: context.repo.repo,
87- pull_number: prNumber
88- });
89-
90- const botReview = reviews.data.find(review =>
91- review.user.login === 'github-actions[bot]' &&
92- review.state === 'CHANGES_REQUESTED'
93- );
94-
95- if (botReview) {
96- await github.rest.pulls.dismissReview({
97- owner: context.repo.owner,
98- repo: context.repo.repo,
99- pull_number: prNumber,
100- review_id: botReview.id,
101- message: 'Large PR justification has been provided. Thank you!'
102- });
103-
104- console.log('Dismissed previous review:', botReview.id);
105-
106- // Add a comment confirming unblock
107- await github.rest.issues.createComment({
108- owner: context.repo.owner,
109- repo: context.repo.repo,
110- issue_number: prNumber,
111- body: '✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review.'
112- });
113- } else {
114- console.log('No previous blocking review found');
115- }
52+ name : pr-enforcement-result
53+ path : pr-enforcement/
54+ retention-days : 1
0 commit comments