Skip to content

warn about month old stale PRs #24615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/stale-prs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Warn about month-old PRs

on:
schedule:
- cron: '0 0 */2 * *' # Runs every other day at midnight

jobs:
stale-prs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Warn about stale PRs
uses: actions/github-script@v4
with:
script: |
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });

const owner = context.repo.owner;
const repo = context.repo.repo;
const staleTime = new Date();
staleTime.setMonth(staleTime.getMonth() - 1);

const prs = await octokit.pulls.list({
owner,
repo,
state: 'open'
});

for (const pr of prs.data) {
const comments = await octokit.issues.listComments({
owner,
repo,
issue_number: pr.number
});

const lastComment = comments.data.length > 0 ? new Date(comments.data[comments.data.length - 1].created_at) : new Date(pr.created_at);

if (lastComment < staleTime) {
await octokit.issues.createComment({
owner,
repo,
issue_number: pr.number,
body: 'This PR has been stale for over a month. Please update or close it.'
});
}
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading