-
Notifications
You must be signed in to change notification settings - Fork 3
103 lines (94 loc) · 3.72 KB
/
issue.yml
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Workflow file for registering dad jokes from issues
name: Register oyajigyagu from issues
on:
issues:
types: [opened]
permissions:
issues: write
contents: write
concurrency:
group: ${{ github.workflow }}
jobs:
register-dad-jokes:
runs-on: ubuntu-latest
if: ${{ startsWith(github.event.issue.title, 'Add oyajigyagu ') }}
steps:
- name: Check permissions
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
const { data: permissions } = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: context.payload.issue.user.login
});
if (permissions.permission !== 'write' && permissions.permission !== 'admin') {
throw new Error('User does not have write permissions');
}
- name: Checkout
uses: actions/checkout@b80ff79f1755d06ba70441c368a6fe801f5f3a62
- name: Write dad joke to file
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
const fs = require('fs');
const path = require('path');
if (!fs.existsSync('database')) {
fs.mkdirSync('database');
}
const issue = context.payload.issue;
const id = `CRE-${new Date().getFullYear()}-${36000+fs.readdirSync('database').length}`;
const body = JSON.parse(issue.body);
if(!body.author || !body.text || !body.vector_string) {
throw new Error('Invalid issue body');
}
body.id = id;
const issuePath = path.join('database', `${id}.json`);
fs.writeFileSync(issuePath, JSON.stringify(body, null, 2));
console.log(`Wrote issue to ${issuePath}`);
- name: Sync database to main branch
run: |
git pull
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add database
git commit -m "Sync database"
git push
- name: Comment and close valid issue
if: success()
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
const fs = require('fs');
const id = `CRE-${new Date().getFullYear()}-${36000+fs.readdirSync('database').length - 1}`;
const issue = context.payload.issue;
github.rest.issues.createComment({
issue_number: issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Registered oyajigyagu with ID [${id}](https://crss.gnknzm.net/details/?id=${id})`
});
github.rest.issues.update({
issue_number: issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed'
});
- name: Comment and close invalid issue
if: failure()
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
with:
script: |
const issue = context.payload.issue;
github.rest.issues.createComment({
issue_number: issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `Closing issue due to the missing permission or invalid body.`
});
github.rest.issues.update({
issue_number: issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: 'closed'
});