File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 22
22
env :
23
23
TITLE : ${{steps.getTitle.outputs.MILESTONE_NAME}}
24
24
GH_TOKEN : ${{ github.token }}
25
+ shell : bash
25
26
run : |
26
- gh api \
27
+ response=$( gh api \
27
28
--method POST \
28
29
/repos/${{ github.repository }}/milestones \
29
- -f "title=$TITLE" -f "state=open"
30
+ -f "title=$TITLE" -f "state=open")
31
+
32
+ # if response has a errors[].code === "already_exists" in a JSON response, we do nothing
33
+ if echo "$response" | jq -e '.errors | map(select(.code == "already_exists")) | length > 0' > /dev/null; then
34
+ echo "Milestone $TITLE already exists, no action needed"
35
+ # if there is .title === $TITLE in the response, we successfully created the milestone
36
+ elif echo "$response" | jq -e ".title == \"$TITLE\"" >/dev/null; then
37
+ echo "Milestone $TITLE created successfully"
38
+ # otherwise, we print the error
39
+ else
40
+ echo "Error creating milestone $TITLE"
41
+ echo $response
42
+ exit 1
43
+ fi
You can’t perform that action at this time.
0 commit comments