1111 name : Validate Issue with Custom Logic
1212 runs-on : ubuntu-latest
1313
14- # These permissions are required to read custom validator scripts and
15- # write/update issue comments.
1614 permissions :
1715 contents : read
1816 issues : write
@@ -25,45 +23,68 @@ jobs:
2523 - name : Install GitHub CLI
2624 run : sudo apt-get install gh
2725
28- - name : Validate Issue Title Format
29- id : title-check
26+ - name : Validate Title
3027 run : |
31- if [[ ! "${{ github.event.issue.title }}" =~ ^\[(New|Bug|Enhancement)\]:\ ]]; then
32- gh issue edit ${{ github.event.issue.number }} --add-label invalid
33- gh issue close ${{ github.event.issue.number }} --comment "由于标题不符合要求,已自动关闭 issue。" --reason "completed"
28+ labels=(${{ toJSON(github.event.issue.labels) }})
29+ is_from_template=false
30+ for label in "${labels[@]}"
31+ do
32+ if [[ "$label" == "from template" ]]; then
33+ is_from_template=true
34+ if [[ ! "${{ github.event.issue.title }}" =~ ^\[(New|Bug|Enhancement)\]:\ ]]; then
35+ gh issue edit ${{ github.event.issue.number }} --add-label invalid
36+ gh issue close ${{ github.event.issue.number }} --comment "由于标题不符合要求,已自动关闭 issue。" --reason "completed"
37+ exit 0
38+ fi
39+ fi
40+ done
41+
42+ if [[ "$is_from_template" == "true" ]]; then
43+ template="unknown"
44+ for label in "${labels[@]}"
45+ do
46+ if [[ "$label" == "bug" ]]; then
47+ template="T1_bug.yaml"
48+ elif [[ "$label" == "enhancement" ]]; then
49+ template="T2_enhancement.yaml"
50+ elif [[ "$label" == "new translator" ]]; then
51+ template="T3_new_translator.yaml"
52+ done
53+ if [[ "$template" == "unknown" ]]; then
54+ echo "This issue does not use a recognized template, skipping validation."
55+ exit 0
56+ fi
57+ echo "template=${template}" >> $GITHUB_ENV
58+ else [[ "$is_from_template" == "false" ]]; then
59+ echo "This issue does not use a template, skipping validation."
3460 exit 0
3561 fi
3662 env :
3763 GH_TOKEN : ${{ github.token }}
3864
39- # Install Node.js on the runner.
4065 - name : Setup Node.js
4166 id : setup-node
4267 uses : actions/setup-node@v4
4368 with :
4469 node-version : 20
4570
46- # Install dependencies from `package.json`.
4771 - name : Install Dependencies
4872 id : install
4973 run : npm install
5074
51- # Parse the issue body and convert it to JSON.
5275 - name : Parse Issue Body
5376 id : parse
5477 uses : issue-ops/parser@v4
5578 with :
5679 body : ${{ github.event.issue.body }}
57- issue-form-template : T3_new_translator.yaml
80+ issue-form-template : ${{ env.template }}
5881 workspace : ${{ github.workspace }}
5982
60- # Validate the parsed issue body against the issue form template. This
61- # example does use custom validators.
6283 - name : Validate Issue Forms
6384 id : validate
6485 uses : issue-ops/validator@v3
6586 with :
66- issue-form-template : T3_new_translator.yaml
87+ issue-form-template : ${{ env.template }}
6788 parsed-issue-body : ${{ steps.parse.outputs.json }}
6889 workspace : ${{ github.workspace }}
6990
0 commit comments