From fa9375341c6fd59c306f3d2bc95f10bd6414b48d Mon Sep 17 00:00:00 2001 From: zeme-wana <15709674+zeme-wana@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:12:56 +0100 Subject: [PATCH] New amends to slack-message-broker (#6632) --- .github/workflows/slack-message-broker.yml | 57 ++++++++++++---------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/.github/workflows/slack-message-broker.yml b/.github/workflows/slack-message-broker.yml index 53394fb729c..81bb37638c8 100644 --- a/.github/workflows/slack-message-broker.yml +++ b/.github/workflows/slack-message-broker.yml @@ -26,6 +26,7 @@ jobs: - name: Prepare Slack Message uses: actions/github-script@main id: prepare-slack-message + with: script: | console.log(${{ toJson(github.event) }}); @@ -67,10 +68,33 @@ jobs: } } + + const isWorkflowRunEvent = "${{ github.event_name }}" == "workflow_run"; + const isCheckRunEvent = "${{ github.event_name }}" == "check_run"; + + + function isDraftPullRequest() { + const workflowRunPrIsNull = "${{ github.event.workflow_run.pull_requests == null }}" === "true"; + const isDraftPrWorkflowRun = "${{ github.event.workflow_run.pull_requests[0][0].draft }}" === "true"; + + const checkRunPrIsNull = "${{ github.event.check_run.check_suite.pull_requests == null }}" === "true"; + const isDraftPrCheckRun = "${{ github.event.check_run.check_suite.pull_requests[0].draft }}" === "true"; + + console.log(`isWorkflowRunEvent: ${isWorkflowRunEvent}`); + console.log(`isCheckRunEvent: ${isCheckRunEvent}`); + console.log(`workflowRunPrIsNull: ${workflowRunPrIsNull}`); + console.log(`checkRunPrIsNull: ${checkRunPrIsNull}`); + console.log(`isDraftPrWorkflowRun: ${isDraftPrWorkflowRun}`); + console.log(`isDraftPrCheckRun: ${isDraftPrCheckRun}`); + + return isDraftPrWorkflowRun || isDraftPrCheckRun; + } + + const slackMembers = getSlackMembersToBeNotified(); + const isDraftPR = isDraftPullRequest(); - let message = ""; - let shouldSendMessage = false; - let slackMembers = getSlackMembersToBeNotified(); + let message; + let shouldSendMessage; function handleWorkflowRunEvent() { @@ -113,36 +137,15 @@ jobs: } - if ("${{ github.event_name }}" == "workflow_run") { + if (!isDraftPR && isWorkflowRunEvent) { handleWorkflowRunEvent(); - } else if ("${{ github.event_name }}" == "check_run") { + } else if (!isDraftPR && isCheckRunEvent) { handleCheckRunEvent(); } else { - message = `Unknown event: ${{ github.event_name }}`; + message = `Unknown event or draft PR: ${{ github.event_name }}`; shouldSendMessage = true; } - - function printDraftPrDebugInfo() { - const eventName = "${{ github.event_name }}"; - const workflowRunPrIsNull = "${{ github.event.workflow_run.pull_requests == null }}"; - const checkRunPrIsNull = "${{ github.event.check_run.check_suite.pull_requests == null }}"; - const pullRequestZeroWorkflowRun = "${{ github.event.workflow_run.pull_requests[0] }}"; - const pullRequestZeroCheckRun = "${{ github.event.check_run.check_suite.pull_requests[0] }}"; - const isDraftPrWorkflowRun = "${{ github.event.workflow_run.pull_requests[0].draft }}"; - const isDraftPrCheckRun = "${{ github.event.check_run.check_suite.pull_requests[0].draft }}"; - - console.log(`eventName: ${eventName}`); - console.log(`workflowRunPrIsNull: ${workflowRunPrIsNull}`); - console.log(`checkRunPrIsNull: ${checkRunPrIsNull}`); - console.log(`pullRequestZeroWorkflowRun: ${pullRequestZeroWorkflowRun}`); - console.log(`pullRequestZeroCheckRun: ${pullRequestZeroCheckRun}`); - console.log(`isDraftPrWorkflowRun: ${isDraftPrWorkflowRun}`); - console.log(`isDraftPrCheckRun: ${isDraftPrCheckRun}`); - } - - printDraftPrDebugInfo(); - console.log(`message: ${message}`); console.log(`shouldSendMessage: ${shouldSendMessage}`);