forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
51 lines (43 loc) · 1.53 KB
/
stale-prs.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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@v4
- name: Warn about stale PRs
uses: actions/github-script@v7
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 }}