From 2ad0b2aafb08631c13468ac9a329146f5362889e Mon Sep 17 00:00:00 2001 From: Jan Hesse Date: Thu, 20 Jun 2024 22:52:42 +0200 Subject: [PATCH] fix: Comments on Issues should not trigger 'checks' action (#759) Co-authored-by: Shine Lee --- __fixtures__/unit/helper.js | 3 ++- docs/changelog.rst | 1 + lib/actions/checks.js | 15 ++++++++++++--- lib/actions/merge.js | 3 +++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/__fixtures__/unit/helper.js b/__fixtures__/unit/helper.js index 6bcc283d..8445714a 100644 --- a/__fixtures__/unit/helper.js +++ b/__fixtures__/unit/helper.js @@ -64,7 +64,8 @@ module.exports = { user: { login: 'creator' }, - number: (options.number) ? options.number : 1 + number: (options.number) ? options.number : 1, + pull_request: {} } }, log: { diff --git a/docs/changelog.rst b/docs/changelog.rst index d3d5a16b..628ff596 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,5 +1,6 @@ CHANGELOG ===================================== +| June 20, 2024: fix: Comments on Issues should not trigger `checks` action `#759 `_ | June 20, 2024: fix: Respect all comments in lastComment validator and comment action `#755 `_ | June 12, 2024: feat: Support `issue_comment` event as trigger for actions `#754 `_ | June 10, 2024: fix: Docker image not working `#753 `_ diff --git a/lib/actions/checks.js b/lib/actions/checks.js index 8ff479b1..2ef0d95b 100644 --- a/lib/actions/checks.js +++ b/lib/actions/checks.js @@ -12,9 +12,9 @@ const createChecks = async (context, payload, actionObj) => { // Note: octokit (wrapped by probot) requires head_branch. // Contradicting API docs that only requires head_sha // --> https://developer.github.com/v3/checks/runs/#create-a-check-run - if (context.payload.checksuite) { - params.head_branch = context.payload.checksuite.head_branch - params.head_sha = context.payload.checksuite.head_sha + if (context.payload.check_suite) { + params.head_branch = context.payload.check_suite.head_branch + params.head_sha = context.payload.check_suite.head_sha } else if (context.eventName === 'issue_comment') { const issueNumber = context.payload.issue.number const pullRequest = (await actionObj.githubAPI.getPR(context, issueNumber)).data @@ -104,6 +104,9 @@ class Checks extends Action { } async beforeValidate (context, settings, name) { + if (context.eventName === 'issue_comment' && !context.payload.issue?.pull_request) { + return Promise.resolve() + } const result = await createChecks(context, { status: 'in_progress', output: { @@ -127,10 +130,16 @@ class Checks extends Action { } async run ({ context, settings, payload }) { + if (context.eventName === 'issue_comment' && !context.payload.issue?.pull_request) { + return Promise.resolve() + } await createChecks(context, payload, this) } async afterValidate (context, settings, name, results) { + if (context.eventName === 'issue_comment' && !context.payload.issue?.pull_request) { + return Promise.resolve() + } const checkRunResult = this.checkRunResult.get(name) const payload = settings.payload ? this.populatePayloadWithResult(settings.payload, results, context) : undefined diff --git a/lib/actions/merge.js b/lib/actions/merge.js index e2468d0b..ee5f83c7 100644 --- a/lib/actions/merge.js +++ b/lib/actions/merge.js @@ -44,6 +44,9 @@ class Merge extends Action { async beforeValidate () {} async afterValidate (context, settings, name, results) { + if (context.eventName === 'issue_comment' && !context.payload.issue?.pull_request) { + return Promise.resolve() + } if (settings.merge_method && !MERGE_METHOD_OPTIONS.includes(settings.merge_method)) { throw new UnSupportedSettingError(`Unknown Merge method, supported options are ${MERGE_METHOD_OPTIONS.join(', ')}`) }