forked from ankidroid/Anki-Android
-
Notifications
You must be signed in to change notification settings - Fork 1
152 lines (136 loc) · 5.57 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
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/checkout@v3
- uses: actions/github-script@v6
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@v6
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",
"marketdescription",
"ankidroid-titles",
];
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 addComments() {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `Message to maintainers, this PR contains strings changes.
1. Before merging this PR, it is best to run the "Sync Translations" GitHub action, then make and merge a PR from the i18n_sync branch to get translations cleaned out.
2. Then merge this PR, and immediately do another translation PR so the huge change made by this PR's key changes are all by themselves.
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)`
})
}
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;
}
}