From 7120491f146f133aec93be51cc28d8d4e4a01a66 Mon Sep 17 00:00:00 2001 From: Siddheya Kulkarni <115717746+Asymtode712@users.noreply.github.com> Date: Mon, 20 May 2024 19:34:36 +0530 Subject: [PATCH 1/3] created close-old-pr-woc.yml --- .github/workflows/close-old-pr-woc.yml | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 .github/workflows/close-old-pr-woc.yml diff --git a/.github/workflows/close-old-pr-woc.yml b/.github/workflows/close-old-pr-woc.yml new file mode 100644 index 0000000..cf45d8c --- /dev/null +++ b/.github/workflows/close-old-pr-woc.yml @@ -0,0 +1,53 @@ +name: Close Stale PRs Without Owner Comments + +on: + schedule: + - cron: "0 0 * * *" # Runs daily at midnight + +jobs: + close_stale_prs: + runs-on: ubuntu-latest + + 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 }} \ No newline at end of file From 01d04a3300ad155551e1ffde4f5a88eacb14ec9e Mon Sep 17 00:00:00 2001 From: Siddheya Kulkarni <115717746+Asymtode712@users.noreply.github.com> Date: Thu, 23 May 2024 01:45:57 +0530 Subject: [PATCH 2/3] Delete .github/workflows/close-old-pr-woc.yml --- .github/workflows/close-old-pr-woc.yml | 53 -------------------------- 1 file changed, 53 deletions(-) delete mode 100644 .github/workflows/close-old-pr-woc.yml diff --git a/.github/workflows/close-old-pr-woc.yml b/.github/workflows/close-old-pr-woc.yml deleted file mode 100644 index cf45d8c..0000000 --- a/.github/workflows/close-old-pr-woc.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Close Stale PRs Without Owner Comments - -on: - schedule: - - cron: "0 0 * * *" # Runs daily at midnight - -jobs: - close_stale_prs: - runs-on: ubuntu-latest - - 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 }} \ No newline at end of file From caf9f1fceb8ef95da94671189cdee42fbaaad422 Mon Sep 17 00:00:00 2001 From: Siddheya Kulkarni <115717746+Asymtode712@users.noreply.github.com> Date: Thu, 23 May 2024 01:46:52 +0530 Subject: [PATCH 3/3] created close-old-issue.yml --- .github/workflows/close-old-issue.yml | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/close-old-issue.yml diff --git a/.github/workflows/close-old-issue.yml b/.github/workflows/close-old-issue.yml new file mode 100644 index 0000000..2984191 --- /dev/null +++ b/.github/workflows/close-old-issue.yml @@ -0,0 +1,37 @@ +name: Close Old Issues +on: + schedule: + - cron: "0 0 * * *" + +jobs: + close-issues: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Close Old Issues + run: | + open_issues=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/issues?state=open" \ + | jq -r '.[] | .number') + for issue in $open_issues; do + # Get the last updated timestamp of the issue + last_updated=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/issues/$issue" \ + | jq -r '.updated_at') + days_since_update=$(( ( $(date +%s) - $(date -d "$last_updated" +%s) ) / 86400 )) + if [ $days_since_update -gt 30 ]; then + curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"state":"closed"}' \ + "https://api.github.com/repos/${{ github.repository }}/issues/$issue" + + # Add a comment explaining when the issue will be closed + curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"body":"This issue has been automatically closed because it has been inactive for more than 30 days. If you believe this is still relevant, feel free to reopen it or create a new one. Thank you!"}' \ + "https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments" + fi + done