-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
104 lines (98 loc) · 3.82 KB
/
action.yml
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
name: 'Issue Comment (Handlebars)'
description: 'Comment on a GitHub issue using a Handlebars template'
author: 'Richard Willis <willis.rh@gmail.com>'
branding:
icon: 'upload-cloud'
color: 'gray-dark'
inputs:
action:
required: true
description: 'Action, one of "update", "create", "delete", or "create-clean". The "create-clean" action will first delete the existing comment, then create a new comment'
template:
required: false
default: ''
description: 'The path to the handlebars template file, if not using the body options (optional). For example: ./.github/pr-comment-template.hbs'
body:
required: false
default: ''
description: 'The comment body, if not using the template option (optional). For example: "a message"'
template-inputs:
required: false
default: ''
description: 'A JSON object of key value pairs (required only if using the template option). For example: {"key":"value"}'
id:
required: true
description: 'The unique id to track the comment. For example: deploy'
issue-number:
required: true
description: 'The GitHub issue number. For example: 1'
token:
required: true
description: 'GITHUB_TOKEN (issues: write, pull-requests: write) or a repo scoped PAT'
runs:
using: 'composite'
steps:
- name: Generate Template Comment Id
uses: actions/github-script@v6
id: template-comment-id
with:
script: |
core.setOutput(
'template-comment-id',
`(ID: ${{ inputs.id }}-${{ inputs.issue-number }})`
);
- uses: badsyntax/github-action-render-template@v1.0.1
name: Render Comment Template
if: inputs.action != 'delete' && inputs.template != ''
id: render-template
with:
template: ${{ inputs.template }}
inputs: |
{
"inputs": ${{ inputs.template-inputs }},
"id": "${{ steps.template-comment-id.outputs.template-comment-id }}"
}
- uses: actions/github-script@v6
name: Render Comment Body
if: inputs.action != 'delete' && inputs.body != ''
id: render-body
with:
script: |
core.setOutput(
'body',
'${{inputs.body}}\n\n`${{ steps.template-comment-id.outputs.template-comment-id }}`'
);
- name: Find PR Comment
uses: peter-evans/find-comment@v2
if: inputs.action != 'create'
id: find-comment
with:
issue-number: ${{ inputs.issue-number }}
body-includes: ${{ steps.template-comment-id.outputs.template-comment-id }}
token: ${{ inputs.token }}
- name: Delete Comment
uses: actions/github-script@v6
if: (inputs.action == 'delete' || inputs.action == 'create-clean') && steps.find-comment.outputs.comment-id != ''
with:
script: |
await github.rest.issues.deleteComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.find-comment.outputs.comment-id }},
});
- name: Update Comment
if: inputs.action == 'update' && steps.find-comment.outputs.comment-id != ''
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ inputs.token }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
body: ${{ steps.render-template.outputs.result || steps.render-body.outputs.body }}
edit-mode: 'replace'
- name: Create Comment
if: inputs.action == 'create' || inputs.action == 'create-clean' || (inputs.action == 'update' && steps.find-comment.outputs.comment-id == '')
uses: peter-evans/create-or-update-comment@v2
with:
token: ${{ inputs.token }}
issue-number: ${{ inputs.issue-number }}
body: ${{ steps.render-template.outputs.result || steps.render-body.outputs.body }}