Skip to content

Commit 62927a4

Browse files
authored
Update close-stale-issues.yml
Trying to fix the commenting portion
1 parent 2aca0fd commit 62927a4

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

.github/workflows/close-stale-issues.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
env:
2424
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2525
LABEL_NAME: 'Status%3A%20Stale'
26-
CUSTOM_MESSAGE: 'Appologies that we were unable to address this issue in a timely manner! Given that we have millions of free users this has been a challenge that we are working on over time. This issue is being closed in order to allow us to focus on resolving more recently active issues. If this issue is still meaningful, please feel free to comment an update and re-open the issue for troubleshooting! Thanks for your continued loyalty to the StackBlitz platform over the years!'
26+
CUSTOM_MESSAGE: 'Appologies that we were unable to address this issue in a timely manner! \\n Given that we have millions of free users this has been a challenge, and we are working to improve over time. As part of an effort to focus on driving the most recent issues to resolution, this issue is being closed. \\n If this issue is still meaningful, please comment with an update and re-open the issue for troubleshooting! Thanks for your continued loyalty to the StackBlitz platform over the years!'
2727
run: |
2828
set -e # Stop the script if any command fails
2929
set -x # Echo each command before executing it
@@ -35,28 +35,36 @@ jobs:
3535
-H "Accept: application/vnd.github.v3+json" \
3636
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues?state=open&labels=$LABEL_NAME&per_page=100&page=$page")
3737
38-
# Check if curl command succeeded
39-
if [ $? -ne 0 ]; then
40-
echo "Curl command failed."
41-
exit 1
42-
fi
43-
44-
# Write to issues.json file for jq processing
4538
echo $response > issues.json
4639
47-
# Exit loop if no issues are returned
4840
if [ $(jq length issues.json) -eq 0 ]; then
4941
echo "No more issues found."
5042
break
5143
fi
5244
53-
echo "Closing issues..."
54-
# Close issues
45+
echo "Commenting and closing issues..."
5546
jq -c '.[] | .number' issues.json | while read -r issue; do
47+
# Comment on the issue
48+
COMMENT_RESPONSE=$(curl -sS -w "%{http_code}" -X POST -H "Authorization: token $GITHUB_TOKEN" \
49+
-H "Accept: application/vnd.github.v3+json" \
50+
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue/comments" \
51+
-d "{\"body\": \"$CUSTOM_MESSAGE\"}")
52+
53+
HTTP_STATUS=$(echo $COMMENT_RESPONSE | rev | cut -c 1-3 | rev)
54+
RESPONSE_BODY=$(echo $COMMENT_RESPONSE | rev | cut -c 4- | rev)
55+
56+
if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then
57+
echo "Successfully commented on issue $issue."
58+
else
59+
echo "Failed to comment on issue $issue. HTTP Status: $HTTP_STATUS, Response: $RESPONSE_BODY"
60+
exit 1
61+
fi
62+
63+
# Close the issue
5664
RESPONSE=$(curl -sS -w "%{http_code}" -X PATCH -H "Authorization: token $GITHUB_TOKEN" \
5765
-H "Accept: application/vnd.github.v3+json" \
5866
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue" \
59-
-d "{\"state\": \"closed\", \"body\": \"$CUSTOM_MESSAGE\"}")
67+
-d "{\"state\": \"closed\"}")
6068
6169
HTTP_STATUS=$(echo $RESPONSE | rev | cut -c 1-3 | rev)
6270
RESPONSE_BODY=$(echo $RESPONSE | rev | cut -c 4- | rev)
@@ -68,6 +76,10 @@ jobs:
6876
exit 1
6977
fi
7078
done
79+
80+
((page++))
81+
done
82+
7183

7284
# Move to the next page
7385
((page++))

0 commit comments

Comments
 (0)