Skip to content

Commit 76c0328

Browse files
Add Sub-Issue Closer workflow
- New workflow that automatically closes parent issues when all sub-issues are completed - Runs daily to keep issue tracker organized - Simple, general-purpose, and works with any repo using GitHub Issues - Source: https://github.com/github/gh-aw/blob/main/.github/workflows/sub-issue-closer.md - Perfect operational track record in gh-aw repository
1 parent 138f589 commit 76c0328

3 files changed

Lines changed: 246 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ A sample family of reusable [GitHub Agentic Workflows](https://github.github.com
44

55
## 📂 Available Workflows
66

7-
### Triage Workflows
7+
### Triage & Issue Management Workflows
88

99
- [🏷️ Issue Triage](docs/issue-triage.md) - Triage issues and pull requests
10+
- [🔒 Sub-Issue Closer](docs/sub-issue-closer.md) - Automatically close parent issues when all sub-issues are completed
1011

1112
## Fault Analysis Workflows
1213

docs/sub-issue-closer.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Sub-Issue Closer
2+
3+
**Automatically closes parent issues when all their sub-issues are completed**
4+
5+
## Overview
6+
7+
The Sub-Issue Closer is an automated workflow that maintains a clean and organized issue tracker by automatically closing parent issues when all of their sub-issues have been completed. It runs daily and processes the issue hierarchy recursively, ensuring that parent issues up the tree are also closed as their sub-issues complete.
8+
9+
## How It Works
10+
11+
1. **Scans for Parent Issues**: The workflow searches for open issues that have sub-issues (tracked issues)
12+
2. **Checks Completion Status**: For each parent issue, it verifies that ALL sub-issues are closed
13+
3. **Closes Completed Parents**: When a parent issue has 100% of its sub-issues closed, it automatically closes the parent
14+
4. **Processes Recursively**: After closing a parent, it checks if that parent is itself a sub-issue of another parent, and repeats the process up the tree
15+
5. **Adds Transparency**: Each closure includes an explanatory comment showing the sub-issue completion status
16+
17+
## Why This Is Valuable
18+
19+
- **Keeps Issue Tracker Clean**: Automatically closes parent issues that are implicitly complete
20+
- **Saves Manual Work**: Eliminates the need to manually track and close parent issues
21+
- **Provides Clarity**: Team members can see at a glance which initiatives are fully complete
22+
- **Recursive Processing**: Handles nested issue hierarchies automatically
23+
- **Conservative Approach**: Only closes when absolutely certain all sub-issues are done
24+
25+
## When It Runs
26+
27+
- **Daily**: Automatically runs once per day on a fuzzy schedule
28+
- **On-Demand**: Can be manually triggered via workflow_dispatch
29+
30+
## Example Scenario
31+
32+
Imagine you have a parent issue tracking a new feature with 5 sub-issues:
33+
34+
``````
35+
Issue #100: "Feature: Add User Profile"
36+
├── #101: "Design profile page" [CLOSED]
37+
├── #102: "Implement backend API" [CLOSED]
38+
├── #103: "Create frontend UI" [CLOSED]
39+
├── #104: "Write tests" [CLOSED]
40+
└── #105: "Update documentation" [CLOSED]
41+
``````
42+
43+
When the last sub-issue (#105) is closed, the next time Sub-Issue Closer runs, it will:
44+
1. Detect that issue #100 has all 5 sub-issues closed (100%)
45+
2. Automatically close issue #100
46+
3. Add a comment: "🎉 Automatically closed by Sub-Issue Closer - All sub-issues completed (5/5)"
47+
4. Check if #100 is itself a sub-issue of a higher-level parent and repeat
48+
49+
## Configuration
50+
51+
The workflow is configured with conservative limits:
52+
- **Maximum 20 issues closed per run**: Prevents accidental mass closures
53+
- **Maximum 20 comments added per run**: Respects API rate limits
54+
- **Daily schedule**: Provides regular cleanup without overwhelming noise
55+
- **Read-only GitHub permissions**: Cannot modify code, only issue status
56+
57+
## Best Practices
58+
59+
- **Use Sub-Issues**: Create parent issues with sub-issues to track multi-part work
60+
- **Keep Sub-Issues Updated**: Close sub-issues promptly when completed
61+
- **Trust the Automation**: The workflow is conservative and only closes when 100% certain
62+
- **Review Closure Comments**: Each automated closure includes a transparent explanation
63+
64+
## What Makes This Workflow Special
65+
66+
- **Simple and Focused**: Does one thing well - closes completed parent issues
67+
- **Language-Agnostic**: Works with any repository that uses GitHub Issues
68+
- **Zero Configuration**: Works out-of-the-box with standard GitHub issue tracking
69+
- **Recursive Logic**: Handles complex nested issue hierarchies automatically
70+
- **Transparent Operation**: Every action is logged and explained in comments
71+
72+
## Merge Rate
73+
74+
While this workflow doesn't create pull requests (it manages issues directly), its sister workflow in the gh-aw repository has been deployed successfully and operates automatically without intervention, demonstrating its reliability and effectiveness in production use.
75+
76+
## Adding to Your Repository
77+
78+
``````bash
79+
gh aw add workflows/sub-issue-closer.md
80+
gh aw compile
81+
``````
82+
83+
Then commit and push the compiled workflow to your repository.
84+
85+
## Related Workflows
86+
87+
- [Issue Triage](issue-triage.md) - Automatically labels and organizes new issues
88+
- [Daily Plan](daily-plan.md) - Creates and updates planning issues with sub-tasks
89+
90+
## Learn More
91+
92+
- [GitHub Issues Documentation](https://docs.github.com/en/issues)
93+
- [Sub-Issues and Task Lists](https://docs.github.com/en/issues/tracking-your-work-with-issues/about-task-lists)
94+
- [GitHub Agentic Workflows](https://github.github.io/gh-aw/)

workflows/sub-issue-closer.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
---
2+
description: Scheduled workflow that recursively closes parent issues when all sub-issues are 100% complete
3+
name: Sub-Issue Closer
4+
on:
5+
schedule: daily
6+
workflow_dispatch:
7+
permissions:
8+
contents: read
9+
issues: read
10+
engine: copilot
11+
strict: true
12+
network:
13+
allowed:
14+
- defaults
15+
tools:
16+
github:
17+
toolsets:
18+
- issues
19+
safe-outputs:
20+
update-issue:
21+
status:
22+
target: "*"
23+
max: 20
24+
add-comment:
25+
target: "*"
26+
max: 20
27+
timeout-minutes: 15
28+
---
29+
30+
# Sub-Issue Closer 🔒
31+
32+
You are an intelligent agent that automatically closes parent issues when all their sub-issues are 100% complete.
33+
34+
## Task
35+
36+
Recursively process GitHub issues in repository **${{ github.repository }}** and close parent issues that have all their sub-issues completed.
37+
38+
## Process
39+
40+
### Step 1: Find Open Parent Issues
41+
42+
Use the GitHub MCP server to search for open issues that have sub-issues. Look for:
43+
- Issues with state = "OPEN"
44+
- Issues that have tracked issues (sub-issues)
45+
- Issues that appear to be tracking/parent issues based on their structure
46+
47+
You can use the `search_issues` tool to find issues with sub-issues, or use `list_issues` to get all open issues and filter those with sub-issues.
48+
49+
### Step 2: Check Sub-Issue Completion
50+
51+
For each parent issue found, check the completion status of its sub-issues:
52+
53+
1. Get the sub-issues for the parent issue using the GitHub API
54+
2. Check if ALL sub-issues are in state "CLOSED"
55+
3. Calculate the completion percentage
56+
57+
**Completion Criteria:**
58+
- A parent issue is considered "100% complete" when ALL of its sub-issues are closed
59+
- If even one sub-issue is still open, the parent should remain open
60+
- Empty parent issues (no sub-issues) should be skipped
61+
62+
### Step 3: Recursive Processing
63+
64+
After closing a parent issue:
65+
1. Check if that issue itself is a sub-issue of another parent
66+
2. If it has a parent issue, check that parent's completion status
67+
3. Recursively close parent issues up the tree as they reach 100% completion
68+
69+
**Important:** Process the tree bottom-up to ensure sub-issues are evaluated before their parents.
70+
71+
### Step 4: Close Completed Parent Issues
72+
73+
For each parent issue that is 100% complete:
74+
75+
1. **Close the issue** using the `update_issue` safe output:
76+
``````json
77+
{"type": "update_issue", "issue_number": 123, "state": "closed", "state_reason": "completed"}
78+
``````
79+
80+
2. **Add a comment** explaining the closure using the `add_comment` safe output:
81+
``````json
82+
{"type": "add_comment", "issue_number": 123, "body": "🎉 **Automatically closed by Sub-Issue Closer**\n\nAll sub-issues have been completed. This parent issue is now closed automatically.\n\n**Sub-issues status:** X/X closed (100%)"}
83+
``````
84+
85+
### Step 5: Report Summary
86+
87+
At the end of processing, provide a summary of:
88+
- Total parent issues analyzed
89+
- Issues closed in this run
90+
- Issues that remain open (with reason: incomplete sub-issues)
91+
- Any errors or issues that couldn't be processed
92+
93+
## Constraints
94+
95+
- Maximum 20 issues closed per run (configured in safe-outputs)
96+
- Maximum 20 comments added per run
97+
- Only close issues when you are ABSOLUTELY certain all sub-issues are closed
98+
- Skip issues that don't have sub-issues
99+
- Only process open parent issues
100+
- Be conservative: when in doubt, don't close
101+
102+
## Example Output Format
103+
104+
During processing, maintain clear logging:
105+
106+
``````
107+
🔍 Analyzing parent issues...
108+
109+
📋 Issue #42: "Feature: Add dark mode"
110+
State: OPEN
111+
Sub-issues: 5 total
112+
- #43: "Design dark mode colors" [CLOSED]
113+
- #44: "Implement dark mode toggle" [CLOSED]
114+
- #45: "Add dark mode to settings" [CLOSED]
115+
- #46: "Test dark mode" [CLOSED]
116+
- #47: "Document dark mode" [CLOSED]
117+
Status: 5/5 closed (100%)
118+
✅ All sub-issues complete - CLOSING
119+
120+
📋 Issue #50: "Feature: User authentication"
121+
State: OPEN
122+
Sub-issues: 3 total
123+
- #51: "Add login page" [CLOSED]
124+
- #52: "Add logout functionality" [OPEN]
125+
- #53: "Add password reset" [CLOSED]
126+
Status: 2/3 closed (67%)
127+
⏸️ Incomplete - keeping open
128+
129+
✅ Summary:
130+
- Parent issues analyzed: 2
131+
- Issues closed: 1
132+
- Issues remaining open: 1
133+
``````
134+
135+
## Important Notes
136+
137+
- This is a scheduled workflow that runs daily
138+
- It catches any parent issues that should be closed but were missed by event-triggered workflows
139+
- Use the GitHub MCP server tools to query issues and their relationships
140+
- Be careful with recursive processing to avoid infinite loops
141+
- Always verify the completion status before closing an issue
142+
- Add clear, informative comments when closing issues for transparency
143+
144+
## Guidelines
145+
146+
- **Be Conservative**: Only close when absolutely certain all sub-issues are closed
147+
- **Be Transparent**: Always add a comment explaining why the issue was closed
148+
- **Be Efficient**: Process issues in batches to respect API rate limits
149+
- **Be Recursive**: Check parent issues up the tree after closing
150+
- **Be Informative**: Provide clear summaries of actions taken

0 commit comments

Comments
 (0)