|
1 |
| -name: Label on Approval |
| 1 | +name: Add Label on Approval |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | pull_request_review:
|
5 |
| - types: [ submitted ] |
| 5 | + types: [ submitted,edited ] |
6 | 6 |
|
7 | 7 | jobs:
|
8 |
| - add-label-on-approval: |
| 8 | + add-label: |
9 | 9 | runs-on: ubuntu-latest
|
10 | 10 |
|
11 | 11 | steps:
|
12 |
| - - name: Checkout repository |
13 |
| - uses: actions/checkout@v2 |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v4 |
14 | 14 |
|
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 |
19 | 18 | with:
|
| 19 | + github-token: ${{ secrets.PAT_TOKEN }} |
20 | 20 | 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 | + }); |
39 | 42 | }
|
| 43 | + |
| 44 | +
|
| 45 | +
|
| 46 | +
|
0 commit comments