-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
263 lines (240 loc) · 10.9 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: 'Send Code of Conduct'
description: 'Checks for CODE_OF_CONDUCT.md and processes it'
inputs:
GITHUB_TOKEN:
description: 'GitHub Token'
required: true
SERVER:
description: 'Server URL to send the code of conduct'
required: true
bot_user:
description: 'GitHub Bot User'
required: true
sendinblue_api_key:
description: 'Sendinblue API key'
required: true
email_from:
description: 'Sender email address'
required: true
email_to:
description: 'Recipient email address'
required: true
bot_token:
description: 'Bot GitHub token'
required: true
runs:
using: 'composite'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0
- name: Install jq
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y jq
- name: Check if actor is bot user
shell: bash
id: check_actor
run: |
if [ "${{ github.actor }}" == "${{ inputs.bot_user }}" ]; then
echo "actor_is_bot=true" >> $GITHUB_ENV
else
echo "actor_is_bot=false" >> $GITHUB_ENV
fi
- name: Create data directory
if: env.actor_is_bot != 'true'
shell: bash
run: mkdir -p data
- name: Save comment details to JSON file
if: env.actor_is_bot != 'true'
shell: bash
run: |
COMMENT_URL="${{ github.event.comment.html_url }}"
if echo "$COMMENT_URL" | grep -q "pull"; then
EVENT_TYPE="pull request"
elif echo "$COMMENT_URL" | grep -q "discussion"; then
EVENT_TYPE="discussion"
else
EVENT_TYPE="issue"
fi
if [[ "${{ github.event_name }}" == "issue_comment" || "${{ github.event_name }}" == "pull_request_review_comment" ]]; then
jq -n --arg type "comment" \
--arg comment_id "${{ github.event.comment.id }}" \
--arg user "${{ github.event.comment.user.login }}" \
--arg user_id "${{ github.event.comment.user.id }}" \
--arg user_avatar_url "${{ github.event.comment.user.avatar_url }}" \
--arg user_html_url "${{ github.event.comment.user.html_url }}" \
--arg user_type "${{ github.event.comment.user.type }}" \
--arg event_type "$EVENT_TYPE" \
--arg event_number "${{ github.event.issue.number }}" \
--arg event_title "${{ github.event.issue.title }}" \
--arg event_body "${{ github.event.issue.body }}" \
--arg comment_body "${{ github.event.comment.body }}" \
--arg created_at "${{ github.event.comment.created_at }}" \
--arg updated_at "${{ github.event.comment.updated_at }}" \
--arg event_url "${{ github.event.issue.html_url }}" \
--arg comment_url "${{ github.event.comment.html_url }}" \
--arg repository_name "${{ github.repository }}" \
--arg repository_full_name "${{ github.repository.full_name }}" \
--arg repository_html_url "${{ github.repository.html_url }}" \
'{type: $type, data: {comment_id: $comment_id, user: $user, user_id: $user_id, user_avatar_url: $user_avatar_url, user_html_url: $user_html_url, user_type: $user_type, event_type: $event_type, event_number: $event_number, event_title: $event_title, event_body: $event_body, comment_body: $comment_body, created_at: $created_at, updated_at: $updated_at, event_url: $event_url, comment_url: $comment_url, repository_name: $repository_name, repository_full_name: $repository_full_name, repository_html_url: $repository_html_url}}' > data/comment.json
elif [[ "${{ github.event_name }}" == "discussion_comment" ]]; then
jq -n --arg type "comment" \
--arg comment_id "${{ github.event.comment.id }}" \
--arg user "${{ github.event.comment.user.login }}" \
--arg user_id "${{ github.event.comment.user.id }}" \
--arg user_avatar_url "${{ github.event.comment.user.avatar_url }}" \
--arg user_html_url "${{ github.event.comment.user.html_url }}" \
--arg user_type "${{ github.event.comment.user.type }}" \
--arg event_type "$EVENT_TYPE" \
--arg event_number "${{ github.event.discussion.number }}" \
--arg event_title "${{ github.event.discussion.title }}" \
--arg event_body "${{ github.event.discussion.body }}" \
--arg comment_body "${{ github.event.comment.body }}" \
--arg created_at "${{ github.event.comment.created_at }}" \
--arg updated_at "${{ github.event.comment.updated_at }}" \
--arg event_url "${{ github.event.discussion.html_url }}" \
--arg comment_url "${{ github.event.comment.html_url }}" \
--arg repository_name "${{ github.repository }}" \
--arg repository_full_name "${{ github.repository.full_name }}" \
--arg repository_html_url "${{ github.repository.html_url }}" \
'{type: $type, data: {comment_id: $comment_id, user: $user, user_id: $user_id, user_avatar_url: $user_avatar_url, user_html_url: $user_html_url, user_type: $user_type, event_type: $event_type, event_number: $event_number, event_title: $event_title, event_body: $event_body, comment_body: $comment_body, created_at: $created_at, updated_at: $updated_at, event_url: $event_url, comment_url: $comment_url, repository_name: $repository_name, repository_full_name: $repository_full_name, repository_html_url: $repository_html_url}}' > data/comment.json
fi
cat data/comment.json
- name: Check if CODE_OF_CONDUCT.md exists
id: check_coc
shell: bash
run: |
if [ -f CODE_OF_CONDUCT.md ]; then
echo "coc_file=CODE_OF_CONDUCT.md" >> $GITHUB_ENV
else
echo "No CODE_OF_CONDUCT.md file found"
echo "missing_coc=true" >> $GITHUB_ENV
fi
- name: Trigger Handle Repos without Code of Conduct Action
if: env.missing_coc == 'true'
uses: SOM-Research/code-of-conduct-initializer@v1
with:
USER_GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
EVENT_ACTION: 'no_code_of_conduct'
- name: Stop When No CoC
if: env.missing_coc == 'true'
shell: bash
run: |
exit 1
- name: Check if CODE_OF_CONDUCT.md has more than 5 lines
id: check_lines
shell: bash
run: |
line_count=$(wc -l < ${{ env.coc_file }})
echo "line_count=$line_count" >> $GITHUB_ENV
if [ $line_count -le 5 ]; then
echo "CODE_OF_CONDUCT.md has 5 lines or less"
echo "repo_name=${{ github.repository }}" >> $GITHUB_ENV
echo "repo_url=${{ github.server_url }}/repos/${{ github.repository }}" >> $GITHUB_ENV
fi
- name: Debug environment variables
shell: bash
if: env.line_count <= 5
run: |
echo "line_count=$line_count"
echo "repo_name=$repo_name"
- name: Activate Issue Manager For Url
if: env.line_count <= 5
uses: SOM-Research/issue-manager@v1
with:
bot_token: ${{ inputs.bot_token }}
repo_name: ${{ env.repo_name }}
event_action: 'code_of_conduct_incomplete'
- name: Stop When Url
if: env.line_count <= 5
shell: bash
run: |
exit 1
- name: Read Code of Conduct
id: read_coc
shell: bash
run: |
mkdir -p data
content=$(cat ${{ env.coc_file }})
echo "$content" > data/code_of_conduct.txt
- name: Get repository details
id: repo_details
shell: bash
run: |
echo "repo_name=${{ github.repository }}" >> $GITHUB_ENV
echo "repo_url=https://github.com/${{ github.repository }}" >> $GITHUB_ENV
- name: Convert Code of Conduct to JSON
id: convert_to_json
shell: bash
run: |
content=$(cat data/code_of_conduct.txt)
repo_name="${{ env.repo_name }}"
repo_url="${{ env.repo_url }}"
jq -n --arg type "code_of_conduct" --arg code_of_conduct "$content" --arg repository_name "$repo_name" --arg repository_url "$repo_url" '{type: $type, code_of_conduct: $code_of_conduct, repository_name: $repository_name, repository_url: $repository_url}' > data/payload.json
cat data/payload.json
- name: Send Code of Conduct to server
id: send_coc
shell: bash
run: |
response=$(curl -s -X POST "${{ inputs.SERVER }}" -H "Content-Type: application/json" --data @data/payload.json)
echo "$response" > data/response.json
cat data/response.json
- name: Check response status
id: check_response
shell: bash
run: |
status=$(jq -r '.data.status' data/response.json)
echo "status=$status" >> $GITHUB_ENV
flags=$(jq -c '.data.flags' data/response.json)
echo "Flags: $flags"
echo "flags=$flags" >> $GITHUB_ENV
- name: Send Comment and Flags to Comment-Analyzer
uses: SOM-Research/comment-analyzer@v2
with:
github_token: ${{ inputs.GITHUB_TOKEN }}
server_url: ${{ inputs.SERVER }}
sendinblue_api_key: ${{ inputs.sendinblue_api_key }}
email_from: ${{ inputs.email_from }}
email_to: ${{ inputs.email_to }}
bot_user: ${{ inputs.bot_user }}
bot_token: ${{ inputs.bot_token }}
comment_json: data/comment.json
flags: ${{ env.flags }}
- name: Calculate missing flags
id: calculate_missing_flags
shell: bash
run: |
required_flags=("F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10")
flags=$(echo '${{ env.flags }}' | jq -r 'keys[]')
missing_flags=()
for required_flag in "${required_flags[@]}"; do
if ! echo "$flags" | grep -q "$required_flag"; then
missing_flags+=("$required_flag")
fi
done
missing_flags_str=$(IFS=','; echo "${missing_flags[*]}")
echo "missing_flags=$missing_flags_str" >> $GITHUB_ENV
- name: Trigger Issue Creation Workflow
if: env.missing_flags != '' && env.status == 'analyzed'
uses: SOM-Research/issue-manager@v1
with:
bot_token: ${{ inputs.bot_token }}
repo_name: ${{ env.repo_name }}
event_action: 'create_issue_for_missing_guidelines'
missing_flags: ${{ env.missing_flags }}
- name: Check Contributor Covenant Version
id: check_version
shell: bash
run: |
version=$(jq -r '.data.contributor_covenant_version' data/response.json)
echo "version=$version" >> $GITHUB_ENV
- name: Trigger Handle Contributor Covenant Version 1.4 Action
if: env.version == '1.4' && env.status == 'analyzed'
uses: SOM-Research/code-of-conduct-initializer@v1
with:
USER_GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }}
EVENT_ACTION: 'handle_contributor_covenant_1_4'