Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 3d7fa56

Browse files
authored
[FEATURE]: Comment on PRs with webhook URL for feature branch (#903)
* [FEATURE]: Add commenting to PR * [FEATURE]: use correct cdk file path * [FEATURE]: ADd token * [FEATURE]: Log stuff for debugging :S * [FEATURE]: Add try catch and conditional for commenting * [FEATURE]: Get cwd * [FEATURE]: Add env for branch name * [FEATURE]: Use path.join * [FEATURE]: Remove bad log, i hate plain js
1 parent 7d20361 commit 3d7fa56

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
module.exports = () => {
4+
try {
5+
const outputsFile = fs.readFileSync('cdk-infra/outputs.json').toString();
6+
const outputs = JSON.parse(outputsFile);
7+
8+
const webhook = Object.values(outputs[`auto-builder-stack-enhancedApp-stg-${process.env.GIT_BRANCH}-webhooks`])[0];
9+
return webhook;
10+
} catch (error) {
11+
console.log('Error occurred when retrieving Webhook URL', error);
12+
return '';
13+
}
14+
};

.github/workflows/deploy-feature-branch.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ on:
55
types:
66
- opened
77
- reopened
8-
98
name: Initial Feature Branch Deploy
109
jobs:
1110
deploy:
11+
permissions: write-all
1212
runs-on: ubuntu-latest
13-
1413
steps:
1514
- uses: actions/checkout@v2
1615
- uses: actions/setup-node@v1
@@ -28,5 +27,18 @@ jobs:
2827
cd cdk-infra/
2928
npm ci
3029
npm run deploy:feature -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} --outputs-file outputs.json
31-
- name: Display resource URLs
32-
run: cat cdk-infra/outputs.json
30+
- name: Get Webhook URL
31+
uses: actions/github-script@v6
32+
id: webhook
33+
env:
34+
GIT_BRANCH: ${{github.head_ref}}
35+
with:
36+
script: |
37+
const script = require('./.github/scripts/webhook-pr-comment.js');
38+
return script()
39+
result-encoding: string
40+
- name: Comment on PR
41+
if: steps.webhook.outputs.result != ''
42+
run: gh pr comment ${{github.event.number}} --body "The URL for your feature branch webhook is ${{steps.webhook.outputs.result}}"
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)