-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
115 lines (107 loc) · 4.24 KB
/
action.yml
File metadata and controls
115 lines (107 loc) · 4.24 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: 'Pull Request Commenter'
author: 'Ørjan Skårnes'
description: 'Create or update a comment on a pull request'
branding:
icon: 'git-pull-request'
color: 'yellow'
inputs:
comment-body:
description: 'Content for comment body'
required: true
comment-search-includes:
description: 'The text to search for in existing comments'
required: true
comment-title:
description: 'Title for the comment'
required: true
comment-edit-mode:
description: 'Edit mode for the comment (append or replace)'
default: 'replace'
comment-reactions:
description: 'Reactions to add to the comment'
required: false
comment-pre-tag:
description: 'Whether to wrap the comment body in a <pre> tag'
default: 'true'
remove-comment-if-no-output:
description: 'Whether to remove the comment if there is no body'
default: 'true'
fail-on-output:
description: 'Whether to fail the workflow if there is no body'
default: 'false'
gif_search_term:
description: 'Search term for Giphy API'
required: false
giphy_api_key:
description: 'Giphy API key'
required: false
github_token:
description: 'GitHub token'
required: true
runs:
using: composite
steps:
# Add this before the 'Fetch random missing gif from Giphy' step
- name: Checkout pull-request-commenter repository
if: inputs.comment-body && inputs.gif_search_term && inputs.giphy_api_key
uses: actions/checkout@v3
with:
repository: OrjanSkarnes/pull-request-commenter
- name: Fetch random missing gif from Giphy
if: inputs.comment-body && inputs.gif_search_term && inputs.giphy_api_key
id: missing_gif
env:
SEARCH_TERM: ${{ inputs.gif_search_term }}
GIPHY_API_KEY: ${{ inputs.giphy_api_key }}
shell: bash
run: |
gif_url=$(bash script/get_gif_url.sh "$SEARCH_TERM" "$GIPHY_API_KEY")
echo "GIF_URL=$gif_url" >> $GITHUB_ENV
- name: Find Comment with specified message
uses: peter-evans/find-comment@v2
id: find_comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: ${{ inputs.comment-search-includes }}
- name: Create or update comment with the output (without gif)
if: inputs.comment-body && !env.GIF_URL
uses: peter-evans/create-or-update-comment@v3.0.0
with:
token: ${{ inputs.github_token }}
issue-number: ${{ github.event.number }}
comment-id: ${{ steps.find_comment.outputs.comment-id }}
body: |
${{ inputs.comment-title }}<br />
${{ inputs.comment-pre-tag == 'true' && '<pre>' || '' }}${{ inputs.comment-body }}${{ inputs.comment-pre-tag == 'true' && '</pre>' || '' }}<br />
edit-mode: ${{ inputs.comment-edit-mode }}
reactions: ${{ inputs.comment-reactions }}
- name: Create or update comment with the output (with gif)
if: inputs.comment-body && env.GIF_URL
uses: peter-evans/create-or-update-comment@v3.0.0
with:
token: ${{ inputs.github_token }}
issue-number: ${{ github.event.number }}
comment-id: ${{ steps.find_comment.outputs.comment-id }}
body: |
${{ inputs.comment-title }}<br />
${{ inputs.comment-pre-tag == 'true' && '<pre>' || '' }}${{ inputs.comment-body }}${{ inputs.comment-pre-tag == 'true' && '</pre>' || '' }}<br />

edit-mode: ${{ inputs.comment-edit-mode }}
reactions: ${{ inputs.comment-reactions }}
- name: Remove comment if body is empty
if: inputs.comment-body == '' && inputs.remove-comment-if-no-output == 'true'
env:
GH_TOKEN: ${{ inputs.github_token }}
shell: bash
run: |
comment_id=${{ steps.find_comment.outputs.comment-id }}
if [ -n "$comment_id" ]; then
gh api --silent -X DELETE "repos/${{ github.repository }}/issues/comments/$comment_id"
fi
- name: Fail workflow if output is found and fail-on-output is true
if: inputs.comment-body != '' && inputs.fail-on-output == 'true'
shell: bash
run: |
echo "::error::Input 'comment-body' is not empty. This is not allowed when 'fail-on-output' is true. Workflow failed."
exit 1