-
Notifications
You must be signed in to change notification settings - Fork 80
123 lines (114 loc) · 4.53 KB
/
issue-responder.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Issue Responder
on:
workflow_dispatch:
inputs:
ticket_number:
description: 'Ticket Number'
required: true
type: integer
ticket_type:
description: 'Ticket Type'
required: true
type: choice
options:
- issues
- discussions
default: issues
avoidUpdate:
description: 'Do not update Resource center'
required: false
type: boolean
default: false
updateDocsOnly:
description: 'Do not add comments to the ticket'
required: false
type: boolean
default: false
issues:
types: [opened]
issue_comment:
types: [created]
discussion:
types: [created]
discussion_comment:
types: [created]
permissions:
issues: write
discussions: write
statuses: write
jobs:
run-script:
runs-on: ubuntu-latest
steps:
- name: Check if comment is from bot user
run: |
if [[ "${{ github.actor }}" == "github-actions[bot]" ]] && [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then
echo "Comment was made by the GitHub Actions bot. Exiting without running the script."
exit 0
fi
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Download script
run: |
curl -o github.mjs https://bot.jiraassistant.com/actions/github/github.mjs
- name: Identify Action
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "TICKET_TYPE=${{ github.event.inputs.ticket_type }}" >> $GITHUB_ENV
echo "TICKET_NUMBER=${{ github.event.inputs.ticket_number }}" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "discussion_comment" ]] || [[ "${{ github.event_name }}" == "discussion" ]]; then
echo "TICKET_TYPE=discussions" >> $GITHUB_ENV
echo "TICKET_NUMBER=${{ github.event.discussion.number }}" >> $GITHUB_ENV
else
echo "TICKET_TYPE=issues" >> $GITHUB_ENV
echo "TICKET_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV
fi
- name: Retrieve collaborators
id: get-collaborators
run: |
if [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then
collaborators=$(curl -s -H "Authorization: token ${{ github.token }}" \
"https://api.github.com/repos/${{ github.repository }}/collaborators" | \
jq -r '.[].login')
echo "${collaborators}" > collaborators.txt
fi
- name: Check if comment is from collaborator
run: |
if [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then
COMMENT_USER="${{ github.actor }}"
if grep -q "$COMMENT_USER" collaborators.txt; then
echo "Comment was made by a collaborator."
echo "avoidComments=true" >> $GITHUB_ENV
node github.mjs --ticket "$TICKET_NUMBER" \
--ticketType "$TICKET_TYPE" \
--repo "${{ github.repository }}" \
--orgId "${{ vars.RESPONDER_ORG_ID }}" \
--botId "${{ vars.RESPONDER_BOT_ID }}" \
--ghToken "${{ github.token }}" \
--authToken "${{ secrets.RESPONDER_TOKEN }}" \
--updateOnly
exit 0
fi
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]] && [[ "${{ github.event.inputs.updateDocsOnly }}" == "true" ]]; then
echo "avoidComments=true" >> $GITHUB_ENV
node github.mjs --ticket "$TICKET_NUMBER" \
--ticketType "$TICKET_TYPE" \
--repo "${{ github.repository }}" \
--orgId "${{ vars.RESPONDER_ORG_ID }}" \
--botId "${{ vars.RESPONDER_BOT_ID }}" \
--ghToken "${{ github.token }}" \
--authToken "${{ secrets.RESPONDER_TOKEN }}" \
--updateOnly
fi
- name: Add comment to ticket
if: env.avoidComments != 'true'
run: |
node github.mjs --testMode "${{ github.event.inputs.avoidUpdate }}" --ticket "$TICKET_NUMBER" \
--ticketType "$TICKET_TYPE" \
--repo "${{ github.repository }}" \
--orgId "${{ vars.RESPONDER_ORG_ID }}" \
--botId "${{ vars.RESPONDER_BOT_ID }}" \
--ghToken "${{ github.token }}" \
--authToken "${{ secrets.RESPONDER_TOKEN }}"