Skip to content

Commit 2cc35d0

Browse files
authored
Create close-innactive-issues-without-repro.yaml
Initial commit
1 parent 4739be6 commit 2cc35d0

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Close Issues with Tag Needs Repro Link After 1 Week of Inactivity
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # Run every day at midnight
6+
workflow_dispatch: # Allows manual triggering
7+
8+
jobs:
9+
close-issues:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: Install Node.js
17+
uses: actions/setup-node@v2
18+
19+
- name: Install jq and date command
20+
run: sudo apt-get update && sudo apt-get install -y jq dateutils
21+
22+
- name: Close Inactive Issues that are missing Repro Link
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
LABEL_NAME: 'Status%3A%20Needs%20a%20reproduction%20link'
26+
CUSTOM_MESSAGE: 'In order to investigate further we need a link to a StackBlitz project reproducing the issue. /n /n As this issue has been inactive for 7 days without a reproduction link, it will be temporarily closed to allow prioritization of other issues. /n /n If this needs additional investigation, please share a reproduction link and re-open the issue! Thanks for your diligence in helping us continuosly improve the StackBlitz platform.'
27+
run: |
28+
set -e # Stop the script if any command fails
29+
set -x # Echo each command before executing it
30+
31+
page=1
32+
while : ; do
33+
echo "Fetching page $page of issues..."
34+
response=$(curl -sS -H "Authorization: token $GITHUB_TOKEN" \
35+
-H "Accept: application/vnd.github.v3+json" \
36+
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues?state=open&labels=$LABEL_NAME&per_page=100&page=$page")
37+
38+
echo $response > issues.json
39+
40+
if [ $(jq length issues.json) -eq 0 ]; then
41+
echo "No more issues found."
42+
break
43+
fi
44+
45+
echo "Commenting and closing issues..."
46+
jq -c '.[] | {number: .number, updated_at: .updated_at}' issues.json | while read -r line; do
47+
issue=$(echo $line | jq -r '.number')
48+
updated_at=$(echo $line | jq -r '.updated_at')
49+
50+
# Check if one week has passed since last updated
51+
current_time=$(date --utc +'%Y-%m-%dT%H:%M:%SZ')
52+
is_week_old=$(dateutils.ddiff "$updated_at" "$current_time" -f '%H:%M:%S' | awk -F: '{if ($1 >= 168) print "yes"; else print "no";}')
53+
54+
if [ "$is_week_old" = "yes" ]; then
55+
echo "Commenting and closing issues..."
56+
jq -c '.[] | .number' issues.json | while read -r issue; do
57+
# Comment on the issue
58+
COMMENT_RESPONSE=$(curl -sS -w "%{http_code}" -X POST -H "Authorization: token $GITHUB_TOKEN" \
59+
-H "Accept: application/vnd.github.v3+json" \
60+
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue/comments" \
61+
-d "{\"body\": \"$CUSTOM_MESSAGE\"}")
62+
63+
HTTP_STATUS=$(echo $COMMENT_RESPONSE | rev | cut -c 1-3 | rev)
64+
RESPONSE_BODY=$(echo $COMMENT_RESPONSE | rev | cut -c 4- | rev)
65+
66+
if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then
67+
echo "Successfully commented on issue $issue."
68+
else
69+
echo "Failed to comment on issue $issue. HTTP Status: $HTTP_STATUS, Response: $RESPONSE_BODY"
70+
exit 1
71+
fi
72+
73+
# Close the issue
74+
RESPONSE=$(curl -sS -w "%{http_code}" -X PATCH -H "Authorization: token $GITHUB_TOKEN" \
75+
-H "Accept: application/vnd.github.v3+json" \
76+
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue" \
77+
-d "{\"state\": \"closed\"}")
78+
79+
HTTP_STATUS=$(echo $RESPONSE | rev | cut -c 1-3 | rev)
80+
RESPONSE_BODY=$(echo $RESPONSE | rev | cut -c 4- | rev)
81+
82+
if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then
83+
echo "Successfully closed issue $issue."
84+
else
85+
echo "Failed to close issue $issue. HTTP Status: $HTTP_STATUS, Response: $RESPONSE_BODY"
86+
exit 1
87+
fi
88+
done
89+
else
90+
echo "Issue $issue is not yet a week old. Skipping."
91+
fi
92+
done
93+
94+
((page++))
95+
done

0 commit comments

Comments
 (0)