From c86714307c1605dc96d5a157ca309f110d9d5d66 Mon Sep 17 00:00:00 2001 From: sivasadobe Date: Tue, 2 Jul 2024 20:52:26 +0530 Subject: [PATCH 1/5] fix --- .github/workflows/merged-to-main.yaml | 2 +- .github/workflows/src/send-slack.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/merged-to-main.yaml b/.github/workflows/merged-to-main.yaml index 7c8a6ff..af9327e 100644 --- a/.github/workflows/merged-to-main.yaml +++ b/.github/workflows/merged-to-main.yaml @@ -65,4 +65,4 @@ jobs: with: script: | const {sendReleaseNotes} = require('./.github/workflows/src/send-slack.js') - sendReleaseNotes(process.env.PR_NUMBER,process.env.CC_RELEASE_SLACK_WH) + sendReleaseNotes(process.env.PR_NUMBER, process.env.CC_RELEASE_SLACK_WH) diff --git a/.github/workflows/src/send-slack.js b/.github/workflows/src/send-slack.js index c9a95ee..c81b0b5 100644 --- a/.github/workflows/src/send-slack.js +++ b/.github/workflows/src/send-slack.js @@ -11,7 +11,8 @@ const auth = process.env.GH_TOKEN; * @returns {Promise} - Promise representing the result of the Slack message sending process */ const sendReleaseNotes = async (prNumber, slackWebHookURL) => { - console.log({ owner, repo, pr_number: prNumber }); + + console.log({ owner, repo, pr_number: prNumber, slackWebHookURL}); try { prNumber = parseInt(prNumber); const { Octokit } = await import("@octokit/rest"); From c988533f4c58768c8b41566783dc5c4b51ca6c5b Mon Sep 17 00:00:00 2001 From: sivasadobe Date: Tue, 2 Jul 2024 20:57:22 +0530 Subject: [PATCH 2/5] fix --- .github/workflows/merged-to-main.yaml | 6 ++++++ .github/workflows/src/send-slack.js | 1 + 2 files changed, 7 insertions(+) diff --git a/.github/workflows/merged-to-main.yaml b/.github/workflows/merged-to-main.yaml index af9327e..31e1be5 100644 --- a/.github/workflows/merged-to-main.yaml +++ b/.github/workflows/merged-to-main.yaml @@ -56,6 +56,12 @@ jobs: - name: Install Octakit run: | npm i -D @octokit/rest + - name: Set up secret file + env: + CC_RELEASE_SLACK_WH: ${{ secrets.CC_RELEASE_SLACK_WH }} + run: | + echo ${{secrets.CC_RELEASE_SLACK_WH}} + # Sending release notes to cc-changelog channel - name: Sending Release Notes to cc-changelog slack channel uses: actions/github-script@v7 diff --git a/.github/workflows/src/send-slack.js b/.github/workflows/src/send-slack.js index c81b0b5..7944e3f 100644 --- a/.github/workflows/src/send-slack.js +++ b/.github/workflows/src/send-slack.js @@ -60,6 +60,7 @@ const sendReleaseNotes = async (prNumber, slackWebHookURL) => { else { console.log(`Slack Message not sent ${result.status}:${result.statusText}`) } + console.log(result) return result; } catch (e) { console.log(e); From a63f79e98b48f483ba3dc31dc17b5f74ad115f72 Mon Sep 17 00:00:00 2001 From: sivasadobe Date: Tue, 2 Jul 2024 21:02:29 +0530 Subject: [PATCH 3/5] fix --- .github/workflows/src/send-slack.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/src/send-slack.js b/.github/workflows/src/send-slack.js index 7944e3f..8615c84 100644 --- a/.github/workflows/src/send-slack.js +++ b/.github/workflows/src/send-slack.js @@ -43,24 +43,25 @@ const sendReleaseNotes = async (prNumber, slackWebHookURL) => { }, ]; - const slackBodyBlocks = { + const slackBodyBlocks = JSON.stringify({ blocks: [...titleBlocks, ...formattedBodyBlocks], - }; + }); console.log("Message", slackBodyBlocks); // Send message to Slack webhook const result = await fetch(slackWebHookURL, { method: "POST", - body: JSON.stringify(slackBodyBlocks), + body: slackBodyBlocks, headers: { "Content-type": "application/json", }, }).catch(console.error); + if (result.status === 200) console.log("Slack Message sent"); else { console.log(`Slack Message not sent ${result.status}:${result.statusText}`) } - console.log(result) + console.log(result); return result; } catch (e) { console.log(e); From f49c47940bc44b7a72dd4a9b89d8bf30260fc242 Mon Sep 17 00:00:00 2001 From: sivasadobe Date: Tue, 2 Jul 2024 21:16:34 +0530 Subject: [PATCH 4/5] fix --- .github/workflows/src/send-slack.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/src/send-slack.js b/.github/workflows/src/send-slack.js index 8615c84..7e796a6 100644 --- a/.github/workflows/src/send-slack.js +++ b/.github/workflows/src/send-slack.js @@ -2,7 +2,7 @@ const { parseTextToSlackBlocks } = require("./helpers"); // Those env variables are set by an github action automatically const [owner, repo]=process.env.GITHUB_REPOSITORY?.split('/') || ''; -const auth = process.env.GH_TOKEN; +const auth = process.env.GITHUB_TOKEN; /** * Function to send Slack message From 0903c6afdc4661016378ebac47eeb86884a7ebb9 Mon Sep 17 00:00:00 2001 From: sivasadobe Date: Thu, 4 Jul 2024 12:53:51 +0530 Subject: [PATCH 5/5] fix --- .github/workflows/merged-to-main.yaml | 74 ++++++++++----------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/.github/workflows/merged-to-main.yaml b/.github/workflows/merged-to-main.yaml index 31e1be5..c4afa89 100644 --- a/.github/workflows/merged-to-main.yaml +++ b/.github/workflows/merged-to-main.yaml @@ -1,74 +1,54 @@ name: Merged to Main on: - # Triggered when a pull request is closed and merged into the main branch + # Trigger this workflow when a pull request is closed and merged into the main branch pull_request: branches: - main types: - closed - # Manually triggered workflow with inputs for title and body + # Allow manual triggering of the workflow with a PR number input workflow_dispatch: inputs: pr_number: - description: "PR Number" + description: "PR Number to use (optional for manual triggers)" default: "200" required: true env: - # Slack webhook secret + # Slack webhook secret for sending release notes CC_RELEASE_SLACK_WH: ${{ secrets.CC_RELEASE_SLACK_WH }} - jobs: - # Job to handle merged pull requests - merged_to_main: + send_release_notes: runs-on: ubuntu-latest environment: cc_pr_merge - # Run the job when a pull request is merged into main and not triggered manually && github.event.pull_request.merged - if: ${{ github.event_name != 'workflow_dispatch' }} - env: - # Environment variable to store pull request details - PR_NUMBER: ${{ github.event.pull_request.number }} + + # This condition ensures the job runs only when a pull request is merged or the workflow is manually triggered + if: ${{ (github.event_name != 'workflow_dispatch' && github.event.pull_request.merged) || github.event_name == 'workflow_dispatch' }} + steps: - # Checkout repository action + # Step to check out the repository - name: Checkout repository uses: actions/checkout@v4 - - name: Install Octakit - run: | - npm i -D @octokit/rest - # Sending release notes to cc-changelog channel - - name: Sending Release Notes to cc-changelog slack channel - uses: actions/github-script@v7 - with: - script: | - const {sendReleaseNotes} = require('./.github/workflows/src/send-slack.js') - sendReleaseNotes(process.env.PR_NUMBER,process.env.CC_RELEASE_SLACK_WH) - # Job to handle manually triggered workflow_dispatch events - workflow_dispatch_event: - runs-on: ubuntu-latest - environment: cc_pr_merge - # Run the job when the workflow is manually triggered - if: ${{ github.event_name == 'workflow_dispatch' }} - steps: - # Checkout repository action - - name: Check repository - uses: actions/checkout@v4 - - name: Install Octakit - run: | - npm i -D @octokit/rest - - name: Set up secret file - env: - CC_RELEASE_SLACK_WH: ${{ secrets.CC_RELEASE_SLACK_WH }} - run: | - echo ${{secrets.CC_RELEASE_SLACK_WH}} - - # Sending release notes to cc-changelog channel + + # Step to install Octokit + - name: Install Octokit + run: npm i -D @octokit/rest + + # Step to set PR_NUMBER environment variable from the pull request event + - name: Set PR Number + if: ${{ github.event_name != 'workflow_dispatch' }} + run: echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV + + # Step to set PR_NUMBER environment variable from the workflow dispatch input + - name: Set PR Number from Input + if: ${{ github.event_name == 'workflow_dispatch' }} + run: echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_ENV + + # Step to send release notes to the cc-changelog Slack channel - name: Sending Release Notes to cc-changelog slack channel uses: actions/github-script@v7 - # Set environment variables for repository URL, PR number,PR title, and PR description - env: - PR_NUMBER: ${{github.event.inputs.pr_number}} with: script: | - const {sendReleaseNotes} = require('./.github/workflows/src/send-slack.js') + const { sendReleaseNotes } = require('./.github/workflows/src/send-slack.js') sendReleaseNotes(process.env.PR_NUMBER, process.env.CC_RELEASE_SLACK_WH)