From 1c812b103b429310bdcd79f76172d5b7f5fdcabd Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 17 Dec 2023 12:42:20 +0100 Subject: [PATCH] Add the `/updpkgsums` slash command As with most of the other slash commands, this triggers a GitHub workflow run in `git-for-windows-automation`, in this instance, unsurprisingly the `upkpkgsums.yml` one. The idea is to help contributors with their Pull Requests that fail CI builds solely due to mismatched checksums after modifying, adding or removing files from a package. Signed-off-by: Johannes Schindelin --- GitForWindowsHelper/slash-commands.js | 29 ++++++++++++++++++++++ README.md | 6 +++++ __tests__/index.test.js | 35 +++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/GitForWindowsHelper/slash-commands.js b/GitForWindowsHelper/slash-commands.js index a8d40f3..af401a0 100644 --- a/GitForWindowsHelper/slash-commands.js +++ b/GitForWindowsHelper/slash-commands.js @@ -105,6 +105,35 @@ module.exports = async (context, req) => { return `I edited the comment: ${commentURL}` } + if (command == '/updpkgsums') { + if (owner !== 'git-for-windows' + || !req.body.issue.pull_request + || !['build-extra', 'MINGW-packages', 'MSYS2-packages'].includes(repo)) { + return `Ignoring ${command} in unexpected repo: ${commentURL}` + } + + await checkPermissions() + await thumbsUp() + + const triggerWorkflowDispatch = require('./trigger-workflow-dispatch') + const answer = await triggerWorkflowDispatch( + context, + await getToken(), + 'git-for-windows', + 'git-for-windows-automation', + 'updpkgsums.yml', + 'main', { + repo, + 'pr-number': issueNumber, + actor: commenter + } + ); + const { appendToIssueComment } = require('./issues'); + ({ html_url: commentURL } = await appendToIssueComment(context, await getToken(), owner, repo, commentId, `The workflow run [was started](${answer.html_url}).`)) + + return `I edited the comment: ${commentURL}` + } + const deployMatch = command.match(/^\/deploy(\s+(\S+)\s*)?$/) if (deployMatch) { if (owner !== 'git-for-windows' diff --git a/README.md b/README.md index faf4c2d..a730990 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,12 @@ For convenience, the command can be abbreviated as `/add relnote ]` **Where can it be called?** In Pull Requests of Git for Windows' [`build-extra`](https://github.com/git-for-windows/build-extra), [`MINGW-packages`](https://github.com/git-for-windows/MINGW-packages) and [`MSYS2-packages`](https://github.com/git-for-windows/MSYS2-packages) repositories. diff --git a/__tests__/index.test.js b/__tests__/index.test.js index 07275aa..ecfd1a5 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -307,6 +307,41 @@ The MINGW workflow run [was started](dispatched-workflow-open-pr.yml)` }) }) +testIssueComment('/updpkgsums', { + issue: { + number: 104, + title: 'Make tig launchable from PowerShell/Command Prompt', + body: 'Add tig.exe to /cmd/', + pull_request: { + html_url: 'https://github.com/git-for-windows/MINGW-packages/pull/104' + } + }, + repository: { + name: 'MINGW-packages' + } +}, async (context) => { + expect(await index(context, context.req)).toBeUndefined() + expect(context.res).toEqual({ + body: `I edited the comment: appended-comment-body-existing comment body + +The workflow run [was started](dispatched-workflow-updpkgsums.yml).`, + headers: undefined, + status: undefined + }) + expect(mockGetInstallationAccessToken).toHaveBeenCalledTimes(1) + expect(mockGitHubApiRequestAsApp).not.toHaveBeenCalled() + expect(dispatchedWorkflows).toHaveLength(1) + expect(dispatchedWorkflows.map(e => e.payload.inputs['pr-number'])).toEqual([104]) + expect(mockGitHubApiRequest).toHaveBeenCalled() + const comment = mockGitHubApiRequest.mock.calls[mockGitHubApiRequest.mock.calls.length - 1] + expect(comment[3]).toEqual('/repos/git-for-windows/MINGW-packages/issues/comments/0') + expect(comment[4]).toEqual({ + body: `existing comment body + +The workflow run [was started](dispatched-workflow-updpkgsums.yml).` + }) +}) + let mockQueueCheckRun = jest.fn(() => 'check-run-id') let mockUpdateCheckRun = jest.fn() let mockListCheckRunsForCommit = jest.fn((_context, _token, _owner, _repo, rev, checkRunName) => {