-
Notifications
You must be signed in to change notification settings - Fork 120
86 lines (73 loc) · 3.66 KB
/
pr-migration-auto-close.yml
File metadata and controls
86 lines (73 loc) · 3.66 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Auto-Close PRs
on:
schedule:
# Runs every second day at noon UTC
- cron: '0 12 */2 * *'
workflow_dispatch:
permissions:
contents: read
jobs:
close-stale-prs:
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
steps:
- name: Close PRs labeled "auto-close"
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const label = "auto-close";
const now = new Date();
const millisecondsInADay = 24 * 60 * 60 * 1000;
const autoCloseDays = 30; // how many days before PRs should be closed automatically
// Fetch all open PRs
const prs = await github.paginate(github.rest.pulls.list, {
owner,
repo,
state: "open",
per_page: 100
});
for (const pr of prs) {
// Check if PR has the "auto-close" label
if (!pr.labels.some(l => l.name === label)) continue;
// Get the PR's label event timeline
const events = await github.paginate(github.rest.issues.listEvents, {
owner,
repo,
issue_number: pr.number
});
// Find the label added event
const labelEvent = events.find(e => e.event === "labeled" && e.label.name === label);
const timeSinceLabeled = Math.floor((now - new Date(labelEvent.created_at)) / millisecondsInADay);
// If label added event found and is older than autoCloseDays days, close the PR
if (labelEvent && timeSinceLabeled >= autoCloseDays) {
console.log(`Closing PR #${pr.number}`);
// Close the PR
await github.rest.pulls.update({
owner,
repo,
pull_number: pr.number,
state: "closed"
});
const commentBody =
"# Automatic PR Closure Notice\n" +
"## Information\n" +
"This PR has been closed automatically. It was marked with the `auto-close` [label](https://github.com/oneapi-src/unified-runtime/labels/auto-close) 30 days ago as part of the Unified Runtime source code migration to the intel/llvm repository - https://github.com/intel/llvm/pull/17043.\n\n" +
"All Unified Runtime development should be done in [intel/llvm](https://github.com/intel/llvm/tree/sycl/unified-runtime), details can be found in the updated [contribution guide](https://oneapi-src.github.io/unified-runtime/core/CONTRIB.html).\n" +
"This repository will continue to exist as a mirror and will host the [specification documentation](https://oneapi-src.github.io/unified-runtime/).\n\n" +
"## Next Steps\n" +
"Should you wish to re-open this PR it **must be moved** to [intel/llvm](https://github.com/intel/llvm/tree/sycl/unified-runtime). We have provided a [script to help automate this process](https://github.com/oneapi-src/unified-runtime/blob/main/scripts/move-pr-to-intel-llvm.py), otherwise no actions are required.\n\n" +
"---\n" +
"*This is an automated comment.*";
// Comment on the PR
await github.rest.issues.createComment({
owner,
repo,
issue_number: pr.number,
body: commentBody
});
}
}