Skip to content

Commit 1ef1bc4

Browse files
authored
Update close-innactive-issues-without-repro.yaml
updating to ensure no additional activity happened after label was added
1 parent 2cc35d0 commit 1ef1bc4

File tree

1 file changed

+40
-26
lines changed

1 file changed

+40
-26
lines changed

.github/workflows/close-innactive-issues-without-repro.yaml

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Close Issues with Tag Needs Repro Link After 1 Week of Inactivity
33
on:
44
schedule:
55
- cron: '0 0 * * *' # Run every day at midnight
6-
workflow_dispatch: # Allows manual triggering
6+
workflow_dispatch:
77

88
jobs:
99
close-issues:
@@ -22,18 +22,19 @@ jobs:
2222
- name: Close Inactive Issues that are missing Repro Link
2323
env:
2424
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25-
LABEL_NAME: 'Status%3A%20Needs%20a%20reproduction%20link'
25+
LABEL_NAME: 'Status: Needs a reproduction link'
26+
LABEL_NAME_URL: 'Status%3A%20Needs%20a%20reproduction%20link'
2627
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.'
2728
run: |
28-
set -e # Stop the script if any command fails
29-
set -x # Echo each command before executing it
29+
set -e
30+
set -x
3031
3132
page=1
3233
while : ; do
3334
echo "Fetching page $page of issues..."
3435
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")
36+
-H "Accept: application/vnd.github.v3+json" \
37+
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues?state=open&labels=$LABEL_NAME_URL&per_page=100&page=$page")
3738
3839
echo $response > issues.json
3940
@@ -42,52 +43,65 @@ jobs:
4243
break
4344
fi
4445
45-
echo "Commenting and closing issues..."
46-
jq -c '.[] | {number: .number, updated_at: .updated_at}' issues.json | while read -r line; do
46+
echo "Checking issues for closure..."
47+
jq -c '.[] | {number: .number}' issues.json | while read -r line; do
4748
issue=$(echo $line | jq -r '.number')
48-
updated_at=$(echo $line | jq -r '.updated_at')
4949
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";}')
50+
timeline=$(curl -sS -H "Authorization: token $GITHUB_TOKEN" \
51+
-H "Accept: application/vnd.github.mockingbird-preview" \
52+
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue/timeline")
53+
54+
echo $timeline > timeline.json
5355
54-
if [ "$is_week_old" = "yes" ]; then
55-
echo "Commenting and closing issues..."
56-
jq -c '.[] | .number' issues.json | while read -r issue; do
56+
# Find the time when the label was added
57+
label_added_at=$(jq -c "map(select(.event==\"labeled\" and .label.name | contains(\"$LABEL_NAME\"))) | .[0].created_at" timeline.json)
58+
59+
if [ "$label_added_at" != "null" ]; then
60+
label_added_at=$(echo $label_added_at | jq -r)
61+
62+
# Check if there has been any activity after the label was added
63+
has_activity_after_label=$(jq -c "map(select(.created_at > \"$label_added_at\")) | length" timeline.json)
64+
65+
# Check if at least 168 hours have passed since the label was added
66+
current_time=$(date --utc +'%Y-%m-%dT%H:%M:%SZ')
67+
is_week_old=$(dateutils.ddiff "$label_added_at" "$current_time" -f '%H:%M:%S' | awk -F: '{if ($1 >= 168) print "yes"; else print "no";}')
68+
69+
if [ "$is_week_old" = "yes" ] && [ "$has_activity_after_label" = "0" ]; then
70+
echo "Commenting and closing issue $issue..."
5771
# Comment on the issue
5872
COMMENT_RESPONSE=$(curl -sS -w "%{http_code}" -X POST -H "Authorization: token $GITHUB_TOKEN" \
5973
-H "Accept: application/vnd.github.v3+json" \
6074
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue/comments" \
6175
-d "{\"body\": \"$CUSTOM_MESSAGE\"}")
62-
76+
6377
HTTP_STATUS=$(echo $COMMENT_RESPONSE | rev | cut -c 1-3 | rev)
64-
RESPONSE_BODY=$(echo $COMMENT_RESPONSE | rev | cut -c 4- | rev)
65-
78+
6679
if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then
6780
echo "Successfully commented on issue $issue."
6881
else
69-
echo "Failed to comment on issue $issue. HTTP Status: $HTTP_STATUS, Response: $RESPONSE_BODY"
82+
echo "Failed to comment on issue $issue. HTTP Status: $HTTP_STATUS"
7083
exit 1
7184
fi
72-
85+
7386
# Close the issue
7487
RESPONSE=$(curl -sS -w "%{http_code}" -X PATCH -H "Authorization: token $GITHUB_TOKEN" \
7588
-H "Accept: application/vnd.github.v3+json" \
7689
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue" \
7790
-d "{\"state\": \"closed\"}")
78-
91+
7992
HTTP_STATUS=$(echo $RESPONSE | rev | cut -c 1-3 | rev)
80-
RESPONSE_BODY=$(echo $RESPONSE | rev | cut -c 4- | rev)
81-
93+
8294
if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then
8395
echo "Successfully closed issue $issue."
8496
else
85-
echo "Failed to close issue $issue. HTTP Status: $HTTP_STATUS, Response: $RESPONSE_BODY"
97+
echo "Failed to close issue $issue. HTTP Status: $HTTP_STATUS"
8698
exit 1
8799
fi
88-
done
100+
else
101+
echo "Issue $issue does not meet closure criteria. Skipping."
102+
fi
89103
else
90-
echo "Issue $issue is not yet a week old. Skipping."
104+
echo "Label not found for issue $issue. Skipping."
91105
fi
92106
done
93107

0 commit comments

Comments
 (0)