|
24 | 24 | pull_request_target:
|
25 | 25 | types:
|
26 | 26 | - opened
|
| 27 | + - closed |
27 | 28 | - synchronize
|
28 | 29 | - reopened
|
29 | 30 | - edited
|
|
64 | 65 | configuration-path: .github/labeler.yml
|
65 | 66 | repo-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }}
|
66 | 67 |
|
| 68 | + # Add "First-time Contributor" label if PR is from a first-time contributor: |
| 69 | + - name: 'Add "First-time Contributor" label if PR is from a first-time contributor' |
| 70 | + if: ${{ ( github.event.action == 'opened' || github.event.action == 'reopened' ) && github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' }} |
| 71 | + # Pin action to full-length commit SHA |
| 72 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 73 | + with: |
| 74 | + github-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }} |
| 75 | + script: | |
| 76 | + const labels = context.payload.pull_request.labels.map( label => label.name ); |
| 77 | + if ( !labels.includes( 'First-time Contributor' ) ) { |
| 78 | + await github.rest.issues.addLabels({ |
| 79 | + 'owner': context.repo.owner, |
| 80 | + 'repo': context.repo.repo, |
| 81 | + 'issue_number': context.payload.pull_request.number, |
| 82 | + 'labels': [ 'First-time Contributor' ] |
| 83 | + }); |
| 84 | + } |
| 85 | +
|
67 | 86 | # Add "Needs Review" label when PR is opened and not a draft:
|
68 | 87 | - name: 'Add "Needs Review" label if PR is opened and not draft'
|
69 | 88 | if: ${{ github.event.action == 'opened' && github.event.pull_request.draft == false }}
|
@@ -133,3 +152,35 @@ jobs:
|
133 | 152 | console.log( 'Error removing label %s: %s', label, error.message );
|
134 | 153 | }
|
135 | 154 | }
|
| 155 | +
|
| 156 | + # Remove "First-time Contributor" label from other open PRs if PR is merged: |
| 157 | + - name: 'Remove "First-time Contributor" label from other open PRs if PR is merged' |
| 158 | + if: ${{ github.event.action == 'closed' && github.event.pull_request.merged == true }} |
| 159 | + # Pin action to full length commit SHA |
| 160 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 161 | + with: |
| 162 | + github-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }} |
| 163 | + script: | |
| 164 | + const prAuthor = context.payload.pull_request.user.login; |
| 165 | +
|
| 166 | + const { data: pullRequests } = await github.rest.pulls.list({ |
| 167 | + 'owner': context.repo.owner, |
| 168 | + 'repo': context.repo.repo, |
| 169 | + 'state': 'open' |
| 170 | + }); |
| 171 | +
|
| 172 | + // Remove "First-time Contributor" label from any other open PRs by the same author: |
| 173 | + for ( const pull of pullRequests ) { |
| 174 | + if ( pull.user.login === prAuthor ) { |
| 175 | + try { |
| 176 | + await github.rest.issues.removeLabel({ |
| 177 | + 'owner': context.repo.owner, |
| 178 | + 'repo': context.repo.repo, |
| 179 | + 'issue_number': pull.number, |
| 180 | + 'name': 'First-time Contributor' |
| 181 | + }); |
| 182 | + } catch ( error ) { |
| 183 | + console.log( 'Error removing "First-time Contributor" label from PR #%d: %s', pull.number, error.message ); |
| 184 | + } |
| 185 | + } |
| 186 | + } |
0 commit comments