From b65f1ea24334e104eb1dca2b0411ebc907b4b8b3 Mon Sep 17 00:00:00 2001 From: Bernd Verst Date: Mon, 21 Aug 2023 17:53:35 -0700 Subject: [PATCH] Add `\rerun ` command for failed jobs in workflows (#3095) Signed-off-by: Bernd Verst --- .github/scripts/dapr_bot.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/scripts/dapr_bot.js b/.github/scripts/dapr_bot.js index 37b4cdd58..30e0ba016 100644 --- a/.github/scripts/dapr_bot.js +++ b/.github/scripts/dapr_bot.js @@ -94,6 +94,10 @@ async function handleIssueCommentCreate({ github, context }) { case '/ok-to-test': await cmdOkToTest(github, issue, isFromPulls) break + case command.match(/^\/rerun \d+/)?.input: + const workflowrunid = command.match(/\d+/)[0]; + await rerunWorkflow(github, issue, workflowrunid) + break default: console.log( `[handleIssueCommentCreate] command ${command} not found, exiting.` @@ -234,3 +238,18 @@ async function cmdOkToTest(github, issue, isFromPulls) { ) } } + +/** + * Rerun all failed jobs of a given workflow run ID. + * @param {*} github GitHub object reference + * @param {*} issue GitHub issue object + * @param {int} workflowrunid the workflow run ID for which to rerun all failed jobs + */ +async function rerunWorkflow(github, issue, workflowrunid) { + // Rerun all failed jobs of the specified workflow run + const pull = await github.rest.actions.reRunWorkflowFailedJobs({ + owner: issue.owner, + repo: issue.repo, + run_id: workflowrunid, + }); +} \ No newline at end of file