diff options
| author | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-01-21 15:49:40 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-01-21 11:49:40 -0300 |
| commit | 5244ecbd2259365ecd6bbf96747285a673b2ee69 (patch) | |
| tree | 79f2ed1f4dd381654e00bb12535766fdc1528115 /.github/workflows | |
| parent | 626d77e52a3f247358514bcf51c761283968099c (diff) | |
Added GitHub action to label PRs without a ticket linked in title.
Diffstat (limited to '.github/workflows')
| -rw-r--r-- | .github/workflows/labels.yml | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml new file mode 100644 index 0000000000..3ca0f643f5 --- /dev/null +++ b/.github/workflows/labels.yml @@ -0,0 +1,52 @@ +name: Labels + +on: + pull_request: + types: [ edited, opened, reopened, ready_for_review ] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + no_ticket: + name: "Flag if no Trac ticket is found in the title" + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - uses: actions/checkout@v4 + + - name: "Check title and manage labels" + uses: actions/github-script@v7 + with: + script: | + const title = context.payload.pull_request.title; + const regex = /#[0-9]+[ ,:]?/gm; + const label = "no ticket"; + const hasMatch = regex.test(title); + const labels = context.payload.pull_request.labels.map(l => l.name); + const owner = context.repo.owner; + const repo = context.repo.repo; + const pr_number = context.payload.pull_request.number; + console.log(`=> Pull Request Title: ${title}`); + console.log(`=> Labels on PR: [${labels}]`); + if (hasMatch && labels.includes(label)) { + console.log(`==> Removing label "${label}" from PR #${pr_number}`); + await github.rest.issues.removeLabel({ + owner, + repo, + issue_number: pr_number, + name: label + }); + } else if (!hasMatch && !labels.includes(label)) { + console.log(`==> Adding label "${label}" to PR #${pr_number}`); + await github.rest.issues.addLabels({ + owner, + repo, + issue_number: pr_number, + labels: [label] + }); + } else { + console.log(`No action needed for PR #${pr_number}`); + } |
