File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ name : Warn about month-old PRs
2+
3+ on :
4+ schedule :
5+ - cron : ' 0 0 */2 * *' # Runs every other day at midnight
6+
7+ jobs :
8+ stale-prs :
9+ runs-on : ubuntu-latest
10+ steps :
11+ - name : Checkout repository
12+ uses : actions/checkout@v2
13+
14+ - name : Warn about stale PRs
15+ uses : actions/github-script@v4
16+ with :
17+ script : |
18+ const { Octokit } = require("@octokit/rest");
19+ const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
20+
21+ const owner = context.repo.owner;
22+ const repo = context.repo.repo;
23+ const staleTime = new Date();
24+ staleTime.setMonth(staleTime.getMonth() - 1);
25+
26+ const prs = await octokit.pulls.list({
27+ owner,
28+ repo,
29+ state: 'open'
30+ });
31+
32+ for (const pr of prs.data) {
33+ const comments = await octokit.issues.listComments({
34+ owner,
35+ repo,
36+ issue_number: pr.number
37+ });
38+
39+ const lastComment = comments.data.length > 0 ? new Date(comments.data[comments.data.length - 1].created_at) : new Date(pr.created_at);
40+
41+ if (lastComment < staleTime) {
42+ await octokit.issues.createComment({
43+ owner,
44+ repo,
45+ issue_number: pr.number,
46+ body: 'This PR has been stale for over a month. Please update or close it.'
47+ });
48+ }
49+ }
50+ env :
51+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
You can’t perform that action at this time.
0 commit comments