-
Notifications
You must be signed in to change notification settings - Fork 12
84 lines (73 loc) · 2.91 KB
/
review-app-comment.yml
File metadata and controls
84 lines (73 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
name: Comment Review App URL
on:
pull_request:
types: [opened, synchronize]
permissions:
pull-requests: write
issues: write
jobs:
comment:
runs-on: ubuntu-latest
steps:
- name: Wait for Heroku deployment
run: sleep 60
- name: Get Review App URL from Heroku
id: heroku
env:
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
run: |
if [ -z "$HEROKU_API_KEY" ]; then
echo "url=https://dashboard.heroku.com/pipelines/kernelboard" >> $GITHUB_OUTPUT
echo "status=pending" >> $GITHUB_OUTPUT
else
REVIEW_APPS=$(curl -s -n https://api.heroku.com/pipelines/kernelboard/review-apps \
-H "Authorization: Bearer $HEROKU_API_KEY" \
-H "Accept: application/vnd.heroku+json; version=3")
PR_NUMBER=${{ github.event.pull_request.number }}
APP_URL=$(echo "$REVIEW_APPS" | jq -r ".[] | select(.pr_number == $PR_NUMBER) | .app.web_url // empty")
if [ -n "$APP_URL" ]; then
echo "url=$APP_URL" >> $GITHUB_OUTPUT
echo "status=ready" >> $GITHUB_OUTPUT
else
echo "url=https://dashboard.heroku.com/pipelines/kernelboard" >> $GITHUB_OUTPUT
echo "status=building" >> $GITHUB_OUTPUT
fi
fi
- name: Comment PR with Review App URL
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const url = '${{ steps.heroku.outputs.url }}';
const status = '${{ steps.heroku.outputs.status }}';
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
const botComment = comments.data.find(c =>
c.body.includes('Review App Preview')
);
let body;
if (status === 'ready') {
body = `## 🔍 Review App Preview\n\n✅ Your preview is ready:\n**${url}**`;
} else if (status === 'building') {
body = `## 🔍 Review App Preview\n\n⏳ Building... Check status at:\n${url}`;
} else {
body = `## 🔍 Review App Preview\n\n⚠️ Add \`HEROKU_API_KEY\` secret to get direct preview links.\n\nCheck the pipeline: ${url}`;
}
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});
}