This repository has been archived by the owner on Oct 13, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
286 lines (247 loc) · 9.99 KB
/
auto-update-db.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
---
name: Auto Update DB
on:
issues:
types: [labeled]
# no point in concurrency since it still cancels pending jobs
jobs:
auto_update_db:
if: (github.event.label.name == 'request-theme' || github.event.label.name == 'approve-theme')
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
steps:
- name: Check if member
if: (github.event.label.name == 'approve-theme')
# if someone, somehow, adds the approval label but isn't a member, then exit
run: |
gh api \
-H "Accept: application/vnd.github+json" \
/orgs/${{ github.repository_owner }}/members/${{ github.actor }} || exit 1
- name: Queue
# we only want to run one add job at a time, so queue them
if: (github.event.label.name == 'approve-theme')
uses: ahmadnassri/action-workflow-queue@v1
- name: Checkout
uses: actions/checkout@v4
- name: Checkout
uses: actions/checkout@v4
with:
ref: database
path: database
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, will fail to push refs to dest repo
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Setup Python Dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: Parse Issue
uses: stefanbuck/github-issue-parser@v3
id: issue-parser
with:
issue-body: ${{ github.event.issue.body }}
template-path: .github/ISSUE_TEMPLATE/theme.yml
- name: Crease JSON
env:
JSON_STRING: ${{ steps.issue-parser.outputs.jsonString }}
run: |
echo ${JSON_STRING} > submission.json
- name: Get Issue Author ID
id: author
run: |
echo "issue_author_id=$(echo "${{ github.event.issue.user.id }}")" >> $GITHUB_OUTPUT
- name: Update
id: update
env:
ISSUE_AUTHOR_USER_ID: ${{ steps.author.outputs.issue_author_id }}
TMDB_API_KEY_V3: ${{ secrets.TMDB_API_KEY_V3 }}
TWITCH_CLIENT_ID: ${{ secrets.TWITCH_CLIENT_ID }}
TWITCH_CLIENT_SECRET: ${{ secrets.TWITCH_CLIENT_SECRET }}
run: |
python -u ./src/updater.py --issue_update
# if exceptions.md file exists, then set output to true
if [ -f exceptions.md ]; then
echo "exception=true" >> $GITHUB_OUTPUT
else
echo "exception=false" >> $GITHUB_OUTPUT
fi
# if duplicate.md file exists, then set output to true
if [ -f duplicate.md ]; then
echo "duplicate=true" >> $GITHUB_OUTPUT
else
echo "duplicate=false" >> $GITHUB_OUTPUT
fi
# if auto_close.md file exists, then set output to true
if [ -f auto_close.md ]; then
echo "auto_close=true" >> $GITHUB_OUTPUT
else
echo "auto_close=false" >> $GITHUB_OUTPUT
fi
- name: Git Diff
id: diff
working-directory: database
run: |
echo "::group::issue_comment"
git add .
echo "" >> ../comment.md
echo "\`\`\`diff" >> ../comment.md
git diff --cached >> ../comment.md
echo "\`\`\`" >> ../comment.md
echo "" >> ../comment.md
echo "" >> ../comment.md
cat ../bot_commands.md >> ../comment.md
cat ../comment.md
echo "::endgroup::"
echo "::group::issue_title"
cat ../title.md
echo "issue_title=$(cat ../title.md)" >> $GITHUB_OUTPUT
echo "::endgroup::"
- name: Update Issue Title
uses: actions/github-script@v7
env:
ISSUE_TITLE: ${{ steps.diff.outputs.issue_title }}
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
github.rest.issues.update({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
title: process.env.ISSUE_TITLE
})
- name: Update Labels
id: labels
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
result-encoding: string
script: |
// get labels
const labels = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
})
// get update outputs
const exception = "${{ steps.update.outputs.exception }}"
const duplicate = "${{ steps.update.outputs.duplicate }}"
// create an array of current labels
let current_labels = labels.data.map(label => label.name)
// check if labels list contains "exception"
const label_exception = current_labels.includes('exception')
// add exception label if there was an exception and not already labeled
if (!label_exception && exception === 'true') {
current_labels.push('exception')
} else if (label_exception && exception === 'false') {
// remove exception label if there is no longer an exception
const index = current_labels.indexOf('exception')
current_labels.splice(index, 1)
}
// check if labels list contains "duplicate"
const label_duplicate = current_labels.includes('duplicate')
// add duplicate label if there was a duplicate and not already labeled
if (!label_duplicate && duplicate === 'true') {
current_labels.push('duplicate')
} else if (label_duplicate && duplicate === 'false') {
// remove duplicate label if there is no longer a duplicate
const index = current_labels.indexOf('duplicate')
current_labels.splice(index, 1)
}
// check if labels list contains "approve-theme"
const approve_label = "approve-theme"
let label_add = current_labels.includes(approve_label)
if (label_add && exception === 'true') {
// remove approve-theme label if there is an exception
const index = current_labels.indexOf(approve_label)
current_labels.splice(index, 1)
}
// remove label "approve-queue"
const queue_label = "approve-queue"
// this is always removed
let label_remove = current_labels.includes(queue_label)
if (label_remove) {
const index = current_labels.indexOf(queue_label)
current_labels.splice(index, 1)
}
// set labels
await github.rest.issues.setLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: current_labels
})
// determine to continue or not
if (label_add) {
return 'true'
}
- name: Issue comment
uses: mshick/add-pr-comment@v2
with:
repo-token: ${{ secrets.GH_BOT_TOKEN }}
message-path: comment.md
- name: Auto Close
if: >-
(github.event.label.name == 'request-theme') &&
steps.update.outputs.auto_close == 'true'
env:
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
comment=$(cat auto_close.md)
close_reason="not planned"
lock_reason="resolved"
gh issue close ${{ github.event.issue.number }} --comment "${comment}" --reason "${close_reason}"
gh issue lock ${{ github.event.issue.number }} --reason "${lock_reason}"
- name: GitHub Commit & Push
if: >-
(github.event.label.name == 'approve-theme') &&
steps.update.outputs.exception == 'false' &&
steps.labels.outputs.result == 'true'
uses: actions-js/[email protected]
with:
author_email: ${{ secrets.GH_BOT_EMAIL }}
author_name: ${{ secrets.GH_BOT_NAME }}
branch: database # commit to database
directory: database # use the database directory
github_token: ${{ secrets.GH_BOT_TOKEN }}
message: 'resolves #${{ github.event.issue.number }}'
- name: Close Issue
if: >-
(github.event.label.name == 'approve-theme') &&
steps.update.outputs.exception == 'false' &&
steps.labels.outputs.result == 'true'
env:
GH_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
comment="This theme has been added/updated and will be available on the next daily scheduled update."
close_reason="completed"
lock_reason="resolved"
gh issue close ${{ github.event.issue.number }} --comment "${comment}" --reason "${close_reason}"
gh issue lock ${{ github.event.issue.number }} --reason "${lock_reason}"
- name: Label next issue
if: >-
(github.event.label.name == 'approve-theme') &&
steps.update.outputs.exception == 'false'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
// get list of open issues
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
labels: 'approve-queue'
})
// add approve-theme label to first issue found
if (issues.data.length > 0) {
github.rest.issues.addLabels({
issue_number: issues.data[0].number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['approve-theme']
})
}