|
73 | 73 | return;
|
74 | 74 | }
|
75 | 75 |
|
| 76 | + // Get the list of changed files |
| 77 | + const { data: changedFiles } = await github.rest.pulls.listFiles({ |
| 78 | + owner, |
| 79 | + repo, |
| 80 | + pull_number, |
| 81 | + }); |
| 82 | +
|
| 83 | + // Check if any files in doc/, library/ or verifast-proofs/ are modified |
| 84 | + const affectsDocs = changedFiles.some(file => file.filename.startsWith('doc/')); |
| 85 | + const affectsLibrary = changedFiles.some(file => file.filename.startsWith('library/')); |
| 86 | + const affectsVerifast = changedFiles.some(file => file.filename.startsWith('verifast-proofs/')); |
| 87 | + // Require two approvals iff one of the above folders are modified; otherwise, one is sufficient. |
| 88 | + const requiresTwoApprovals = affectsDocs || affectsLibrary || affectsVerifast; |
| 89 | + const requiredApprovals = requiresTwoApprovals ? 2 : 1; |
| 90 | +
|
76 | 91 | // Get all reviews with pagination
|
77 | 92 | async function getAllReviews() {
|
78 | 93 | let allReviews = [];
|
@@ -113,23 +128,27 @@ jobs:
|
113 | 128 | .map(review => review.user.login)
|
114 | 129 | );
|
115 | 130 |
|
116 |
| - const requiredApprovals = 2; |
117 | 131 | const committeeApprovers = Array.from(approvers)
|
118 | 132 | .filter(approver => requiredApprovers.includes(approver));
|
119 | 133 | const currentCountfromCommittee = committeeApprovers.length;
|
120 | 134 |
|
121 |
| - // Core logic that checks if the approvers are in the committee |
122 |
| - const conclusion = (currentCountfromCommittee >= 2) ? 'success' : 'failure'; |
| 135 | + // Check if we have enough approvals |
| 136 | + const conclusion = (currentCountfromCommittee >= requiredApprovals) ? 'success' : 'failure'; |
123 | 137 |
|
124 | 138 | console.log('PR Approval Status');
|
| 139 | + console.log('Modified folders:'); |
| 140 | + console.log(`- doc/: ${affectsDocs ? 'yes' : 'no'}`); |
| 141 | + console.log(`- library/: ${affectsLibrary ? 'yes' : 'no'}`); |
| 142 | + console.log(`- verifast-proofs/: ${affectsVerifast ? 'yes' : 'no'}`); |
| 143 | + console.log(`Required approvals from committee: ${requiredApprovals}`); |
125 | 144 | console.log(`PR has ${approvers.size} total approvals and ${currentCountfromCommittee} required approvals from the committee.`);
|
126 | 145 |
|
127 | 146 | console.log(`Committee Members: [${requiredApprovers.join(', ')}]`);
|
128 | 147 | console.log(`Committee Approvers: ${committeeApprovers.length === 0 ? 'NONE' : `[${committeeApprovers.join(', ')}]`}`);
|
129 | 148 | console.log(`All Approvers: ${approvers.size === 0 ? 'NONE' : `[${Array.from(approvers).join(', ')}]`}`);
|
130 | 149 |
|
131 | 150 | if (conclusion === 'failure') {
|
132 |
| - core.setFailed(`PR needs 2 approvals from committee members, but it has ${currentCountfromCommittee}`); |
| 151 | + core.setFailed(`PR needs ${requiredApprovals} approval${requiredApprovals > 1 ? 's' : ''} from committee members, but it has ${currentCountfromCommittee}`); |
133 | 152 | } else {
|
134 | 153 | core.info('PR approval check passed successfully.');
|
135 | 154 | }
|
0 commit comments