-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
92 lines (86 loc) · 3.05 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
name: Create issue
description: GitHub Action to create an issue as the github-actions user
inputs:
title:
type: string
required: true
description:
type: string
required: true
close_existing:
type: boolean
required: false
default: false
runs:
using: composite
steps:
- name: Close existing issues
shell: bash
if: ${{ inputs.close_existing == 'true' }}
env:
TITLE: ${{ inputs.title }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
# Close any existing issues with the same title
# https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28
RESP_CODE=$(curl -w %{http_code} -s -o __issues.json \
-X GET https://api.github.com/repos/$GITHUB_REPOSITORY/issues?state=open \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ github.token }}" \
)
if [[ $RESP_CODE != "200" ]]; then
echo "Unable to fetch issues - HTTP response code was $RESP_CODE"
exit 1
fi
ISSUE_NUMBERS=$(jq -r --arg var1 "$TITLE" '.[] | select(.title == $var1) | select(.user.login == "github-actions[bot]") | .number' __issues.json)
for ISSUE_NUMBER in $ISSUE_NUMBERS; do
# https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#update-an-issue
RESP_CODE=$(curl -w %{http_code} -s -o __issues.json \
-X PATCH https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$ISSUE_NUMBER \
-H "Accept: application/vnd.github+json" \
-H "Authorization: token ${{ github.token }}" \
-d '{"state":"closed"}'
)
if [[ $RESP_CODE != "200" ]]; then
echo "Unable to close issue $ISSUE_NUMBER - HTTP response code was $RESP_CODE"
exit 1
fi
echo "Issue $ISSUE_NUMBER closed"
done
- name: Create issue
shell: bash
env:
TITLE: ${{ inputs.title }}
DESCRIPTION: ${{ inputs.description }}
GITHUB_REPOSITORY: ${{ github.repository }}
run: |
# Escape double quotes '"' => '\"'
TITLE=${TITLE//\"/\\\"}
DESCRIPTION=${DESCRIPTION//\"/\\\"}
# Create new issue via GitHub API
# https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#create-an-issue
RESP_CODE=$(curl -w %{http_code} -s -o /dev/null \
-X POST https://api.github.com/repos/$GITHUB_REPOSITORY/issues \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token ${{ github.token }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-d @- << EOF
{
"title": "$TITLE",
"body": "$DESCRIPTION"
}
EOF
)
if [[ $RESP_CODE == "201" ]]; then
echo "New issue created"
else
echo "Fail to create issue - HTTP response code was $RESP_CODE"
exit 1
fi
- name: Delete temporary files
shell: bash
if: always()
run: |
if [[ -f __issues.json ]]; then
rm __issues.json
fi