forked from hr3lxphr6j/bililive-go
-
Notifications
You must be signed in to change notification settings - Fork 0
62 lines (59 loc) · 2.28 KB
/
validate_issue.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Validate issue
on:
issues:
types:
- labeled
jobs:
validate:
runs-on: ubuntu-latest
steps:
- name: Check if issue is labeled within one minute
id: check-time
uses: actions/github-script@v6
with:
script: |
const createdAt = new Date("${{ github.event.issue.created_at }}");
const now = new Date();
const oneMinute = 60 * 1000; // milliseconds
if (now - createdAt > oneMinute) {
console.log('Issue was not labeled within one minute. Skipping...');
return false;
}
return true;
result-encoding: string
- name: Check if issue is labeled as bug or question
id: check-label
if: steps.check-time.outputs.result == 'true'
uses: actions/github-script@v6
with:
script: |
const labels = JSON.parse(`${{ toJSON(github.event.issue.labels) }}`).map(label => label.name);
const isBugOrQuestion = labels.includes('bug') || labels.includes('question');
core.setOutput('isBugOrQuestion', isBugOrQuestion);
- name: Validate issues
if: steps.check-label.outputs.isBugOrQuestion == 'true'
uses: actions/github-script@v6
with:
script: |
const body = "${{ github.event.issue.body }}";
const versionRegex = /### 程序版本\s*(.+)\s*### 所使用的/;
const versionMatch = body.match(versionRegex);
let closeReasons = [];
if (!versionMatch || !versionMatch[1].match(/\d+/)) {
closeReasons.push('请填入有效的程序版本。');
}
if (closeReasons.length > 0) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `Issue 未通过验证:\n${closeReasons.join('\n')}`,
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'closed'
});
}
github-token: ${{ secrets.GITHUB_TOKEN }}