|
| 1 | +#/ |
| 2 | +# @license Apache-2.0 |
| 3 | +# |
| 4 | +# Copyright (c) 2025 The Stdlib Authors. |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +#/ |
| 18 | + |
| 19 | +# Workflow name: |
| 20 | +name: label_good_first_prs |
| 21 | + |
| 22 | +# Workflow triggers: |
| 23 | +on: |
| 24 | + pull_request_target: |
| 25 | + types: |
| 26 | + - opened |
| 27 | + - closed |
| 28 | + - synchronize |
| 29 | + - reopened |
| 30 | + - edited |
| 31 | + |
| 32 | +# Workflow jobs: |
| 33 | +jobs: |
| 34 | + |
| 35 | + # Define a job which automatically labels pull requests based on whether they reference good first issues |
| 36 | + labeler: |
| 37 | + |
| 38 | + # Define job name: |
| 39 | + name: 'Label PRs for issues with label "Good First Issue" as "Good First PR"s' |
| 40 | + |
| 41 | + # Only run this job if the pull request did not have label `automated-pr`: |
| 42 | + if: contains(github.event.pull_request.labels.*.name, 'automated-pr') == false |
| 43 | + |
| 44 | + # Define job permissions: |
| 45 | + permissions: |
| 46 | + contents: read |
| 47 | + pull-requests: write |
| 48 | + |
| 49 | + # Define the type of virtual host machine: |
| 50 | + runs-on: ubuntu-latest |
| 51 | + |
| 52 | + # Define the sequence of job steps: |
| 53 | + steps: |
| 54 | + # Checkout the repository: |
| 55 | + - name: 'Checkout repository' |
| 56 | + # Pin action to full length commit SHA |
| 57 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 58 | + with: |
| 59 | + # Specify whether to remove untracked files before checking out the repository: |
| 60 | + clean: true |
| 61 | + |
| 62 | + # Limit clone depth to the most recent commit: |
| 63 | + fetch-depth: 1 |
| 64 | + |
| 65 | + # Specify whether to download Git-LFS files: |
| 66 | + lfs: false |
| 67 | + timeout-minutes: 10 |
| 68 | + |
| 69 | + # Check whether any of the referenced issues is a "Good First Issue": |
| 70 | + - name: 'Check whether any of the referenced issues is a "Good First Issue"' |
| 71 | + id: 'check-pr' |
| 72 | + env: |
| 73 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 74 | + run: | |
| 75 | + bool=$(. "$GITHUB_WORKSPACE/.github/workflows/scripts/references_good_first_issue" $PR_NUMBER) |
| 76 | + echo "good-first-pr=$bool" >> $GITHUB_OUTPUT |
| 77 | +
|
| 78 | + # Add "Good First PR" label if PR references a "Good First Issue" |
| 79 | + - name: 'Add "Good First PR" label if PR references a "Good First Issue"' |
| 80 | + if: ${{ steps.check-pr.outputs.good-first-pr == 'true' }} |
| 81 | + # Pin action to full-length commit SHA |
| 82 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 83 | + with: |
| 84 | + github-token: ${{ secrets.STDLIB_BOT_PAT_REPO_WRITE }} |
| 85 | + script: | |
| 86 | + const { data: pr } = await github.rest.pulls.get({ |
| 87 | + 'owner': context.repo.owner, |
| 88 | + 'repo': context.repo.repo, |
| 89 | + 'pull_number': context.payload.pull_request.number |
| 90 | + }); |
| 91 | + const labels = context.payload.pull_request.labels.map( label => label.name ); |
| 92 | + if ( !labels.includes( 'Good First PR' ) ) { |
| 93 | + await github.rest.issues.addLabels({ |
| 94 | + 'owner': context.repo.owner, |
| 95 | + 'repo': context.repo.repo, |
| 96 | + 'issue_number': context.payload.pull_request.number, |
| 97 | + 'labels': [ 'Good First PR' ] |
| 98 | + }); |
| 99 | + } |
0 commit comments