Skip to content

Close Issues with Tag Needs Repro Link #292

Close Issues with Tag Needs Repro Link

Close Issues with Tag Needs Repro Link #292

name: Close Issues with Tag Needs Repro Link
on:
schedule:
- cron: '0 0 * * *' # Run every day at midnight
workflow_dispatch:
jobs:
close-issues:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Install Node.js
uses: actions/setup-node@v2
- name: Install jq and date command
run: sudo apt-get update && sudo apt-get install -y jq dateutils
- name: Close Inactive Issues that are missing Repro Link
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LABEL_NAME: 'Status: Needs a reproduction link'
LABEL_NAME_URL: 'Status%3A%20Needs%20a%20reproduction%20link'
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 1 day without a reproduction link, it will be closed to allow prioritization of other issues. /n /n If this needs additional investigation, please share a reproduction link by opening a new issue. Thanks for your diligence in helping us continuously improve the StackBlitz platform.'
run: |
set -e
set -x
page=1
while : ; do
echo "Fetching page $page of issues..."
response=$(curl -sS -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues?state=open&labels=$LABEL_NAME_URL&per_page=100&page=$page")
echo $response > issues.json
if [ $(jq length issues.json) -eq 0 ]; then
echo "No more issues found."
break
fi
echo "Checking issues for closure..."
jq -c '.[] | {number: .number}' issues.json | while read -r line; do
issue=$(echo $line | jq -r '.number')
timeline=$(curl -sS -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.mockingbird-preview" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue/timeline")
echo $timeline > timeline.json
# Find the time when the label was added
label_added_at=$(jq -c 'map(select(.event=="labeled" and (.label.name | contains("'"$LABEL_NAME"'")))) | .[0].created_at' timeline.json)
if [ "$label_added_at" != "null" ]; then
label_added_at=$(echo $label_added_at | jq -r)
# Check if there has been any activity after the label was added
has_activity_after_label=$(jq -c "map(select(.created_at > \"$label_added_at\")) | length" timeline.json)
# Check if at least 1 day has passed since the label was added
current_time=$(date --utc +'%Y-%m-%dT%H:%M:%SZ')
is_day_old=$(dateutils.ddiff "$label_added_at" "$current_time" -f '%H:%M:%S' | awk -F: '{if ($1 >= 24) print "yes"; else print "no";}')
if [ "$is_day_old" = "yes" ] && [ "$has_activity_after_label" = "0" ]; then
echo "Commenting and closing issue $issue..."
# Comment on the issue
COMMENT_RESPONSE=$(curl -sS -w "%{http_code}" -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue/comments" \
-d "{\"body\": \"$CUSTOM_MESSAGE\"}")
HTTP_STATUS=$(echo $COMMENT_RESPONSE | rev | cut -c 1-3 | rev)
if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then
echo "Successfully commented on issue $issue."
else
echo "Failed to comment on issue $issue. HTTP Status: $HTTP_STATUS"
exit 1
fi
# Close the issue
RESPONSE=$(curl -sS -w "%{http_code}" -X PATCH -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/issues/$issue" \
-d "{\"state\": \"closed\"}")
HTTP_STATUS=$(echo $RESPONSE | rev | cut -c 1-3 | rev)
if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then
echo "Successfully closed issue $issue."
else
echo "Failed to close issue $issue. HTTP Status: $HTTP_STATUS"
exit 1
fi
else
echo "Issue $issue does not meet closure criteria. Skipping."
fi
else
echo "Label not found for issue $issue. Skipping."
fi
done
((page++))
done