Skip to content

Commit 6f89e62

Browse files
authored
[ISSUE #545]🔧Update label-on-approval.yml (#546)
* [ISSUE #545]🔧Update label-on-approval.yml * fix ci error * fix ci error * fix ci error * fix error * fix error * fix ci error * fix error * fix error * ttt * ttt * ttt * ttt * ttt
1 parent b14eab5 commit 6f89e62

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed
+34-27
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
1-
name: Label on Approval
1+
name: Add Label on Approval
22

33
on:
44
pull_request_review:
5-
types: [ submitted ]
5+
types: [ submitted,edited ]
66

77
jobs:
8-
add-label-on-approval:
8+
add-label:
99
runs-on: ubuntu-latest
1010

1111
steps:
12-
- name: Checkout repository
13-
uses: actions/checkout@v2
12+
- name: Checkout code
13+
uses: actions/checkout@v4
1414

15-
- name: Check for approval and add label
16-
uses: actions/github-script@v6
17-
env:
18-
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }}
15+
- name: Check if approval is from Collaborators
16+
id: check_approval
17+
uses: actions/github-script@v7
1918
with:
19+
github-token: ${{ secrets.PAT_TOKEN }}
2020
script: |
21-
const approved = context.payload.review.state === 'approved';
22-
const owner = context.repo.owner;
23-
const repo = context.repo.repo;
24-
const pull_number = context.payload.pull_request.number;
25-
26-
if (approved) {
27-
const { data: collaborators } = await github.repos.listCollaborators({ owner, repo });
28-
const reviewer = context.payload.review.user.login;
29-
const isOwner = collaborators.some(collab => collab.login === reviewer && collab.permissions.admin);
30-
31-
if (isOwner) {
32-
await github.issues.addLabels({
33-
owner,
34-
repo,
35-
issue_number: pull_number,
36-
labels: ['approved','auto merge']
37-
});
38-
}
21+
const { owner, repo } = context.repo;
22+
const { pull_request, review } = context.payload;
23+
24+
// Define your list of collaborators
25+
const collaborators = ['mxsm', 'TeslaRustor','SpaceXCN']; // Replace with actual GitHub usernames
26+
console.log('review:', review.state);
27+
console.log('review:', review.state === 'approved');
28+
console.log('Collaborators:', collaborators);
29+
console.log('Collaborators:', collaborators.includes(review.user.login));
30+
// Check if the review is approved and from a collaborator
31+
const isApprovedByCollaborator = review.state === 'approved' && collaborators.includes(review.user.login);
32+
console.log('isApprovedByCollaborator:', isApprovedByCollaborator);
33+
console.log('pull_request:', pull_request.number);
34+
// Return the result to the workflow
35+
if (isApprovedByCollaborator) {
36+
await github.rest.issues.addLabels({
37+
owner,
38+
repo,
39+
issue_number: pull_request.number,
40+
labels: ['approved','auto merge']
41+
});
3942
}
43+
44+
45+
46+

0 commit comments

Comments
 (0)