Skip to content

Commit 8c0fdab

Browse files
rojiCopilot
andcommitted
Add issue-closed workflow and switch runners to ubuntu-slim
Add a GitHub Actions workflow that changes issues closed as 'completed' by external users (no write access) to 'not planned', since these are typically users closing their own issues without a fix. Also switch all lightweight workflows to ubuntu-slim runners. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 3445554 commit 8c0fdab

3 files changed

Lines changed: 69 additions & 2 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# When an external user (no write access) closes an issue as "completed",
2+
# change it to "not planned". This handles users closing their own issues
3+
# without anything actually being fixed.
4+
5+
name: Issue closed
6+
7+
on:
8+
issues:
9+
types: [closed]
10+
11+
permissions:
12+
issues: write
13+
14+
jobs:
15+
check-close:
16+
runs-on: ubuntu-slim
17+
steps:
18+
- name: Reclose as not planned if external user
19+
uses: actions/github-script@v8
20+
with:
21+
script: |
22+
const issue = context.payload.issue;
23+
const closer = context.actor;
24+
25+
// Only act on issues closed as "completed"
26+
if (issue.state_reason !== 'completed') {
27+
console.log(`Issue #${issue.number} closed as '${issue.state_reason}', skipping`);
28+
return;
29+
}
30+
31+
// Check if the closing user has write access
32+
let hasWriteAccess = false;
33+
try {
34+
const { data: permissions } = await github.rest.repos.getCollaboratorPermissionLevel({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
username: closer
38+
});
39+
40+
hasWriteAccess = ['admin', 'write'].includes(permissions.permission);
41+
console.log(`User ${closer} has permission level: ${permissions.permission}`);
42+
} catch (error) {
43+
if (error.status === 404) {
44+
console.log(`User ${closer} not found, treating as external`);
45+
} else {
46+
console.error('Error checking permissions:', error);
47+
return;
48+
}
49+
}
50+
51+
if (hasWriteAccess) {
52+
console.log(`User ${closer} has write access, skipping`);
53+
return;
54+
}
55+
56+
// Reclose as "not planned"
57+
console.log(`External user ${closer} closed issue #${issue.number} as completed, changing to not_planned`);
58+
59+
await github.rest.issues.update({
60+
owner: context.repo.owner,
61+
repo: context.repo.repo,
62+
issue_number: issue.number,
63+
state: 'closed',
64+
state_reason: 'not_planned'
65+
});
66+
67+
console.log(`Issue #${issue.number} updated to not_planned`);

.github/workflows/label-and-milestone-issues.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ permissions:
1919
jobs:
2020
label:
2121
if: github.event.pull_request.merged == true
22-
runs-on: ubuntu-latest
22+
runs-on: ubuntu-slim
2323
steps:
2424
- name: Label issues and update milestones
2525
uses: actions/github-script@v8

.github/workflows/validate-pr-target-branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ permissions:
1616

1717
jobs:
1818
validate:
19-
runs-on: ubuntu-latest
19+
runs-on: ubuntu-slim
2020
steps:
2121
- name: Check PR target branch and author permissions
2222
uses: actions/github-script@v8

0 commit comments

Comments
 (0)