From 8c24fa495e09307145c7a8ecef0ed6adef952cc4 Mon Sep 17 00:00:00 2001 From: Siddheya Kulkarni <115717746+Asymtode712@users.noreply.github.com> Date: Sat, 27 Jul 2024 08:40:36 +0530 Subject: [PATCH] Update close-old-pr.yml --- .github/workflows/close-old-pr.yml | 71 +++++++++++------------------- 1 file changed, 26 insertions(+), 45 deletions(-) diff --git a/.github/workflows/close-old-pr.yml b/.github/workflows/close-old-pr.yml index 88ea86a..b310d4f 100644 --- a/.github/workflows/close-old-pr.yml +++ b/.github/workflows/close-old-pr.yml @@ -1,53 +1,34 @@ -name: Close Stale PRs Without Owner Comments +name: Close Stale PRs on: schedule: - - cron: "0 0 * * *" # Runs daily at midnight + - cron: '0 0 * * *' # Runs daily at midnight + pull_request: + types: + - opened + - reopened + - synchronize + +permissions: + pull-requests: write + issues: write jobs: close_stale_prs: runs-on: ubuntu-latest - + permissions: + pull-requests: write + steps: - - name: Check out the repository - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Close Stale PRs Without Owner Comments - run: | - const daysThreshold = 30; - const github = require('@actions/github'); - const { Octokit } = require('@octokit/rest'); - const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN }); - const owner = github.context.repo.owner; - const repo = github.context.repo.repo; - const now = new Date(); - const thresholdDate = new Date(now.setDate(now.getDate() - daysThreshold)); - - async function run() { - const { data: pullRequests } = await octokit.pulls.list({ owner, repo, state: 'open' }); - for (const pr of pullRequests) { - const { data: comments } = await octokit.issues.listComments({ owner, repo, issue_number: pr.number }); - const ownerComments = comments.filter(comment => comment.user.login === owner); - const recentOwnerComment = ownerComments.find(comment => new Date(comment.created_at) > thresholdDate); - - if (!recentOwnerComment) { - await octokit.pulls.update({ owner, repo, pull_number: pr.number, state: 'closed' }); - await octokit.issues.createComment({ - owner, - repo, - issue_number: pr.number, - body: "This pull request has been closed because there has been no comment from the repository owner for the last 30 days. Please reach out to the maintainers if you have any questions." - }); - } - } - } - - run().catch(err => { - console.error(err); - process.exit(1); - }); - - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/stale@v7 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + stale-pr-message: 'This PR has been automatically closed due to inactivity from the owner for 30 days.' + days-before-pr-stale: 30 + days-before-pr-close: 0 + exempt-pr-author: false + exempt-pr-labels: '' + only-labels: '' + operations-per-run: 30 + remove-stale-when-updated: true + debug-only: false