-
Notifications
You must be signed in to change notification settings - Fork 4
114 lines (106 loc) · 5.44 KB
/
handle-pr-comment.yml
File metadata and controls
114 lines (106 loc) · 5.44 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Handle a PR comment
run-name: Handle slash command in a PR comment`
on:
# GitGitGadget's GitHub App is expected to trigger this on `issue_comment` events
# that have the `action` set to `created` or `edited`
workflow_dispatch:
inputs:
pr-comment-url:
description: 'URL of the PR comment to handle'
required: true
env:
PR_COMMENT_URL: ${{ inputs.pr-comment-url }}
concurrency:
group: ${{ github.workflow }}-${{ inputs.pr-comment-url }}
jobs:
handle-pr-comment:
runs-on: ubuntu-latest
if: vars.CONFIG != ''
steps:
- uses: actions/create-github-app-token@v1
id: pr-repo-token
with:
app-id: ${{ secrets.GITGITGADGET_GITHUB_APP_ID }}
private-key: ${{ secrets.GITGITGADGET_GITHUB_APP_PRIVATE_KEY }}
owner: ${{ fromJSON(vars.CONFIG).repo.owner }}
repositories: ${{ fromJSON(vars.CONFIG).repo.name }}
- uses: actions/create-github-app-token@v1
if: ${{ contains(fromJSON(vars.CONFIG).repo.owners, fromJSON(vars.CONFIG).repo.baseOwner) }}
id: upstream-repo-token
with:
app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }}
private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }}
owner: ${{ fromJSON(vars.CONFIG).repo.baseOwner }}
repositories: ${{ fromJSON(vars.CONFIG).repo.name }}
- uses: actions/create-github-app-token@v1
if: ${{ contains(fromJSON(vars.CONFIG).repo.owners, fromJSON(vars.CONFIG).repo.testOwner) }}
id: test-repo-token
with:
app-id: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_ID }}
private-key: ${{ secrets.GITGITGADGET_GIT_GITHUB_APP_PRIVATE_KEY }}
owner: ${{ fromJSON(vars.CONFIG).repo.testOwner }}
repositories: ${{ fromJSON(vars.CONFIG).repo.name }}
- name: create a check run
id: create-check-run
run: |
set -x
title="Handle PR comment"
summary="Handling PR comment $PR_COMMENT_URL"
details_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
text="This handles $PR_COMMENT_URL, see $details_url for details."
echo "title=$title" >> $GITHUB_OUTPUT
echo "summary=$summary" >> $GITHUB_OUTPUT
echo "text=$text" >> $GITHUB_OUTPUT
PR_NUMBER="${PR_COMMENT_URL%#*}" # skip the suffix with the comment ID
PR_NUMBER="${PR_NUMBER##*/}" # skip the prefix before the PR number
PR_REPO="${PR_COMMENT_URL%/pull/$PR_NUMBER*#*}" # skip the suffix including the PR number
PR_REPO="${PR_REPO#https://*/}"
export GH_TOKEN="${{ secrets.GITHUB_TOKEN }}"
eval "$(gh api repos/$PR_REPO/pulls/$PR_NUMBER \
--jq '"head_sha=\(.head.sha) && repo=\(.base.repo.full_name)"')"
echo "head_sha=$head_sha" >> $GITHUB_OUTPUT
echo "repo=$repo" >> $GITHUB_OUTPUT
export GH_TOKEN="$(case "$repo" in
'${{ fromJSON(vars.CONFIG).repo.owner }}/${{ fromJSON(vars.CONFIG).repo.name }}') echo "${{ steps.pr-repo-token.outputs.token }}";;
'${{ fromJSON(vars.CONFIG).repo.baseOwner }}/${{ fromJSON(vars.CONFIG).repo.name }}') echo "${{ steps.upstream-repo-token.outputs.token }}";;
'${{ fromJSON(vars.CONFIG).repo.testOwner }}/${{ fromJSON(vars.CONFIG).repo.name }}') echo "${{ steps.test-repo-token.outputs.token }}";;
*) echo "${{ secrets.GITHUB_TOKEN }}";;
esac
)"
eval "$(gh api repos/$repo/check-runs -X POST \
-f name='handle_pr_comment' \
-f head_sha="$head_sha" \
-f status='in_progress' \
-f details_url="$details_url" \
-f "output[title]=$title" \
-f "output[summary]=$summary" \
-f "output[text]=$text" \
--jq '"check_run_id=\(.id)"')"
echo "check_run_id=$check_run_id" >> $GITHUB_OUTPUT
- uses: gitgitgadget/gitgitgadget/handle-pr-comment@v1
with:
config: ${{ vars.CONFIG }}
pr-repo-token: ${{ steps.pr-repo-token.outputs.token }}
upstream-repo-token: ${{ steps.upstream-repo-token.outputs.token }}
test-repo-token: ${{ steps.test-repo-token.outputs.token }}
smtp-host: '${{ fromJSON(vars.CONFIG).mail.smtpHost }}'
smtp-user: '${{ fromJSON(vars.CONFIG).mail.smtpUser }}'
smtp-pass: "${{ secrets.GITGITGADGET_SMTP_PASS }}"
pr-comment-url: ${{ env.PR_COMMENT_URL }}
- name: update the check run
if: always() && steps.create-check-run.outputs.check_run_id != ''
run: |
export GH_TOKEN="$(case "${{ steps.create-check-run.outputs.repo }}" in
'${{ fromJSON(vars.CONFIG).repo.owner }}/${{ fromJSON(vars.CONFIG).repo.name }}') echo "${{ steps.pr-repo-token.outputs.token }}";;
'${{ fromJSON(vars.CONFIG).repo.baseOwner }}/${{ fromJSON(vars.CONFIG).repo.name }}') echo "${{ steps.upstream-repo-token.outputs.token }}";;
'${{ fromJSON(vars.CONFIG).repo.testOwner }}/${{ fromJSON(vars.CONFIG).repo.name }}') echo "${{ steps.test-repo-token.outputs.token }}";;
*) echo "${{ secrets.GITHUB_TOKEN }}";;
esac
)"
gh api repos/${{ steps.create-check-run.outputs.repo }}/check-runs/${{ steps.create-check-run.outputs.check_run_id }} \
-X PATCH \
-f status='completed' \
-f conclusion='${{ job.status }}' \
-f 'output[title]=${{ steps.create-check-run.outputs.title }}' \
-f 'output[summary]=${{ steps.create-check-run.outputs.summary }}' \
-f 'output[text]=${{ steps.create-check-run.outputs.text }}'