From 0660835bc599c5be321c27e683cb2e79bbbdca49 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 7 Jun 2024 10:45:21 +0200 Subject: [PATCH 1/3] get-webhook-event-payload: mark the script as executable Signed-off-by: Johannes Schindelin --- get-webhook-event-payload.js | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 get-webhook-event-payload.js diff --git a/get-webhook-event-payload.js b/get-webhook-event-payload.js old mode 100644 new mode 100755 index 6d5f342..0c97b13 --- a/get-webhook-event-payload.js +++ b/get-webhook-event-payload.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + (async () => { const fs = require('fs') From 6a31ce32517b066b863efb6509faf3343ed0d5f2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 7 Jun 2024 11:39:07 +0200 Subject: [PATCH 2/3] get-webhook-event-payload: make it easy to start at a given comment The most common use case for the `get-webhook-event-payload` script is to obtain the record of a failed slash command. To make it easier to use this script, then, accept the URL to the comment in the PR that contains said slash command. Signed-off-by: Johannes Schindelin --- get-webhook-event-payload.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/get-webhook-event-payload.js b/get-webhook-event-payload.js index 0c97b13..1ec1fb0 100755 --- a/get-webhook-event-payload.js +++ b/get-webhook-event-payload.js @@ -11,6 +11,16 @@ while (args.length) { let option = args.shift() + const issueCommentMatch = option.match(/^https:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/\d+#issuecomment-(\d+)$/) + if (issueCommentMatch) { + eventType = 'issue_comment' + const githubRequest = require('./GitForWindowsHelper/github-api-request') + const [owner, repo, comment_id] = issueCommentMatch.slice(1) + const comment = await githubRequest(console, null, 'GET', `/repos/${owner}/${repo}/issues/comments/${comment_id}`) + aroundDate = new Date(comment.updated_at) + continue + } + const optionWithArgument = option.match(/^(--[^=]+)=(.*)$/) if (optionWithArgument) { option = optionWithArgument[1] From bd8d28a6481ceb308e5d1493e6280f89d2915580 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 8 Jun 2024 00:09:46 +0200 Subject: [PATCH 3/3] /updpkgsums: pass all workflow dispatch inputs as strings When using a bare number as input, GitHub reacts with 422 as `statusCode` and the `statusMessage` "Unprocessable Entity". Signed-off-by: Johannes Schindelin --- GitForWindowsHelper/slash-commands.js | 2 +- __tests__/index.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/GitForWindowsHelper/slash-commands.js b/GitForWindowsHelper/slash-commands.js index 453c5e0..8eb80f7 100644 --- a/GitForWindowsHelper/slash-commands.js +++ b/GitForWindowsHelper/slash-commands.js @@ -124,7 +124,7 @@ module.exports = async (context, req) => { 'updpkgsums.yml', 'main', { repo, - 'pr-number': issueNumber, + 'pr-number': '' + issueNumber, actor: commenter } ); diff --git a/__tests__/index.test.js b/__tests__/index.test.js index bb0000f..778015e 100644 --- a/__tests__/index.test.js +++ b/__tests__/index.test.js @@ -354,7 +354,7 @@ The workflow run [was started](dispatched-workflow-updpkgsums.yml).`, expect(mockGetInstallationAccessToken).toHaveBeenCalledTimes(1) expect(mockGitHubApiRequestAsApp).not.toHaveBeenCalled() expect(dispatchedWorkflows).toHaveLength(1) - expect(dispatchedWorkflows.map(e => e.payload.inputs['pr-number'])).toEqual([104]) + 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')