Skip to content

Commit db4fca2

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

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Autofix Label Manager
2+
3+
on:
4+
pull_request_target:
5+
types: [labeled]
6+
7+
jobs:
8+
check-to-remove-autofix-label:
9+
env:
10+
GITHUB_REPOSITORY: ${{ github.repository }}
11+
PR_NUMBER: ${{ github.event.number }}
12+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13+
REQUIRES_AUTOFIX_LABEL: "Autofix Validation Required"
14+
DOES_NOT_REQUIRE_AUTOFIX_LABEL: "No Autofix Validation Required"
15+
LABEL_ADDED: ${{ github.event.label.name }}
16+
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Check if label "No Autofix Validation Required" is added
20+
shell: bash
21+
run: |
22+
if [ "$LABEL_ADDED" != "$DOES_NOT_REQUIRE_AUTOFIX_LABEL" ]; then
23+
echo "Label $DOES_NOT_REQUIRE_AUTOFIX_LABEL was not added."
24+
exit 0
25+
fi
26+
27+
echo "Label $DOES_NOT_REQUIRE_AUTOFIX_LABEL was added."
28+
29+
# Check if Label $REQUIRES_AUTOFIX_LABEL exists and remove it
30+
REQUIRES_AUTOFIX_LABEL_EXISTS=$(gh api /repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels | jq --arg label "Autofix Validation Required" '.[] | select(.name==$label) | .name')
31+
if [ "$REQUIRES_AUTOFIX_LABEL_EXISTS" == "$REQUIRES_AUTOFIX_LABEL" ]; then
32+
gh api -X DELETE "/repos/$GITHUB_REPOSITORY/issues/$PR_NUMBER/labels/$REQUIRES_AUTOFIX_LABEL"
33+
echo "$REQUIRES_AUTOFIX_LABEL Label removed."
34+
else
35+
echo "$REQUIRES_AUTOFIX_LABEL Label does not exist or was already removed."
36+
fi
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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: write
8+
issues: write
9+
10+
on:
11+
pull_request:
12+
branches:
13+
- main
14+
- "rc/*"
15+
paths:
16+
- "**/*.qhelp"
17+
- "**/*.ql"
18+
- "**/*.qll"
19+
# This workflow
20+
- ".github/workflows/autofix-reminder.yml"
21+
22+
jobs:
23+
autofix-reminder:
24+
env:
25+
GITHUB_REPOSITORY: ${{ github.repository }}
26+
PR_NUMBER: ${{ github.event.number }}
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
REQUIRES_AUTOFIX_LABEL: "Autofix Validation Required"
29+
DOES_NOT_REQUIRE_AUTOFIX_LABEL: "No Autofix Validation Required"
30+
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Check existing labels
34+
id: label_check
35+
shell: bash
36+
run: |
37+
gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels" | jq -r '.[].name' > labels.txt
38+
39+
if grep -q -x -e "${REQUIRES_AUTOFIX_LABEL}" labels.txt || grep -q -x -e "${DOES_NOT_REQUIRE_AUTOFIX_LABEL}" labels.txt; then
40+
echo "Stopping workflow due to label presence."
41+
echo "should_continue=false" >> $GITHUB_OUTPUT
42+
else
43+
echo "Add $REQUIRES_AUTOFIX_LABEL label."
44+
echo "should_continue=true" >> $GITHUB_OUTPUT
45+
fi
46+
47+
- name: Add label
48+
if: steps.label_check.outputs.should_continue == 'true'
49+
run: |
50+
gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/labels" -X POST -f "labels[]=$REQUIRES_AUTOFIX_LABEL"
51+
52+
- name: Comment on PR
53+
if: steps.label_check.outputs.should_continue == 'true'
54+
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)