Repository navigation
Expand file tree
/
Copy pathaction.yaml
More file actions
59 lines (56 loc) · 2.32 KB
/
Copy pathaction.yaml
File metadata and controls
59 lines (56 loc) · 2.32 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
name: "Complete PR Comment"
description: >-
Removes the 'eyes' reaction and adds a completion reaction ('rocket' for success, 'confused' for 'failure',
'cancelled', or 'skipped') to the triggering comment. Requires `issues: write` permission in the calling workflow to
update comment reactions via the GitHub Reactions API.
inputs:
status:
description:
"The status of the workflow. If 'success', a 'rocket' reaction is added. For any non-success status (including
'failure', 'cancelled', or 'skipped'), a 'confused' reaction is added. Defaults to 'success'."
required: false
default: "success"
runs:
using: "composite"
steps:
- name: Update PR Comment Reactions
if: github.event_name == 'issue_comment'
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
env:
INPUT_STATUS: ${{ inputs.status }}
with:
script: |
const status = process.env.INPUT_STATUS;
const completionReaction = (status === 'success') ? 'rocket' : 'confused';
// 1. Remove "eyes" reaction
try {
const { data: reactions } = await github.rest.reactions.listForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id
});
const eyesReaction = reactions.find(
(r) => r.content === 'eyes' && r.user && r.user.login === 'github-actions[bot]'
);
if (eyesReaction) {
await github.rest.reactions.deleteForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
reaction_id: eyesReaction.id
});
}
} catch (e) {
core.warning(`Failed to remove "eyes" reaction: ${e.message}`);
}
// 2. Add completion reaction
try {
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: completionReaction
});
} catch (e) {
core.warning(`Failed to add "${completionReaction}" reaction: ${e.message}`);
}