Skip to content

[New]:

[New]: #15

name: Issue Opened/Edited
on:
issues:
types:
- opened
- edited
jobs:
validate:
name: Validate Issue with Custom Logic
runs-on: ubuntu-latest
# These permissions are required to read custom validator scripts and
# write/update issue comments.
permissions:
contents: read
issues: write
steps:
- name: Checkout Repository
id: checkout
uses: actions/checkout@v4
- name: Install GitHub CLI
run: sudo apt-get install gh
- name: Validate Issue Title Format
id: title-check
run: |
if [[ ! "${{ github.event.issue.title }}" =~ ^\[New\]:\ ]]; then
gh issue edit ${{ github.event.issue.number }} --add-label invalid
gh issue close ${{ github.event.issue.number }} --comment "由于标题不符合要求,已自动关闭 issue。" --reason "completed"
exit 0
fi
env:
GH_TOKEN: ${{ github.token }}
# Install Node.js on the runner.
- name: Setup Node.js
id: setup-node
uses: actions/setup-node@v4
with:
node-version: 20
# Install dependencies from `package.json`.
- name: Install Dependencies
id: install
run: npm install
# Parse the issue body and convert it to JSON.
- name: Parse Issue Body
id: parse
uses: issue-ops/parser@v4
with:
body: ${{ github.event.issue.body }}
issue-form-template: T3_new_translator.yaml
workspace: ${{ github.workspace }}
# Validate the parsed issue body against the issue form template. This
# example does use custom validators.
- name: Validate Issue Forms
id: validate
uses: issue-ops/validator@v3
with:
issue-form-template: T3_new_translator.yaml
parsed-issue-body: ${{ steps.parse.outputs.json }}
workspace: ${{ github.workspace }}
- name: Handle Validation Errors
if: ${{ steps.validate.outputs.errors != '' }}
run: |
gh issue edit ${{ github.event.issue.number }} --add-label invalid
gh issue close ${{ github.event.issue.number }} --comment "请仔细阅读 issue 模板中的说明。" --reason "completed"
env:
GH_TOKEN: ${{ github.token }}