Skip to content

Commit 11d7b2d

Browse files
committed
DRY up the /deploy handling
There was a lot of copy/edited code in that part, owing to the fact that it is not _completely_ trivial to generalize adding the intended Check Runs, triggering the intended workflow runs, updating the PR comment with said information, and then updating the Check Runs, too. Unfortunately, there is no really good way to present this refactoring, as it collapses the separate MSYS2/MINGW code paths into a single one. The end result looks a lot cleaner, though, with the only tricky bit being how the comment is constructed (since there is now a variable number of workflow runs that may need to be listed). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent fd43ea1 commit 11d7b2d

1 file changed

Lines changed: 41 additions & 76 deletions

File tree

GitForWindowsHelper/slash-commands.js

Lines changed: 41 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -156,104 +156,69 @@ module.exports = async (context, req) => {
156156
commentId,
157157
text
158158
)
159-
if (!isMSYSPackage(package_name)) {
160-
let aarch64Answer
159+
160+
const toTrigger = []
161+
if (isMSYSPackage(package_name)) {
162+
toTrigger.push(
163+
{ architecture: 'x86_64' },
164+
{ architecture: 'i686' }
165+
)
166+
} else {
167+
toTrigger.push(
168+
{ displayArchitecture: 'i686/x86_64' }
169+
)
161170
if (needsSeparateARM64Build(package_name)) {
162-
const aarch64Id = await queueCheckRun(
163-
context,
164-
await getToken(),
165-
'git-for-windows',
166-
repo,
167-
ref,
168-
'deploy_aarch64',
169-
`Build and deploy ${package_name}`,
170-
`Deploying ${package_name}`
171-
)
172-
aarch64Answer = await triggerBuild('aarch64')
173-
await updateCheckRun(
174-
context,
175-
await getToken(),
176-
'git-for-windows',
177-
repo,
178-
aarch64Id, {
179-
details_url: aarch64Answer.html_url
180-
}
171+
toTrigger.push(
172+
{ architecture: 'aarch64', displayArchitecture: 'arm64' }
181173
)
182174
}
175+
}
183176

184-
const id = await queueCheckRun(
177+
for (const e of toTrigger) {
178+
const deployLabel = e.architecture ? `deploy_${e.architecture}` : 'deploy'
179+
e.id = await queueCheckRun(
185180
context,
186181
await getToken(),
187182
'git-for-windows',
188183
repo,
189184
ref,
190-
'deploy',
185+
deployLabel,
191186
`Build and deploy ${package_name}`,
192187
`Deploying ${package_name}`
193188
)
189+
}
194190

195-
const answer = await triggerBuild()
196-
const answer2 = await appendToComment(aarch64Answer
197-
? `The [i686/x86_64](${answer.html_url}) and the [arm64](${aarch64Answer.html_url}) workflow runs were started.`
198-
: `The workflow run [was started](${answer.html_url}).`
199-
)
191+
for (const e of toTrigger) {
192+
e.answer = await triggerBuild(e.architecture)
193+
}
194+
195+
const answer = await appendToComment(
196+
toTrigger.length === 1
197+
? `The workflow run [was started](${toTrigger[0].answer.html_url}).`
198+
: `${toTrigger.map((e, index) => {
199+
return `${
200+
index === 0 ? 'The' : index === toTrigger.length - 1 ? ' and the' : ', the'
201+
} [${
202+
e.displayArchitecture || e.architecture
203+
}](${
204+
e.answer.html_url
205+
})`
206+
}).join('')} workflow runs were started.`
207+
)
208+
209+
for (const e of toTrigger) {
200210
await updateCheckRun(
201211
context,
202212
await getToken(),
203213
'git-for-windows',
204214
repo,
205-
id, {
206-
details_url: answer.html_url
215+
e.id, {
216+
details_url: e.answer.html_url
207217
}
208218
)
209-
return `I edited the comment: ${answer2.html_url}`
210219
}
211220

212-
const x86_64Id = await queueCheckRun(
213-
context,
214-
await getToken(),
215-
'git-for-windows',
216-
repo,
217-
ref,
218-
'deploy_x86_64',
219-
`Build and deploy ${package_name}`,
220-
`Deploying ${package_name}`
221-
)
222-
const i686Id = await queueCheckRun(
223-
context,
224-
await getToken(),
225-
'git-for-windows',
226-
repo,
227-
ref,
228-
'deploy_i686',
229-
`Build and deploy ${package_name}`,
230-
`Deploying ${package_name}`
231-
)
232-
233-
const x86_64Answer = await triggerBuild('x86_64')
234-
const i686Answer = await triggerBuild('i686')
235-
const answer2 = await appendToComment(
236-
`The [x86_64](${x86_64Answer.html_url}) and the [i686](${i686Answer.html_url}) workflow runs were started.`
237-
)
238-
await updateCheckRun(
239-
context,
240-
await getToken(),
241-
'git-for-windows',
242-
repo,
243-
x86_64Id, {
244-
details_url: x86_64Answer.html_url
245-
}
246-
)
247-
await updateCheckRun(
248-
context,
249-
await getToken(),
250-
'git-for-windows',
251-
repo,
252-
i686Id, {
253-
details_url: i686Answer.html_url
254-
}
255-
)
256-
return `I edited the comment: ${answer2.html_url}`
221+
return `I edited the comment: ${answer.html_url}`
257222
}
258223

259224
if (command == '/git-artifacts') {

0 commit comments

Comments
 (0)