forked from anomalyco/models.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (59 loc) · 2.19 KB
/
Copy pathclose-stale-pull-requests.yml
File metadata and controls
68 lines (59 loc) · 2.19 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Close stale pull requests
on:
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
permissions:
issues: write
pull-requests: write
jobs:
close-stale-pull-requests:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v8
env:
REVIEWER: rekram1-node
with:
script: |
const { owner, repo } = context.repo
const now = Date.now()
const weekAgo = now - 7 * 24 * 60 * 60 * 1000
const monthAgo = now - 30 * 24 * 60 * 60 * 1000
const pulls = await github.paginate(github.rest.pulls.list, {
owner,
repo,
state: "open",
per_page: 100,
})
const feedbackPulls = new Set()
for (const qualifier of ["commenter", "reviewed-by"]) {
const results = await github.paginate(
github.rest.search.issuesAndPullRequests,
{
q: `repo:${owner}/${repo} is:pr is:open ${qualifier}:${process.env.REVIEWER}`,
per_page: 100,
},
)
for (const result of results) feedbackPulls.add(result.number)
}
for (const pull of pulls) {
const updatedAt = Date.parse(pull.updated_at)
const monthStale = updatedAt < monthAgo
const feedbackStale = updatedAt < weekAgo && feedbackPulls.has(pull.number)
if (!monthStale && !feedbackStale) continue
const reason = monthStale
? "it has not been updated in 30 days"
: `it has not been updated in 7 days after feedback from @${process.env.REVIEWER}`
await github.rest.issues.createComment({
owner,
repo,
issue_number: pull.number,
body: `Closing this pull request as stale because ${reason}. Feel free to reopen it or submit a new pull request if the work is resumed.`,
})
await github.rest.pulls.update({
owner,
repo,
pull_number: pull.number,
state: "closed",
})
}