Skip to content

Commit 53c19b2

Browse files
committed
ci: auto-apply correctness label from PR template checkbox
Replace the free-text Yes/No comment in PULL_REQUEST_TEMPLATE.md with a single checkbox. A new GitHub Actions workflow (correctness-label.yml) triggers on pull_request_target opened/edited/synchronize, parses the correctness section of the PR body, and adds or removes the `correctness` label automatically — no manual committer action needed.
1 parent 71a7d0a commit 53c19b2

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Thanks for sending a pull request! Here are some tips for you:
1616

1717
### Does this PR resolve a correctness bug?
1818

19-
<!-- Yes/No. (Note: If yes, committer will add `correctness` label to current pull request). -->
19+
<!-- Check if yes. The `correctness` label will be added/removed automatically. -->
20+
- [ ] Yes
2021

2122
### Does this PR introduce _any_ user-facing change?
2223

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)