1
1
name : Add Label on Approval
2
2
3
3
on :
4
+ pull_request_target :
5
+ types : [opened, synchronize]
4
6
pull_request_review :
5
7
types : [submitted]
6
8
@@ -9,17 +11,38 @@ permissions:
9
11
pull-requests : write
10
12
11
13
jobs :
14
+ setup :
15
+ if : github.event_name == 'pull_request_target'
16
+ runs-on : ubuntu-latest
17
+
18
+ steps :
19
+ - name : Checkout code
20
+ uses : actions/checkout@v4
21
+ with :
22
+ ref : ${{ github.event.pull_request.head.ref }}
23
+ repository : ${{ github.event.pull_request.head.repo.full_name }}
24
+
25
+ - name : Authenticate with GitHub App
26
+ id : auth
27
+ uses : tibdex/github-app-token@v2
28
+ with :
29
+ app_id : ${{ secrets.APP_ID }}
30
+ private_key : ${{ secrets.PRIVATE_KEY }}
31
+
12
32
add-label :
33
+ if : github.event_name == 'pull_request_review' && github.event.review.state == 'approved'
13
34
runs-on : ubuntu-latest
14
35
15
36
steps :
37
+ - name : Checkout code
38
+ uses : actions/checkout@v4
39
+
16
40
- name : Authenticate with GitHub App
17
41
id : auth
18
42
uses : tibdex/github-app-token@v2
19
43
with :
20
44
app_id : ${{ secrets.APP_ID }}
21
45
private_key : ${{ secrets.PRIVATE_KEY }}
22
- - run : " echo 'The created token is masked: ${{ steps.create_token.outputs.token }}'"
23
46
24
47
- name : Check if approval is from Collaborators
25
48
id : check_approval
@@ -33,25 +56,16 @@ jobs:
33
56
console.log('No review found.');
34
57
return;
35
58
}
36
- const collaborators = ['mxsm', 'TeslaRustor','SpaceXCN']; // Replace with actual GitHub usernames
37
- console.log('review:', review.state);
38
- console.log('review:', review.state === 'approved');
39
- console.log('Collaborators:', collaborators);
40
- console.log('Collaborators:', collaborators.includes(review.user.login));
59
+ const collaborators = ['mxsm', 'TeslaRustor', 'SpaceXCN']; // Replace with actual GitHub usernames
60
+
41
61
// Check if the review is approved and from a collaborator
42
62
const isApprovedByCollaborator = review.state === 'approved' && collaborators.includes(review.user.login);
43
- console.log('isApprovedByCollaborator:', isApprovedByCollaborator);
44
- console.log('pull_request:', pull_request.number);
45
- // Return the result to the workflow
46
- if (isApprovedByCollaborator) {
63
+
64
+ if (isApprovedByCollaborator) {
47
65
await github.rest.issues.addLabels({
48
66
owner,
49
67
repo,
50
68
issue_number: pull_request.number,
51
- labels: ['approved','auto merge']
69
+ labels: ['approved', 'auto merge']
52
70
});
53
71
}
54
-
55
-
56
-
57
-
0 commit comments