diff --git a/.github/workflows/develop_actions.yml b/.github/workflows/develop_actions.yml index f6e8c1e..6b361ec 100644 --- a/.github/workflows/develop_actions.yml +++ b/.github/workflows/develop_actions.yml @@ -18,3 +18,4 @@ jobs: - uses: ./ with: GITHUB_TOKEN: ${{secrets.TOKEN}} + SLACK_WEBHOOK_URL: ${{secrets.SLACK_WEBHOOK_URL}} diff --git a/src/develop_actions.js b/src/develop_actions.js index be3086a..bf7644e 100644 --- a/src/develop_actions.js +++ b/src/develop_actions.js @@ -4,6 +4,7 @@ const core = require("@actions/core"); // const response = require("../res"); const GITHUB_TOKEN = core.getInput("GITHUB_TOKEN"); +const SLACK_WEBHOOK_URL = core.getInput("SLACK_WEBHOOK_URL"); const octokit = github.getOctokit(GITHUB_TOKEN); const { context = {} } = github; @@ -16,13 +17,6 @@ const run = async () => { .slice(1) .join("/"); - // context - console.log(context.payload); - console.log("branch name", branch_name); - console.log("full name", context.payload?.full_name); - console.log("owner", context.payload?.owner?.login); - console.log("repo", context.payload?.repository?.name); - let commits = ""; context.payload?.commits?.forEach((e, i) => { @@ -36,12 +30,10 @@ const run = async () => { i === 0 ? "> " + e.message : commits + "\n\n" + "> " + e.message; }); - console.log(commits); - const createpr = await octokit.request( - `POST /repos/${context.payload?.full_name}/pulls`, + `POST /repos/${context.payload?.repository?.full_name}/pulls`, { - owner: context.payload?.owner?.login, + owner: context.payload?.repository?.owner?.login, repo: context.payload?.repository?.name, title: branch_name, body: commits, @@ -50,6 +42,21 @@ const run = async () => { } ); console.log("createPr", createpr?.data); + if (createpr?.data) { + axios + .post( + `${SLACK_WEBHOOK_URL}`, + `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")); + }); + } } catch (error) { console.log("error", error?.message); }