Skip to content

Commit b0f8600

Browse files
authored
feat: add auto closing of issues / pull requests based on staleness (#1944)
<!-- This is an auto-generated description by cubic. --> ## Summary by cubic Added GitHub workflows to automatically close stale issues and pull requests with unresolved merge conflicts older than 3 days. - **Automation** - Closes open pull requests with merge conflicts after 3 days. - Closes issues immediately when marked as stale. <!-- End of auto-generated description by cubic. --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Introduced automated workflows to close old pull requests with unresolved merge conflicts and to close stale issues, helping keep the repository clean and up to date. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent cdb3d25 commit b0f8600

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Close Old Conflicted PRs
2+
3+
on:
4+
schedule:
5+
- cron: "0 * * * *"
6+
7+
jobs:
8+
close_conflicted_prs:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
pull-requests: write
12+
steps:
13+
- name: Close PRs with merge conflicts older than 3 days
14+
uses: actions/github-script@v7
15+
with:
16+
script: |
17+
const prs = await github.rest.pulls.list({
18+
owner: context.repo.owner,
19+
repo: context.repo.repo,
20+
state: 'open'
21+
});
22+
23+
const now = new Date();
24+
for (const pr of prs.data) {
25+
const details = await github.rest.pulls.get({
26+
owner: context.repo.owner,
27+
repo: context.repo.repo,
28+
pull_number: pr.number
29+
});
30+
31+
if (details.data.mergeable === false || details.data.mergeable === null) {
32+
const createdAt = new Date(pr.created_at);
33+
const diffDays = (now - createdAt) / (1000 * 60 * 60 * 24);
34+
if (diffDays > 3) {
35+
await github.rest.issues.createComment({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
issue_number: pr.number,
39+
body: "This PR has merge conflicts and has been open for more than 3 days. It will be automatically closed. Please resolve the conflicts and reopen the PR if you'd like to continue working on it."
40+
});
41+
42+
await github.rest.pulls.update({
43+
owner: context.repo.owner,
44+
repo: context.repo.repo,
45+
pull_number: pr.number,
46+
state: 'closed'
47+
});
48+
}
49+
}
50+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Close Stale Issues
2+
3+
on:
4+
schedule:
5+
- cron: "0 * * * *"
6+
7+
jobs:
8+
stale:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
issues: write
12+
contents: read
13+
steps:
14+
- uses: actions/stale@v9
15+
with:
16+
days-before-stale: 3
17+
days-before-close: 0
18+
only-issues: true
19+
stale-issue-label: "stale"
20+
stale-issue-message: "This issue is stale (3+ days) and will be closed."
21+
close-issue-message: "Closing stale issue."

0 commit comments

Comments
 (0)