Skip to content

Commit b256ffa

Browse files
committed
Add autofix reminder
Remind query authors to validate their changes in autofix before merging.
1 parent 9a72914 commit b256ffa

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow creates a reminder to query authors to test their queries
2+
# in autofix.
3+
name: Autofix reminder
4+
5+
permissions:
6+
contents: read
7+
pull-requests: read
8+
issues: write
9+
10+
on:
11+
pull_request:
12+
branches:
13+
- main
14+
- "rc/*"
15+
paths:
16+
- "**/*.qhelp"
17+
- "**/*.ql"
18+
- "**/*.qll"
19+
20+
jobs:
21+
autofix-reminder:
22+
env:
23+
GITHUB_REPOSITORY: ${{ github.repository }}
24+
PR_NUMBER: ${{ github.event.number }}
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
REQUIRES_AUTOFIX_LABEL: "Autofix Validation Required"
27+
DOES_NOT_REQUIRE_AUTOFIX_LABEL: "No Autofix Validation Required"
28+
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Save PR number
32+
run: echo "${PR_NUMBER}" > pr_number.txt
33+
shell: bash
34+
env:
35+
PR_NUMBER: ${{ github.event.number }}
36+
37+
- name: Check existing labels
38+
shell: bash
39+
run:
40+
gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels" | jq -r '.[].name' > labels.txt
41+
42+
if grep -q -x -e "${REQUIRES_AUTOFIX_LABEL}" labels.txt || grep -q -x -e "${DOES_NOT_REQUIRE_AUTOFIX_LABEL}" labels.txt; then
43+
echo "::set-output name=should_continue::false"
44+
echo "Stopping workflow due to label presence."
45+
else
46+
echo "::set-output name=should_continue::true"
47+
fi
48+
49+
- name: Add label
50+
if: steps.label_check.outputs.should_continue == 'true'
51+
run: gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels" -X POST -F labels="${REQUIRES_AUTOFIX_LABEL}"
52+
53+
- name: Comment on PR
54+
if: steps.label_check.outputs.should_continue == 'true'
55+
run: gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" -X POST --field body="This pull request updates `.ql`, `.qll`, or `.qhelp` files, Please validate that autofixes generated based on these changes are valid. See [the documentation](https://github.com/github/codeql-team/blob/main/docs/best-practices/validating-autofix-for-query-changes.md) (internal access required). If autofix validation is not required, please add the label '${DOES_NOT_REQUIRE_AUTOFIX_LABEL}' to this pull request."

0 commit comments

Comments
 (0)