Skip to content

Commit 8d8076b

Browse files
authored
Merge pull request #2726 from martygrant/martin/re-add-migration-workflows
Re-add migration workflows, both to run on schedule
2 parents 5cbfc12 + 54ceee6 commit 8d8076b

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Auto-Close PRs
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # Runs daily at midnight (UTC)
6+
workflow_dispatch: # Allows manual triggering
7+
8+
permissions:
9+
pull-requests: write
10+
issues: write
11+
12+
jobs:
13+
close-stale-prs:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Close PRs labeled "auto-close"
17+
uses: actions/github-script@v6
18+
with:
19+
github-token: ${{ secrets.GITHUB_TOKEN }}
20+
script: |
21+
const { owner, repo } = context.repo;
22+
const label = "auto-close";
23+
const now = new Date();
24+
const millisecondsInADay = 24 * 60 * 60 * 1000;
25+
const autoCloseDays = 30; // how many days before PRs should be closed automatically
26+
27+
// Fetch all open PRs
28+
const prs = await github.paginate(github.rest.pulls.list, {
29+
owner,
30+
repo,
31+
state: "open",
32+
per_page: 100
33+
});
34+
35+
for (const pr of prs) {
36+
// Check if PR has the "auto-close" label
37+
if (!pr.labels.some(l => l.name === label)) continue;
38+
39+
// Get the PR's label event timeline
40+
const events = await github.paginate(github.rest.issues.listEvents, {
41+
owner,
42+
repo,
43+
issue_number: pr.number
44+
});
45+
46+
// Find the label added event
47+
const labelEvent = events.find(e => e.event === "labeled" && e.label.name === label);
48+
49+
const timeSinceLabeled = Math.floor((now - new Date(labelEvent.created_at)) / millisecondsInADay);
50+
51+
// If label added event found and is older than autoCloseDays days, close the PR
52+
if (labelEvent && timeSinceLabeled >= autoCloseDays) {
53+
console.log(`Closing PR #${pr.number}`);
54+
55+
// Close the PR
56+
await github.rest.pulls.update({
57+
owner,
58+
repo,
59+
pull_number: pr.number,
60+
state: "closed"
61+
});
62+
63+
const commentBody =
64+
"# Automatic PR Closure Notice\n" +
65+
"## Information\n" +
66+
"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" +
67+
"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" +
68+
"This repository will continue to exist as a mirror and will host the [specification documentation](https://oneapi-src.github.io/unified-runtime/).\n\n" +
69+
"## Next Steps\n" +
70+
"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" +
71+
"---\n" +
72+
"*This is an automated comment.*";
73+
74+
// Comment on the PR
75+
await github.rest.issues.createComment({
76+
owner,
77+
repo,
78+
issue_number: pr.number,
79+
body: commentBody
80+
});
81+
}
82+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Warn about intel/llvm migration
2+
3+
on:
4+
schedule:
5+
- cron: '0 * * * *' # Runs hourly
6+
workflow_dispatch: # Allows manual triggering
7+
8+
permissions:
9+
pull-requests: write
10+
issues: write
11+
12+
jobs:
13+
label-and-comment:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Label and comment on open PRs
17+
uses: actions/github-script@v6
18+
with:
19+
github-token: ${{ secrets.GITHUB_TOKEN }}
20+
script: |
21+
const { owner, repo } = context.repo;
22+
const label = "auto-close";
23+
24+
// Fetch all open PRs
25+
const open_pulls = await github.paginate(
26+
github.rest.pulls.list,
27+
{ owner, repo, state: "open" }
28+
);
29+
30+
for (const pr of open_pulls) {
31+
const pr_number = pr.number;
32+
33+
// Get current labels on the PR
34+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
35+
owner,
36+
repo,
37+
issue_number: pr_number
38+
});
39+
40+
// Check if label is already present
41+
if (!labels.some(labelObj => labelObj.name === label)) {
42+
// Add the label if not present
43+
await github.rest.issues.addLabels({
44+
owner,
45+
repo,
46+
issue_number: pr_number,
47+
labels: [label]
48+
});
49+
50+
const commentBody =
51+
"# Unified Runtime -> intel/llvm Repo Move Notice\n" +
52+
"## Information\n" +
53+
"The source code of Unified Runtime has been moved to [intel/llvm](https://github.com/intel/llvm) under the [unified-runtime](https://github.com/intel/llvm/tree/sycl/unified-runtime) top-level directory,\n" +
54+
"all future development will now be carried out there. This was done in https://github.com/intel/llvm/pull/17043.\n\n" +
55+
"The code will be mirrored to [oneapi-src/unified-runtime](https://github.com/oneapi-src/unified-runtime) and the specification will continue to be hosted at [oneapi-src.github.io/unified-runtime](https://oneapi-src.github.io/unified-runtime/).\n\n" +
56+
"The [contribution guide](https://oneapi-src.github.io/unified-runtime/core/CONTRIB.html) will be updated with new instructions for contributing to Unified Runtime.\n\n" +
57+
"## PR Migration\n" +
58+
"All open PRs including this one will be marked with the `auto-close` [label](https://github.com/oneapi-src/unified-runtime/labels/auto-close) and shall be **automatically closed after 30 days**.\n\n" +
59+
"Should you wish to continue with your PR **you will need to migrate it** to [intel/llvm](https://github.com/intel/llvm/tree/sycl/unified-runtime).\n" +
60+
"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).\n\n" +
61+
"If your PR should remain open and not be closed automatically, you can remove the `auto-close` label.\n\n" +
62+
"---\n" +
63+
"*This is an automated comment.*";
64+
65+
// Add a comment about the migration process
66+
await github.rest.issues.createComment({
67+
owner,
68+
repo,
69+
issue_number: pr_number,
70+
body: commentBody
71+
});
72+
73+
console.log(`Added label '${label}' and commented on PR #${pr_number}`);
74+
} else {
75+
console.log(`PR #${pr_number} already has the '${label}' label. Skipping.`);
76+
}
77+
}

0 commit comments

Comments
 (0)