-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
208 lines (188 loc) · 7.61 KB
/
label.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
name: Add/Remove Labels
on:
pull_request_target:
types: [ opened, closed ]
jobs:
merge_job:
if: github.event.pull_request.merged == true
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
let removeLabelsList = [
"Pending Merge",
"Needs Author Reply",
"Needs Review",
"Review High Priority",
"Needs Second Approval",
"Blocked by dependency",
"Needs a new dev",
"squash-merge",
"Keep Open",
"Stable"
];
async function removeLabel(label) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: label
});
}
async function addPostMergeComments() {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `Maintainers: Please [Sync Translations](https://github.com/ankidroid/Anki-Android/actions/workflows/sync_translations.yml) to produce a commit with only the automated changes from this PR.
Read more about updating strings on the wiki,
- [localization-administration](https://github.com/ankidroid/Anki-Android/wiki/Development-Guide#localization-administration)
- [download-localized-strings](https://github.com/ankidroid/Anki-Android/wiki/Development-Guide#download-localized-strings)`
})
}
let result = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
if (result.data !== null && result.data.length > 0) {
let labels = result.data;
for (let label of labels) {
if (removeLabelsList.includes(label.name)) {
console.log("Removed: ", label.name);
removeLabel(label.name);
}
// add post merge comments for 'strings' labeled PR
if (label.name == "Strings") {
addPostMergeComments();
}
}
}
add_label:
if: (!(github.event.action == 'closed' && github.event.pull_request.merged != true)) && github.event.pull_request.merged != true && github.event.pull_request.head.ref != 'i18n_sync'
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const I18N_FILES = [
"01-core",
"02-strings",
"03-dialogs",
"04-network",
"05-feedback",
"06-statistics",
"07-cardbrowser",
"08-widget",
"09-backup",
"10-preferences",
"11-arrays",
"16-multimedia-editor",
"17-model-manager",
"18-standard-models",
"20-search-preference",
"marketdescription",
];
let stringsLabel = "Strings";
async function addLabel(labels) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: labels
});
}
async function removeLabel(labels) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: labels,
});
}
async function addComments() {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `> [!IMPORTANT]
> **Maintainers**: This PR contains https://github.com/ankidroid/Anki-Android/labels/Strings changes
1. [Sync Translations](https://github.com/ankidroid/Anki-Android/actions/workflows/sync_translations.yml) before merging this PR and wait for the action to complete
2. Review and merge the [auto-generated PR](https://github.com/ankidroid/Anki-Android/pulls/mikehardy-machineaccount) in order to sync all user-submitted translations
3. [Sync Translations again](https://github.com/ankidroid/Anki-Android/actions/workflows/sync_translations.yml) and merge the [PR](https://github.com/ankidroid/Anki-Android/pulls/mikehardy-machineaccount) so the huge automated string changes caused by merging this PR are by themselves and easy to review`
})
}
const changedFiles = await github.rest.pulls.listFiles({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
// loop through list of files in current pr, then check if filename contains in i18n file name,
// set boolean to true and use the boolean in outer loop to add label
let fileChanged = false;
for (let files of changedFiles.data) {
for (let i18n of I18N_FILES) {
if (files.filename.includes(i18n)) {
fileChanged = true;
break;
}
}
if (fileChanged) {
addLabel([stringsLabel]);
addComments();
break;
}
}
async function getPullRequest() {
return await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
});
}
// if no file changed, remove label
const pullRequestData = await getPullRequest();
if (!fileChanged) {
if (pullRequestData.data.labels.find(label => label.name === stringsLabel)) {
console.log(`Removing #${stringsLabel} label from PR #${context.issue.number}`);
removeLabel([stringsLabel]);
}
}
add_new_contributor_label:
if: github.event.action == 'opened'
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const creator = context.payload.sender.login
const opts = github.rest.issues.listForRepo.endpoint.merge({
...context.issue,
creator,
state: 'all'
})
const issues = await github.paginate(opts)
for (const issue of issues) {
if (issue.number === context.issue.number) {
continue
}
if (issue.pull_request) {
return // creator is already a contributor
}
}
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['New contributor']
})