From 16b5671d3b5b6574a196eb2fdb739554bafe3f6a Mon Sep 17 00:00:00 2001 From: branberry Date: Thu, 31 Aug 2023 15:23:03 -0500 Subject: [PATCH] [FEATURE]: Add try catch and conditional for commenting --- .github/scripts/webhook-pr-comment.js | 18 ++++++++++++------ .github/workflows/deploy-feature-branch.yml | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/scripts/webhook-pr-comment.js b/.github/scripts/webhook-pr-comment.js index 09e96f00d..b53dbbe27 100644 --- a/.github/scripts/webhook-pr-comment.js +++ b/.github/scripts/webhook-pr-comment.js @@ -1,10 +1,16 @@ const fs = require('fs'); module.exports = ({ github }) => { - const outputsFile = fs.readFileSync('cdk-infra/outputs.json').toString(); - const outputs = JSON.parse(outputsFile); - console.log(github.head_ref); - console.log(outputsFile); - const webhook = Object.values(outputs[`auto-builder-stack-enhancedApp-stg-${github.head_ref}-webhooks`])[0]; - return webhook; + try { + const outputsFile = fs.readFileSync('cdk-infra/outputs.json').toString(); + const outputs = JSON.parse(outputsFile); + console.log('github', github); + console.log(github.head_ref); + console.log(outputsFile); + const webhook = Object.values(outputs[`auto-builder-stack-enhancedApp-stg-${github.head_ref}-webhooks`])[0]; + return webhook; + } catch (error) { + console.log('Error occurred when retrieving Webhook URL'); + return ''; + } }; diff --git a/.github/workflows/deploy-feature-branch.yml b/.github/workflows/deploy-feature-branch.yml index 232d51c0e..e9ecbe1c7 100644 --- a/.github/workflows/deploy-feature-branch.yml +++ b/.github/workflows/deploy-feature-branch.yml @@ -36,6 +36,7 @@ jobs: return script({context, github}) result-encoding: string - name: Comment on PR + if: steps.webhook.outputs.result != '' run: gh pr comment ${{github.event.number}} --body "The URL for your feature branch webhook is ${{steps.webhook.outputs.result}}" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file