From b0f860003ffc8f3db80189991b640749bb4806f9 Mon Sep 17 00:00:00 2001 From: amrit Date: Thu, 7 Aug 2025 09:32:55 +0530 Subject: [PATCH] feat: add auto closing of issues / pull requests based on staleness (#1944) ## Summary by cubic Added GitHub workflows to automatically close stale issues and pull requests with unresolved merge conflicts older than 3 days. - **Automation** - Closes open pull requests with merge conflicts after 3 days. - Closes issues immediately when marked as stale. ## Summary by CodeRabbit * **Chores** * Introduced automated workflows to close old pull requests with unresolved merge conflicts and to close stale issues, helping keep the repository clean and up to date. --- .github/workflows/close-conflicted-prs.yml | 50 ++++++++++++++++++++++ .github/workflows/close-stale-issues.yml | 21 +++++++++ 2 files changed, 71 insertions(+) create mode 100644 .github/workflows/close-conflicted-prs.yml create mode 100644 .github/workflows/close-stale-issues.yml diff --git a/.github/workflows/close-conflicted-prs.yml b/.github/workflows/close-conflicted-prs.yml new file mode 100644 index 000000000..4cb12112f --- /dev/null +++ b/.github/workflows/close-conflicted-prs.yml @@ -0,0 +1,50 @@ +name: Close Old Conflicted PRs + +on: + schedule: + - cron: "0 * * * *" + +jobs: + close_conflicted_prs: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Close PRs with merge conflicts older than 3 days + uses: actions/github-script@v7 + with: + script: | + const prs = await github.rest.pulls.list({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open' + }); + + const now = new Date(); + for (const pr of prs.data) { + const details = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pr.number + }); + + if (details.data.mergeable === false || details.data.mergeable === null) { + const createdAt = new Date(pr.created_at); + const diffDays = (now - createdAt) / (1000 * 60 * 60 * 24); + if (diffDays > 3) { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number, + body: "This PR has merge conflicts and has been open for more than 3 days. It will be automatically closed. Please resolve the conflicts and reopen the PR if you'd like to continue working on it." + }); + + await github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: pr.number, + state: 'closed' + }); + } + } + } diff --git a/.github/workflows/close-stale-issues.yml b/.github/workflows/close-stale-issues.yml new file mode 100644 index 000000000..1457e1c9d --- /dev/null +++ b/.github/workflows/close-stale-issues.yml @@ -0,0 +1,21 @@ +name: Close Stale Issues + +on: + schedule: + - cron: "0 * * * *" + +jobs: + stale: + runs-on: ubuntu-latest + permissions: + issues: write + contents: read + steps: + - uses: actions/stale@v9 + with: + days-before-stale: 3 + days-before-close: 0 + only-issues: true + stale-issue-label: "stale" + stale-issue-message: "This issue is stale (3+ days) and will be closed." + close-issue-message: "Closing stale issue."