From d1afc3b3af85e2c05e4f567a402a2746b5eb4df8 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:02:48 +0300 Subject: [PATCH 01/19] test commit --- src/develop_actions.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index 721f153..7edc15d 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -40,7 +40,6 @@ const run = async () => { base: "staging", } ); - console.log("createPr", createpr?.data); if (createpr?.data) { axios .post( From ca8226e300cac9484a524c96a90ae3dec1b4c4f8 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:07:44 +0300 Subject: [PATCH 02/19] 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 7edc15d..ec48ee0 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -43,16 +43,16 @@ const run = async () => { if (createpr?.data) { axios .post( - `${SLACK_WEBHOOK_URL}`, - `PR from ${branch_name} to staging was created successfully` + SLACK_WEBHOOK_URL, + JSON.stringify( + `PR from ${branch_name} to staging was created successfully` + ) ) .then((response) => { console.log("SUCCEEDED: Sent slack webhook", response.data); - resolve(response.data); }) .catch((error) => { console.log("FAILED: Send slack webhook", error); - reject(new Error("FAILED: Send slack webhook")); }); } const compare_commits = await octokit.request( From 9fc989367c945595d45f1b71098f5b862f730242 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:12:13 +0300 Subject: [PATCH 03/19] test sending random slack notification --- src/develop_actions.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/develop_actions.js b/src/develop_actions.js index ec48ee0..fa76d8d 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -40,6 +40,7 @@ const run = async () => { base: "staging", } ); + console.log(createpr?.data); if (createpr?.data) { axios .post( @@ -54,6 +55,21 @@ const run = async () => { .catch((error) => { console.log("FAILED: Send slack webhook", error); }); + } else { + // fetch pr from branch_name to staging + // update existing pr + console.log("pr exists"); + axios + .post( + SLACK_WEBHOOK_URL, + JSON.stringify(`PR from ${branch_name} to staging already exist`) + ) + .then((response) => { + console.log("SUCCEEDED: Sent slack webhook", response.data); + }) + .catch((error) => { + console.log("FAILED: Send slack webhook", error); + }); } const compare_commits = await octokit.request( `GET /repos/${context.payload?.repository?.full_name}/compare/staging...${branch_name}`, From f5cb7301912394025ff4442373d1472a0a07722b Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:15:01 +0300 Subject: [PATCH 04/19] test sending random slack notification --- src/develop_actions.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index fa76d8d..d090871 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -29,6 +29,10 @@ const run = async () => { i === 0 ? "> " + e.message : commits + "\n\n" + "> " + e.message; }); + // fetch pr from branch_name to staging to check if it exists + // if pr exists, update + // if not create + const createpr = await octokit.request( `POST /repos/${context.payload?.repository?.full_name}/pulls`, { @@ -56,7 +60,6 @@ const run = async () => { console.log("FAILED: Send slack webhook", error); }); } else { - // fetch pr from branch_name to staging // update existing pr console.log("pr exists"); axios From 6d714c75ac6445265d915fc64b4541568c67c362 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:18:06 +0300 Subject: [PATCH 05/19] test sending random slack notification --- src/develop_actions.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index d090871..94b5431 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -44,7 +44,16 @@ const run = async () => { base: "staging", } ); - console.log(createpr?.data); + 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 commits", compare_commits); if (createpr?.data) { axios .post( @@ -74,16 +83,6 @@ const run = async () => { console.log("FAILED: Send slack webhook", error); }); } - 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_commits); } catch (error) { console.log("error", error?.message); } From 1438fd11fd39e0e7bafcf9743221bfecda97369c Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:21:15 +0300 Subject: [PATCH 06/19] 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 94b5431..783b46a 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -53,7 +53,7 @@ const run = async () => { head: branch_name, } ); - console.log("compare commits", compare_commits); + console.log("compare commit", compare_commits); if (createpr?.data) { axios .post( From 041c4470f3cca66cdfad78866e33fedfd3839cf0 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:24:08 +0300 Subject: [PATCH 07/19] 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 08/19] 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 09/19] 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 10/19] 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; From 3fd5a3fdc9e58e08f87bcc2f9f24983b82fc17ed Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:37:13 +0300 Subject: [PATCH 11/19] test sending random slack notification --- src/develop_actions.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index 8a42f36..42ebb8c 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -25,7 +25,6 @@ const run = async () => { head: branch_name, } ); - console.log("compare commit", compare_commits?.data?.commits); let commits = ""; @@ -37,7 +36,9 @@ const run = async () => { !e?.commit?.message.includes("Skip") ) commits = - i === 0 ? "> " + e.message : commits + "\n\n" + "> " + e.message; + i === 0 + ? "> " + e.commit.message + : commits + "\n\n" + "> " + e.commit.message; }); // fetch pr from branch_name to staging to check if it exists @@ -55,7 +56,7 @@ const run = async () => { type: "header", text: { type: "plain_text", - text: `:sparkles: PR was created from ${branch_name} to satging`, + text: `:sparkles: PR was created from ${branch_name} to staging`, emoji: true, }, }, @@ -63,7 +64,7 @@ const run = async () => { type: "context", elements: [ { - text: `commits`, + text: commits, type: "mrkdwn", }, ], From 07241952e0fdf365502e267b1f04887d51bbab6f Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:38:00 +0300 Subject: [PATCH 12/19] test sending random slack notification --- src/develop_actions.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index 42ebb8c..b41fe7a 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -52,26 +52,24 @@ const run = async () => { const options = { blocks: [ - { - type: "header", - text: { - type: "plain_text", - text: `:sparkles: PR was created from ${branch_name} to staging`, - emoji: true, - }, - }, + // { + // type: "header", + // text: { + // type: "plain_text", + // text: `:sparkles: PR was created from ${branch_name} to staging`, + // emoji: true, + // }, + // }, { type: "context", elements: [ { - text: commits, type: "mrkdwn", + text: `:sparkles: PR was created from ${branch_name} to staging`, + emoji: true, }, ], }, - { - type: "divider", - }, ], }; From ce1d86b2ddc08afd9025a705e336d53222e48ce6 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 22 Apr 2022 23:58:18 +0300 Subject: [PATCH 13/19] test update pr --- src/develop_actions.js | 115 ++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 42 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index b41fe7a..3e00a1e 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -8,14 +8,16 @@ const octokit = github.getOctokit(GITHUB_TOKEN); const { context = {} } = github; const run = async () => { - try { - const branch_name = context.payload?.head_commit?.message - ?.split("from")[1] - .split("\n")[0] - ?.split("/") - .slice(1) - .join("/"); + const branch_name = context.payload?.head_commit?.message + ?.split("from")[1] + .split("\n")[0] + ?.split("/") + .slice(1) + .join("/"); + // fetching commits + let commits = ""; + try { const compare_commits = await octokit.request( `GET /repos/${context.payload?.repository?.full_name}/compare/staging...${branch_name}`, { @@ -28,6 +30,11 @@ const run = async () => { let commits = ""; + if (compare_commits?.data?.commits?.length === 0) { + commits = ""; + return; + } + compare_commits?.data?.commits?.forEach((e, i) => { if ( !e?.commit?.message.includes("Merge") && @@ -44,35 +51,33 @@ const run = async () => { // fetch pr from branch_name to staging to check if it exists // if pr exists, update // if not create + } catch (error) { + console.log(error?.message); + } - if (compare_commits?.data?.commits?.length === 0) { - console.log("no changes"); - return; - } - + // attempt to create PR + try { const options = { blocks: [ - // { - // type: "header", - // text: { - // type: "plain_text", - // text: `:sparkles: PR was created from ${branch_name} to staging`, - // emoji: true, - // }, - // }, + { + type: "header", + text: { + type: "plain_text", + text: ``, + emoji: true, + }, + }, { type: "context", elements: [ { type: "mrkdwn", - text: `:sparkles: PR was created from ${branch_name} to staging`, - emoji: true, + text: `<:sparkles: PR was created from ${branch_name} to staging>`, }, ], }, ], }; - const createpr = await octokit.request( `POST /repos/${context.payload?.repository?.full_name}/pulls`, { @@ -85,32 +90,58 @@ const run = async () => { } ); if (createpr?.data) { - axios - .post(SLACK_WEBHOOK_URL, JSON.stringify(options)) - .then((response) => { - console.log("SUCCEEDED: Sent slack webhook", response.data); - }) - .catch((error) => { - console.log("FAILED: Send slack webhook", error); - }); + console.log("pr created successfully"); + // axios + // .post(SLACK_WEBHOOK_URL, JSON.stringify(options)) + // .then((response) => { + // console.log("SUCCEEDED: Sent slack webhook", response.data); + // }) + // .catch((error) => { + // console.log("FAILED: Send slack webhook", error); + // }); } else { // update existing pr console.log("pr exists"); - axios - .post( - SLACK_WEBHOOK_URL, - JSON.stringify(`PR from ${branch_name} to staging already exist`) - ) - .then((response) => { - console.log("SUCCEEDED: Sent slack webhook", response.data); - }) - .catch((error) => { - console.log("FAILED: Send slack webhook", error); - }); + // axios + // .post( + // SLACK_WEBHOOK_URL, + // JSON.stringify(`PR from ${branch_name} to staging already exist`) + // ) + // .then((response) => { + // console.log("SUCCEEDED: Sent slack webhook", response.data); + // }) + // .catch((error) => { + // console.log("FAILED: Send slack webhook", error); + // }); } } catch (error) { console.log("error", error?.message); } + + // update PR + try { + // fetching existing PR + const existing_pr = await this.octokit.rest.pulls.list({ + owner: context.payload?.repository?.owner?.login, + repo: context.payload?.repository?.name, + state: "open", + head: branch_name, + base: "staging", + }); + console.log("existing PR", existing_pr); + // update pr + await this.octokit.rest.pulls.update({ + pull_number: existing_pr?.data[0].number, + owner: context.payload?.repository?.owner?.login, + repo: context.payload?.repository?.name, + title: branch_name, + body: commits, + head: branch_name, + base: "staging", + }); + } catch (error) { + console.log("error", error?.message); + } }; run(); From e07a19c3b8366f5814c584ca34b5cc2b223fe988 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 23 Apr 2022 00:00:22 +0300 Subject: [PATCH 14/19] test update pr --- src/develop_actions.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index 3e00a1e..bd1a9b8 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -121,7 +121,7 @@ const run = async () => { // update PR try { // fetching existing PR - const existing_pr = await this.octokit.rest.pulls.list({ + const existing_pr = await octokit.rest.pulls.list({ owner: context.payload?.repository?.owner?.login, repo: context.payload?.repository?.name, state: "open", @@ -130,7 +130,7 @@ const run = async () => { }); console.log("existing PR", existing_pr); // update pr - await this.octokit.rest.pulls.update({ + const update_pr = await octokit.rest.pulls.update({ pull_number: existing_pr?.data[0].number, owner: context.payload?.repository?.owner?.login, repo: context.payload?.repository?.name, @@ -139,6 +139,7 @@ const run = async () => { head: branch_name, base: "staging", }); + console.log(update_pr?.data); } catch (error) { console.log("error", error?.message); } From 4f102fb4f843500a88b27e58779ca7836bc4b92c Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 23 Apr 2022 00:05:05 +0300 Subject: [PATCH 15/19] test update pr --- src/develop_actions.js | 92 ++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 44 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index bd1a9b8..d6a1629 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -57,16 +57,8 @@ const run = async () => { // attempt to create PR try { - const options = { + let options = { blocks: [ - { - type: "header", - text: { - type: "plain_text", - text: ``, - emoji: true, - }, - }, { type: "context", elements: [ @@ -90,29 +82,15 @@ const run = async () => { } ); if (createpr?.data) { - console.log("pr created successfully"); - // axios - // .post(SLACK_WEBHOOK_URL, JSON.stringify(options)) - // .then((response) => { - // console.log("SUCCEEDED: Sent slack webhook", response.data); - // }) - // .catch((error) => { - // console.log("FAILED: Send slack webhook", error); - // }); - } else { - // update existing pr - console.log("pr exists"); - // axios - // .post( - // SLACK_WEBHOOK_URL, - // JSON.stringify(`PR from ${branch_name} to staging already exist`) - // ) - // .then((response) => { - // console.log("SUCCEEDED: Sent slack webhook", response.data); - // }) - // .catch((error) => { - // console.log("FAILED: Send slack webhook", error); - // }); + axios + .post(SLACK_WEBHOOK_URL, JSON.stringify(options)) + .then((response) => { + console.log("SUCCEEDED: Sent slack webhook", response.data); + }) + .catch((error) => { + console.log("FAILED: Send slack webhook", error); + }); + return; } } catch (error) { console.log("error", error?.message); @@ -120,6 +98,19 @@ const run = async () => { // update PR try { + const options = { + blocks: [ + { + type: "context", + elements: [ + { + type: "mrkdwn", + text: `<:sparkles: PR was updated from ${branch_name} to staging>`, + }, + ], + }, + ], + }; // fetching existing PR const existing_pr = await octokit.rest.pulls.list({ owner: context.payload?.repository?.owner?.login, @@ -128,18 +119,31 @@ const run = async () => { head: branch_name, base: "staging", }); - console.log("existing PR", existing_pr); - // update pr - const update_pr = await octokit.rest.pulls.update({ - pull_number: existing_pr?.data[0].number, - owner: context.payload?.repository?.owner?.login, - repo: context.payload?.repository?.name, - title: branch_name, - body: commits, - head: branch_name, - base: "staging", - }); - console.log(update_pr?.data); + + if (existing_pr?.data) { + // update pr + const update_pr = await octokit.rest.pulls.update({ + pull_number: existing_pr?.data[0].number, + owner: context.payload?.repository?.owner?.login, + repo: context.payload?.repository?.name, + title: branch_name, + body: commits, + head: branch_name, + base: "staging", + }); + } + if (update_pr.data) { + // send slack notification + axios + .post(SLACK_WEBHOOK_URL, JSON.stringify(options)) + .then((response) => { + console.log("SUCCEEDED: Sent slack webhook", response.data); + }) + .catch((error) => { + console.log("FAILED: Send slack webhook", error); + }); + return; + } } catch (error) { console.log("error", error?.message); } From 0010d22507ea4b5325f153a0fb3ea2ddc4a8a01a Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 23 Apr 2022 00:07:33 +0300 Subject: [PATCH 16/19] test update pr --- src/develop_actions.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index d6a1629..2621da1 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -131,18 +131,18 @@ const run = async () => { head: branch_name, base: "staging", }); - } - if (update_pr.data) { - // send slack notification - axios - .post(SLACK_WEBHOOK_URL, JSON.stringify(options)) - .then((response) => { - console.log("SUCCEEDED: Sent slack webhook", response.data); - }) - .catch((error) => { - console.log("FAILED: Send slack webhook", error); - }); - return; + if (update_pr.data) { + // send slack notification + axios + .post(SLACK_WEBHOOK_URL, JSON.stringify(options)) + .then((response) => { + console.log("SUCCEEDED: Sent slack webhook", response.data); + }) + .catch((error) => { + console.log("FAILED: Send slack webhook", error); + }); + return; + } } } catch (error) { console.log("error", error?.message); From aeb67ceba393f77e1e01b87d25e8bff9220b83d8 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 23 Apr 2022 00:12:47 +0300 Subject: [PATCH 17/19] finalize develop branch actions --- src/develop_actions.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index 2621da1..08567fb 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -59,12 +59,20 @@ const run = async () => { try { let options = { blocks: [ + { + type: "header", + text: { + type: "plain_text", + text: ":sparkles: New notification sent from github actions", + emoji: true, + }, + }, { type: "context", elements: [ { type: "mrkdwn", - text: `<:sparkles: PR was created from ${branch_name} to staging>`, + text: `> :sparkles: PR was created from ${branch_name} to staging`, }, ], }, @@ -100,12 +108,20 @@ const run = async () => { try { const options = { blocks: [ + { + type: "header", + text: { + type: "plain_text", + text: ":sparkles: New notification sent from github actions", + emoji: true, + }, + }, { type: "context", elements: [ { type: "mrkdwn", - text: `<:sparkles: PR was updated from ${branch_name} to staging>`, + text: `> :sparkles: PR was updated from ${branch_name} to staging`, }, ], }, @@ -150,6 +166,3 @@ const run = async () => { }; run(); - -// $GITHUB_REF would look like (refs/pull/33/merge), $GITHUB_HEAD_REF would just store the source branch name while $GITHUB_BASE_REF would represent RP destination branch. Maybe you can update your answer to fallback to $GITHUB_HEAD_REF -// ${GITHUB_REF##*/} From 812ff25bb2a9f5201497fc2010b3e45b6b82e724 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 23 Apr 2022 00:15:39 +0300 Subject: [PATCH 18/19] finalize develop branch actions --- .github/workflows/develop_actions.yml | 1 + action.yml | 3 +++ src/develop_actions.js | 19 ++++++++----------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/develop_actions.yml b/.github/workflows/develop_actions.yml index 6b361ec..6dd1eff 100644 --- a/.github/workflows/develop_actions.yml +++ b/.github/workflows/develop_actions.yml @@ -19,3 +19,4 @@ jobs: with: GITHUB_TOKEN: ${{secrets.TOKEN}} SLACK_WEBHOOK_URL: ${{secrets.SLACK_WEBHOOK_URL}} + DESTINATION_BRANCH: staging diff --git a/action.yml b/action.yml index f5270f6..f5917a0 100644 --- a/action.yml +++ b/action.yml @@ -9,6 +9,9 @@ inputs: SLACK_WEBHOOK_URL: description: 'Slack webhook' required: true + DESTINATION_BRANCH: + description: 'destination branch' + required: true runs: using: 'node16' main: './src/develop_actions.js' diff --git a/src/develop_actions.js b/src/develop_actions.js index 08567fb..abda7fb 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -4,6 +4,7 @@ const core = require("@actions/core"); const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN"); const SLACK_WEBHOOK_URL = core.getInput("SLACK_WEBHOOK_URL"); +const DESTINATION_BRANCH = core.getInput("DESTINATION_BRANCH"); const octokit = github.getOctokit(GITHUB_TOKEN); const { context = {} } = github; @@ -19,11 +20,11 @@ const run = async () => { let commits = ""; try { const compare_commits = await octokit.request( - `GET /repos/${context.payload?.repository?.full_name}/compare/staging...${branch_name}`, + `GET /repos/${context.payload?.repository?.full_name}/compare/${DESTINATION_BRANCH}...${branch_name}`, { owner: context.payload?.repository?.owner?.login, repo: context.payload?.repository?.name, - base: "staging", + base: DESTINATION_BRANCH, head: branch_name, } ); @@ -47,10 +48,6 @@ const run = async () => { ? "> " + e.commit.message : commits + "\n\n" + "> " + e.commit.message; }); - - // fetch pr from branch_name to staging to check if it exists - // if pr exists, update - // if not create } catch (error) { console.log(error?.message); } @@ -72,7 +69,7 @@ const run = async () => { elements: [ { type: "mrkdwn", - text: `> :sparkles: PR was created from ${branch_name} to staging`, + text: `> :sparkles: PR was created from ${branch_name} to ${DESTINATION_BRANCH}`, }, ], }, @@ -86,7 +83,7 @@ const run = async () => { title: branch_name, body: commits, head: branch_name, - base: "staging", + base: DESTINATION_BRANCH, } ); if (createpr?.data) { @@ -121,7 +118,7 @@ const run = async () => { elements: [ { type: "mrkdwn", - text: `> :sparkles: PR was updated from ${branch_name} to staging`, + text: `> :sparkles: PR was updated from ${branch_name} to ${DESTINATION_BRANCH}`, }, ], }, @@ -133,7 +130,7 @@ const run = async () => { repo: context.payload?.repository?.name, state: "open", head: branch_name, - base: "staging", + base: DESTINATION_BRANCH, }); if (existing_pr?.data) { @@ -145,7 +142,7 @@ const run = async () => { title: branch_name, body: commits, head: branch_name, - base: "staging", + base: DESTINATION_BRANCH, }); if (update_pr.data) { // send slack notification From 35a285bb0dff2493acea59bfb2d00d55f0115da9 Mon Sep 17 00:00:00 2001 From: Ben Date: Sat, 23 Apr 2022 00:18:46 +0300 Subject: [PATCH 19/19] finalize develop branch actions --- src/develop_actions.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/develop_actions.js b/src/develop_actions.js index abda7fb..1d1d03d 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -69,7 +69,7 @@ const run = async () => { elements: [ { type: "mrkdwn", - text: `> :sparkles: PR was created from ${branch_name} to ${DESTINATION_BRANCH}`, + text: `> Pull request was created from ${branch_name} to ${DESTINATION_BRANCH}`, }, ], }, @@ -118,7 +118,7 @@ const run = async () => { elements: [ { type: "mrkdwn", - text: `> :sparkles: PR was updated from ${branch_name} to ${DESTINATION_BRANCH}`, + text: `> Pull request was updated from ${branch_name} to ${DESTINATION_BRANCH}`, }, ], },