Skip to content

Commit 1df9095

Browse files
committed
/add relnote: verify that the package was deployed correctly
When calling `/add relnote` from a `component-updates` issue (and letting the GitForWindowsHelper GitHub App figure out the package name and version from the title) or from a corresponding PR, we would like to ensure that the corresponding package files have been deployed correctly. In git-for-windows/git#4523, we forgot to deploy all the package files, and it's an easy mistake to make, hence this commit, to help prevent the same in the future). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 741a618 commit 1df9095

2 files changed

Lines changed: 45 additions & 4 deletions

File tree

GitForWindowsHelper/slash-commands.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,10 +462,18 @@ module.exports = async (context, req) => {
462462

463463
await checkPermissions()
464464

465+
const { appendToIssueComment } = require('./issues')
465466
let [ , , , type, message ] = relNotesMatch
466467
if (!type) {
467-
const { guessReleaseNotes } = require('./component-updates');
468-
({ type, message } = await guessReleaseNotes(context, req.body.issue))
468+
const { guessReleaseNotes, getMissingDeployments } = require('./component-updates');
469+
let package_name, version
470+
({ type, message, package: package_name, version } = await guessReleaseNotes(context, req.body.issue))
471+
const missingDeployments = await getMissingDeployments(package_name, version)
472+
if (missingDeployments.length > 0) {
473+
const message = `The following deployment(s) are missing:\n\n* ${missingDeployments.join('\n* ')}`
474+
await appendToIssueComment(context, await getToken(), owner, repo, commentId, message)
475+
throw new Error(message)
476+
}
469477
}
470478

471479
await thumbsUp()
@@ -482,7 +490,6 @@ module.exports = async (context, req) => {
482490
message
483491
}
484492
)
485-
const { appendToIssueComment } = require('./issues')
486493
const answer2 = await appendToIssueComment(context, await getToken(), owner, repo, commentId, `The workflow run [was started](${answer.html_url})`)
487494
return `I edited the comment: ${answer2.html_url}`
488495
}

__tests__/index.test.js

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ function extend (a, ...list) {
168168
}
169169

170170
const testIssueComment = (comment, bodyExtra_, fn) => {
171+
let note = comment
172+
if (typeof comment === 'object') {
173+
note = comment.note
174+
comment = comment.comment
175+
}
171176
if (!fn) {
172177
fn = bodyExtra_
173178
bodyExtra_= undefined
@@ -201,7 +206,7 @@ const testIssueComment = (comment, bodyExtra_, fn) => {
201206
'x-github-event': 'issue_comment'
202207
})
203208

204-
test(`test ${comment}`, async () => {
209+
test(`test ${comment}${note ? ` (${note})` : ''}`, async () => {
205210
try {
206211
await fn(context)
207212
} catch (e) {
@@ -465,6 +470,12 @@ The workflow run [was started](dispatched-workflow-build-and-deploy.yml).`)
465470
expect(dispatchedWorkflows.map(e => e.payload.inputs.architecture)).toEqual(['aarch64'])
466471
})
467472

473+
const missingURL = 'https://wingit.blob.core.windows.net/x86-64/mingw-w64-x86_64-git-lfs-3.4.0-1-any.pkg.tar.xz'
474+
const mockDoesURLReturn404 = jest.fn(url => url === missingURL)
475+
jest.mock('../GitForWindowsHelper/https-request', () => {
476+
return { doesURLReturn404: mockDoesURLReturn404 }
477+
})
478+
468479
testIssueComment('/add release note', {
469480
issue: {
470481
number: 4281,
@@ -487,13 +498,36 @@ The workflow run [was started](dispatched-workflow-add-release-note.yml)`,
487498
})
488499
expect(mockGetInstallationAccessToken).toHaveBeenCalledTimes(1)
489500
expect(mockGitHubApiRequestAsApp).not.toHaveBeenCalled()
501+
expect(mockDoesURLReturn404).toHaveBeenCalledTimes(4)
490502
expect(dispatchedWorkflows).toHaveLength(1)
491503
expect(dispatchedWorkflows[0].payload.inputs).toEqual({
492504
message: 'Comes with [GNU TLS v3.8.0](https://lists.gnupg.org/pipermail/gnutls-help/2023-February/004816.html).',
493505
type: 'feature'
494506
})
495507
})
496508

509+
testIssueComment({ comment: '/add release note', note: 'missing deployment' }, {
510+
issue: {
511+
number: 4523,
512+
labels: [{ name: 'component-update' }],
513+
title: '[New git-lfs version] v3.4.0',
514+
body: `https://github.com/git-lfs/git-lfs/releases/tag/v3.4.0`
515+
}
516+
}, async (context) => {
517+
expect(await index(context, context.req)).toBeUndefined()
518+
expect(context.res).toEqual({
519+
body: `The following deployment(s) are missing:
520+
521+
* https://wingit.blob.core.windows.net/x86-64/mingw-w64-x86_64-git-lfs-3.4.0-1-any.pkg.tar.xz`,
522+
headers: undefined,
523+
status: 500
524+
})
525+
expect(mockGetInstallationAccessToken).toHaveBeenCalledTimes(1)
526+
expect(mockGitHubApiRequestAsApp).not.toHaveBeenCalled()
527+
expect(mockDoesURLReturn404).toHaveBeenCalledTimes(2)
528+
expect(dispatchedWorkflows).toHaveLength(0)
529+
})
530+
497531
test('a completed `tag-git` run triggers `git-artifacts` runs', async () => {
498532
const context = makeContext({
499533
action: 'completed',

0 commit comments

Comments
 (0)