|
1 | | -name: 🛠️ Add/Remove Labels |
| 1 | +name: Add Needs Review label |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request_target: |
5 | | - types: [ opened, closed ] |
| 4 | + pull_request: |
| 5 | + types: [opened, ready_for_review] |
6 | 6 |
|
7 | | -jobs: |
8 | | - merge_job: |
9 | | - if: github.event.pull_request.merged == true |
10 | | - permissions: |
11 | | - contents: read |
12 | | - pull-requests: write |
13 | | - runs-on: ubuntu-latest |
14 | | - steps: |
15 | | - - uses: actions/github-script@v8 |
16 | | - with: |
17 | | - script: | |
18 | | - let removeLabelsList = [ |
19 | | - "Pending Merge", |
20 | | - "Needs Author Reply", |
21 | | - "Needs Review", |
22 | | - "Review High Priority", |
23 | | - "Needs Second Approval", |
24 | | - "Blocked by dependency", |
25 | | - "Needs a new dev", |
26 | | - "squash-merge", |
27 | | - "Keep Open", |
28 | | - "Stable" |
29 | | - ]; |
| 7 | +permissions: |
| 8 | + pull-requests: write |
| 9 | + issues: write |
30 | 10 |
|
31 | | - async function removeLabel(label) { |
32 | | - await github.rest.issues.removeLabel({ |
33 | | - owner: context.repo.owner, |
34 | | - repo: context.repo.repo, |
35 | | - issue_number: context.issue.number, |
36 | | - name: label |
37 | | - }); |
38 | | - } |
39 | | -
|
40 | | - async function addPostMergeComments() { |
41 | | - await github.rest.issues.createComment({ |
42 | | - owner: context.repo.owner, |
43 | | - repo: context.repo.repo, |
44 | | - issue_number: context.issue.number, |
45 | | - 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. |
46 | | - |
47 | | - Read more about updating strings on the wiki, |
48 | | - - [localization-administration](https://github.com/ankidroid/Anki-Android/wiki/Development-Guide#localization-administration) |
49 | | - - [download-localized-strings](https://github.com/ankidroid/Anki-Android/wiki/Development-Guide#download-localized-strings)` |
50 | | - }) |
51 | | - } |
52 | | -
|
53 | | - let result = await github.rest.issues.listLabelsOnIssue({ |
54 | | - owner: context.repo.owner, |
55 | | - repo: context.repo.repo, |
56 | | - issue_number: context.issue.number, |
57 | | - }); |
58 | | -
|
59 | | - if (result.data !== null && result.data.length > 0) { |
60 | | - let labels = result.data; |
61 | | - for (let label of labels) { |
62 | | - if (removeLabelsList.includes(label.name)) { |
63 | | - console.log("Removed: ", label.name); |
64 | | - removeLabel(label.name); |
65 | | - } |
66 | | -
|
67 | | - // add post merge comments for 'strings' labeled PR |
68 | | - if (label.name == "Strings") { |
69 | | - addPostMergeComments(); |
70 | | - } |
71 | | - } |
72 | | - } |
73 | | -
|
74 | | - add_label: |
75 | | - 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' |
76 | | - permissions: |
77 | | - contents: read |
78 | | - pull-requests: write |
| 11 | +jobs: |
| 12 | + add-needs-review: |
| 13 | + if: github.event.pull_request.draft == false |
79 | 14 | runs-on: ubuntu-latest |
80 | 15 | steps: |
81 | | - - uses: actions/github-script@v8 |
| 16 | + - name: Add Needs Review label |
| 17 | + uses: actions/github-script@v7 |
82 | 18 | with: |
83 | 19 | script: | |
84 | | - const I18N_FILES = [ |
85 | | - "01-core", |
86 | | - "02-strings", |
87 | | - "03-dialogs", |
88 | | - "04-network", |
89 | | - "05-feedback", |
90 | | - "06-statistics", |
91 | | - "07-cardbrowser", |
92 | | - "08-widget", |
93 | | - "09-backup", |
94 | | - "10-preferences", |
95 | | - "11-arrays", |
96 | | - "16-multimedia-editor", |
97 | | - "17-model-manager", |
98 | | - "18-standard-models", |
99 | | - "20-search-preference", |
100 | | - "marketdescription", |
101 | | - ]; |
102 | | -
|
103 | | - let stringsLabel = "Strings"; |
104 | | -
|
105 | | - async function addLabel(labels) { |
106 | | - await github.rest.issues.addLabels({ |
107 | | - owner: context.repo.owner, |
108 | | - repo: context.repo.repo, |
109 | | - issue_number: context.issue.number, |
110 | | - labels: labels |
111 | | - }); |
112 | | - } |
113 | | -
|
114 | | - async function removeLabel(labels) { |
115 | | - await github.rest.issues.removeLabel({ |
116 | | - owner: context.repo.owner, |
117 | | - repo: context.repo.repo, |
118 | | - issue_number: context.issue.number, |
119 | | - name: labels, |
120 | | - }); |
121 | | - } |
122 | | -
|
123 | | - async function addComments() { |
124 | | - await github.rest.issues.createComment({ |
125 | | - owner: context.repo.owner, |
126 | | - repo: context.repo.repo, |
127 | | - issue_number: context.issue.number, |
128 | | - body: `> [!IMPORTANT] |
129 | | - > **Maintainers**: This PR contains https://github.com/ankidroid/Anki-Android/labels/Strings changes |
130 | | - |
131 | | - 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 |
132 | | - 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 |
133 | | - 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` |
134 | | - }) |
135 | | - } |
136 | | -
|
137 | | - const changedFiles = await github.rest.pulls.listFiles({ |
| 20 | + github.rest.issues.addLabels({ |
138 | 21 | owner: context.repo.owner, |
139 | 22 | repo: context.repo.repo, |
140 | | - pull_number: context.issue.number, |
141 | | - }); |
142 | | -
|
143 | | - // loop through list of files in current pr, then check if filename contains in i18n file name, |
144 | | - // set boolean to true and use the boolean in outer loop to add label |
145 | | - let fileChanged = false; |
146 | | - for (let files of changedFiles.data) { |
147 | | - for (let i18n of I18N_FILES) { |
148 | | - if (files.filename.includes(i18n)) { |
149 | | - fileChanged = true; |
150 | | - break; |
151 | | - } |
152 | | - } |
153 | | -
|
154 | | - if (fileChanged) { |
155 | | - addLabel([stringsLabel]); |
156 | | - addComments(); |
157 | | - break; |
158 | | - } |
159 | | - } |
160 | | -
|
161 | | - async function getPullRequest() { |
162 | | - return await github.rest.pulls.get({ |
163 | | - owner: context.repo.owner, |
164 | | - repo: context.repo.repo, |
165 | | - pull_number: context.issue.number, |
166 | | - }); |
167 | | - } |
168 | | -
|
169 | | - // if no file changed, remove label |
170 | | - const pullRequestData = await getPullRequest(); |
171 | | - if (!fileChanged) { |
172 | | - if (pullRequestData.data.labels.find(label => label.name === stringsLabel)) { |
173 | | - console.log(`Removing #${stringsLabel} label from PR #${context.issue.number}`); |
174 | | - removeLabel([stringsLabel]); |
175 | | - } |
176 | | - } |
177 | | -
|
178 | | - add_new_contributor_label: |
179 | | - if: github.event.action == 'opened' |
180 | | - permissions: |
181 | | - contents: read |
182 | | - pull-requests: write |
183 | | - runs-on: ubuntu-latest |
184 | | - steps: |
185 | | - - uses: actions/github-script@v8 |
186 | | - with: |
187 | | - script: | |
188 | | - const creator = context.payload.sender.login |
189 | | - const opts = github.rest.issues.listForRepo.endpoint.merge({ |
190 | | - ...context.issue, |
191 | | - creator, |
192 | | - state: 'all' |
193 | | - }) |
194 | | - const issues = await github.paginate(opts) |
195 | | - for (const issue of issues) { |
196 | | - if (issue.number === context.issue.number) { |
197 | | - continue |
198 | | - } |
199 | | - if (issue.pull_request) { |
200 | | - return // creator is already a contributor |
201 | | - } |
202 | | - } |
203 | | - await github.rest.issues.addLabels({ |
204 | 23 | issue_number: context.issue.number, |
205 | | - owner: context.repo.owner, |
206 | | - repo: context.repo.repo, |
207 | | - labels: ['New contributor'] |
| 24 | + labels: ['Needs Review'] |
208 | 25 | }) |
0 commit comments