diff --git a/.github/workflows/close-inactive-issues-without-repro.yaml b/.github/workflows/close-inactive-issues-without-repro.yaml index 1318437f..69f21b58 100644 --- a/.github/workflows/close-inactive-issues-without-repro.yaml +++ b/.github/workflows/close-inactive-issues-without-repro.yaml @@ -1,4 +1,4 @@ -name: Close Issues with Tag Needs Repro Link After 1 Month of Inactivity +name: Close Issues with Tag Needs Repro Link on: schedule: @@ -24,7 +24,7 @@ jobs: 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 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 continuously improve the StackBlitz platform.' + 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 @@ -62,11 +62,12 @@ jobs: # 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 30 days have passed since the label was added + # Check if at least 1 day has passed since the label was added current_time=$(date --utc +'%Y-%m-%dT%H:%M:%SZ') - is_week_old=$(dateutils.ddiff "$label_added_at" "$current_time" -f '%H:%M:%S' | awk -F: '{if ($1 >= 672) print "yes"; else print "no";}') + 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_week_old" = "yes" ] && [ "$has_activity_after_label" = "0" ]; then + + 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" \ diff --git a/.github/workflows/close-lock-engineblock-issues.yml b/.github/workflows/close-lock-engineblock-issues.yml new file mode 100644 index 00000000..76f098c2 --- /dev/null +++ b/.github/workflows/close-lock-engineblock-issues.yml @@ -0,0 +1,79 @@ +name: Close and Lock Issues with Status Stale Label + +on: + schedule: + - cron: "0 0 * * *" # Run every day at midnight + workflow_dispatch: # Allows manual triggering + +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 + run: sudo apt-get update && sudo apt-get install -y jq + + - name: Close and lock issues + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + LABEL_NAME: "Status%3A%20EngineBlock" + CUSTOM_MESSAGE: 'Hey there! \n \n It looks like you are using an EngineBlock project, which we recently removed from our starters. You can read more about how we are upgrading our starters here: [Starters Upgrade: WebContainers and Vite](https://blog.stackblitz.com/posts/webcontainers-starters-update/).\n\nMoving forward I would recommend that you see if this problem persists in a WebContainer based project. You can do that by simply clicking one of the links below: \n [node.new](https://node.new) \n [vite.new](https://vite.new) \n Or even more here.\n\nFor now, I am going to close this issue, but feel free to open a new one if you have any issues with the WebContainer based project.' + run: | + set -e # Stop the script if any command fails + set -x # Echo each command before executing it + + 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&per_page=1&page=$page") + + echo $response > issues.json + + if [ $(jq length issues.json) -eq 0 ]; then + echo "No more issues found." + break + fi + + echo "Commenting, closing, and locking issues..." + jq -c '.[] | .number' issues.json | while read -r issue; do + # 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) + RESPONSE_BODY=$(echo $COMMENT_RESPONSE | rev | cut -c 4- | 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, Response: $RESPONSE_BODY" + exit 1 + fi + + # Close and lock 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\", \"lock_reason\": \"resolved\"}") + + HTTP_STATUS=$(echo $RESPONSE | rev | cut -c 1-3 | rev) + RESPONSE_BODY=$(echo $RESPONSE | rev | cut -c 4- | rev) + + if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then + echo "Successfully closed and locked issue $issue." + else + echo "Failed to close and lock issue $issue. HTTP Status: $HTTP_STATUS, Response: $RESPONSE_BODY" + exit 1 + fi + done + done