From 041c4470f3cca66cdfad78866e33fedfd3839cf0 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:24:08 +0300 Subject: [PATCH 1/4] test sending random slack notification --- src/develop_actions.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index 783b46a..fe50928 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -16,9 +16,20 @@ const run = async () => { .slice(1) .join("/"); + const compare_commits = await octokit.request( + `GET /repos/${context.payload?.repository?.full_name}/compare/staging...${branch_name}`, + { + owner: context.payload?.repository?.owner?.login, + repo: context.payload?.repository?.name, + base: "staging", + head: branch_name, + } + ); + console.log("compare commit", compare_commits); + let commits = ""; - context.payload?.commits?.forEach((e, i) => { + compare_commits?.data?.commits?.forEach((e, i) => { if ( !e.message.includes("Merge") && !e.message.includes("Merged") && @@ -44,16 +55,6 @@ const run = async () => { base: "staging", } ); - const compare_commits = await octokit.request( - `GET /repos/${context.payload?.repository?.full_name}/compare/staging...${branch_name}`, - { - owner: context.payload?.repository?.owner?.login, - repo: context.payload?.repository?.name, - base: "staging", - head: branch_name, - } - ); - console.log("compare commit", compare_commits); if (createpr?.data) { axios .post( From 731dd45deaa8fb2500bc4f734419ef45b8486caa Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:24:33 +0300 Subject: [PATCH 2/4] test sending random slack notification --- src/develop_actions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index fe50928..bc616f7 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -25,7 +25,7 @@ const run = async () => { head: branch_name, } ); - console.log("compare commit", compare_commits); + console.log("compare commit", compare_commits?.data?.commits); let commits = ""; From 5e2dbbaec76b1ae81a7c5e94662c6fe398792088 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:30:38 +0300 Subject: [PATCH 3/4] test sending random slack notification --- src/develop_actions.js | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index bc616f7..6b657d4 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -44,6 +44,36 @@ const run = async () => { // if pr exists, update // if not create + if (compare_commits?.data?.commits?.length === 0) { + console.log("no changes"); + return; + } + + const options = { + blocks: [ + { + type: "header", + text: { + type: "plain_text", + text: `:sparkles: PR was created from ${branch_name} to satging`, + emoji: true, + }, + }, + { + type: "context", + elements: [ + { + text: `commits`, + type: "mrkdwn", + }, + ], + }, + { + type: "divider", + }, + ], + }; + const createpr = await octokit.request( `POST /repos/${context.payload?.repository?.full_name}/pulls`, { @@ -57,12 +87,7 @@ const run = async () => { ); if (createpr?.data) { axios - .post( - SLACK_WEBHOOK_URL, - JSON.stringify( - `PR from ${branch_name} to staging was created successfully` - ) - ) + .post(SLACK_WEBHOOK_URL, JSON.stringify(options)) .then((response) => { console.log("SUCCEEDED: Sent slack webhook", response.data); }) From 022c3c1277e5b2d424ce9bc8d28235bb2c68dffe Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:33:58 +0300 Subject: [PATCH 4/4] test sending random slack notification --- src/develop_actions.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index 6b657d4..8a42f36 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -31,10 +31,10 @@ const run = async () => { compare_commits?.data?.commits?.forEach((e, i) => { if ( - !e.message.includes("Merge") && - !e.message.includes("Merged") && - !e.message.includes("skip") && - !e.message.includes("Skip") + !e?.commit?.message.includes("Merge") && + !e?.commit?.message.includes("Merged") && + !e?.commit?.message.includes("skip") && + !e?.commit?.message.includes("Skip") ) commits = i === 0 ? "> " + e.message : commits + "\n\n" + "> " + e.message;