Skip to content

Commit 5d8ee62

Browse files
authored
Add permissions needed to modify PR (#34)
Fixes: https://github.com/model-checking/verify-rust-std/actions/runs/9878423942/job/27283663117 which is a 403 error from github. [Source for fix](https://stackoverflow.com/questions/70435286/resource-not-accessible-by-integration-on-github-post-repos-owner-repo-ac) Test: https://github.com/jaisnan/rust-dev/pull/22/checks?check_run_id=27285370500 By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.
1 parent bbfbb19 commit 5d8ee62

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

.github/workflows/pr_approval.yml

+10-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ on:
99
types: [submitted]
1010
workflow_dispatch:
1111

12+
# Without these permissions, we get a 403 error from github
13+
# for trying to modify the pull request for newer project.
14+
# Source: https://stackoverflow.com/a/76994510
15+
permissions: write-all
16+
1217
jobs:
1318
check-approvals:
1419
if: github.event.review.state == 'APPROVED' || github.event_name == 'workflow_dispatch'
@@ -95,20 +100,20 @@ jobs:
95100
);
96101
97102
const requiredApprovals = 2;
98-
const requiredApproversCount = Array.from(approvers)
103+
const currentCountfromCommittee = Array.from(approvers)
99104
.filter(approver => requiredApprovers.includes(approver))
100105
.length;
101106
102107
// TODO: Improve logging and messaging to the user
103108
console.log('PR Approvers:', Array.from(approvers));
104-
console.log('Required Approvers:', requiredApproversCount);
109+
console.log('Required Approvers:', requiredApprovals);
105110
106111
// Core logic that checks if the approvers are in the committee
107112
const checkName = 'PR Approval Status';
108-
const conclusion = (approvers.size >= requiredApprovals && requiredApproversCount >= 2) ? 'success' : 'failure';
113+
const conclusion = (approvers.size >= requiredApprovals && currentCountfromCommittee >= 2) ? 'success' : 'failure';
109114
const output = {
110115
title: checkName,
111-
summary: `PR has ${approvers.size} total approvals and ${requiredApproversCount} required approvals.`,
116+
summary: `PR has ${approvers.size} total approvals and ${requiredApprovals} required approvals.`,
112117
text: `Approvers: ${Array.from(approvers).join(', ')}\nRequired Approvers: ${requiredApprovers.join(', ')}`
113118
};
114119
@@ -152,5 +157,5 @@ jobs:
152157
}
153158
154159
if (conclusion === 'failure') {
155-
core.setFailed(`PR needs at least ${requiredApprovals} total approvals and 2 required approvals. Current approvals: ${approvers.size}, Required approvals: ${requiredApproversCount}`);
160+
core.setFailed(`PR needs at least ${requiredApprovals} total approvals and 2 required approvals. Current approvals: ${approvers.size}, Required approvals: ${requiredApprovals}`);
156161
}

0 commit comments

Comments
 (0)