|
| 1 | +# |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. 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, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +# |
| 19 | +name: Correctness Label |
| 20 | + |
| 21 | +on: |
| 22 | + pull_request_target: |
| 23 | + types: [opened, edited, synchronize] |
| 24 | + |
| 25 | +jobs: |
| 26 | + label: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + permissions: |
| 29 | + pull-requests: write |
| 30 | + steps: |
| 31 | + - uses: actions/github-script@v7 |
| 32 | + with: |
| 33 | + script: | |
| 34 | + const body = context.payload.pull_request.body || ''; |
| 35 | + const prNumber = context.payload.pull_request.number; |
| 36 | + const { owner, repo } = context.repo; |
| 37 | + const LABEL = 'correctness'; |
| 38 | +
|
| 39 | + // Extract only the "correctness bug" section (up to the next ### heading or end of body). |
| 40 | + // Body is accessed via context.payload (JS), not via ${{ }} interpolation — no injection risk. |
| 41 | + const sectionMatch = body.match( |
| 42 | + /###\s*Does this PR resolve a correctness bug\?[\s\S]*?(?=\n###|$)/i |
| 43 | + ); |
| 44 | + const isYes = sectionMatch != null && |
| 45 | + /- \[[xX]\] Yes/.test(sectionMatch[0]); |
| 46 | +
|
| 47 | + const { data: currentLabels } = await github.rest.issues.listLabelsOnIssue({ |
| 48 | + owner, repo, issue_number: prNumber, |
| 49 | + }); |
| 50 | + const hasLabel = currentLabels.some(l => l.name === LABEL); |
| 51 | +
|
| 52 | + if (isYes && !hasLabel) { |
| 53 | + await github.rest.issues.addLabels({ |
| 54 | + owner, repo, issue_number: prNumber, labels: [LABEL], |
| 55 | + }); |
| 56 | + core.info(`Added '${LABEL}' label`); |
| 57 | + } else if (!isYes && hasLabel) { |
| 58 | + await github.rest.issues.removeLabel({ |
| 59 | + owner, repo, issue_number: prNumber, name: LABEL, |
| 60 | + }); |
| 61 | + core.info(`Removed '${LABEL}' label`); |
| 62 | + } else { |
| 63 | + core.info(`No label change needed (isYes=${isYes}, hasLabel=${hasLabel})`); |
| 64 | + } |
0 commit comments