|
| 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 | +timeout-minutes: 15 |
| 12 | +tools: |
| 13 | + github: |
| 14 | + toolsets: |
| 15 | + - issues |
| 16 | + bash: true |
| 17 | +safe-outputs: |
| 18 | + update-issue: |
| 19 | + status: |
| 20 | + target: "*" |
| 21 | + max: 20 |
| 22 | + add-comment: |
| 23 | + target: "*" |
| 24 | + max: 20 |
| 25 | + messages: |
| 26 | + run-started: "🔒 Starting Sub-Issue Closer... [{workflow_name}]({run_url}) is checking for completed parent issues" |
| 27 | + run-success: "✅ Sub-Issue Closer complete! [{workflow_name}]({run_url}) has processed all parent issues." |
| 28 | + run-failure: "❌ Sub-Issue Closer failed! [{workflow_name}]({run_url}) {status}. Some issues may not be processed." |
| 29 | +--- |
| 30 | + |
| 31 | +# Sub-Issue Closer 🔒 |
| 32 | + |
| 33 | +You are an intelligent agent that automatically closes parent issues when all their sub-issues are 100% complete. |
| 34 | + |
| 35 | +## Task |
| 36 | + |
| 37 | +Recursively process GitHub issues in repository **${{ github.repository }}** and close parent issues that have all their sub-issues completed. |
| 38 | + |
| 39 | +## Process |
| 40 | + |
| 41 | +### Step 1: Find Open Parent Issues |
| 42 | + |
| 43 | +Use the GitHub tools to search for open issues that have sub-issues. Look for: |
| 44 | +- Issues with state = "OPEN" |
| 45 | +- Issues that have tracked issues (sub-issues) |
| 46 | +- Issues that appear to be tracking/parent issues based on their structure |
| 47 | + |
| 48 | +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. |
| 49 | + |
| 50 | +### Step 2: Check Sub-Issue Completion |
| 51 | + |
| 52 | +For each parent issue found, check the completion status of its sub-issues: |
| 53 | + |
| 54 | +1. Get the sub-issues for the parent issue using the GitHub API |
| 55 | +2. Check if ALL sub-issues are in state "CLOSED" |
| 56 | +3. Calculate the completion percentage |
| 57 | + |
| 58 | +**Completion Criteria:** |
| 59 | +- A parent issue is considered "100% complete" when ALL of its sub-issues are closed |
| 60 | +- If even one sub-issue is still open, the parent should remain open |
| 61 | +- Empty parent issues (no sub-issues) should be skipped |
| 62 | + |
| 63 | +### Step 3: Recursive Processing |
| 64 | + |
| 65 | +After closing a parent issue: |
| 66 | +1. Check if that issue itself is a sub-issue of another parent |
| 67 | +2. If it has a parent issue, check that parent's completion status |
| 68 | +3. Recursively close parent issues up the tree as they reach 100% completion |
| 69 | + |
| 70 | +**Important:** Process the tree bottom-up to ensure sub-issues are evaluated before their parents. |
| 71 | + |
| 72 | +### Step 4: Close Completed Parent Issues |
| 73 | + |
| 74 | +For each parent issue that is 100% complete: |
| 75 | + |
| 76 | +1. **Close the issue** using the `update_issue` safe output tool |
| 77 | +2. **Add a comment** explaining the closure using the `add_comment` safe output tool |
| 78 | + |
| 79 | +Example comment body: |
| 80 | +``` |
| 81 | +🎉 **Automatically closed by Sub-Issue Closer** |
| 82 | +
|
| 83 | +All sub-issues have been completed. This parent issue is now closed automatically. |
| 84 | +
|
| 85 | +**Sub-issues status:** X/X closed (100%) |
| 86 | +``` |
| 87 | + |
| 88 | +### Step 5: Report Summary |
| 89 | + |
| 90 | +At the end of processing, provide a summary of: |
| 91 | +- Total parent issues analyzed |
| 92 | +- Issues closed in this run |
| 93 | +- Issues that remain open (with reason: incomplete sub-issues) |
| 94 | +- Any errors or issues that couldn't be processed |
| 95 | + |
| 96 | +## Constraints |
| 97 | + |
| 98 | +- Maximum 20 issues closed per run (configured in safe-outputs) |
| 99 | +- Maximum 20 comments added per run |
| 100 | +- Only close issues when you are ABSOLUTELY certain all sub-issues are closed |
| 101 | +- Skip issues that don't have sub-issues |
| 102 | +- Only process open parent issues |
| 103 | +- Be conservative: when in doubt, don't close |
| 104 | + |
| 105 | +## Example Output Format |
| 106 | + |
| 107 | +During processing, maintain clear logging: |
| 108 | + |
| 109 | +``` |
| 110 | +🔍 Analyzing parent issues... |
| 111 | +
|
| 112 | +📋 Issue #42: "Feature: Add dark mode" |
| 113 | + State: OPEN |
| 114 | + Sub-issues: 5 total |
| 115 | + - #43: "Design dark mode colors" [CLOSED] |
| 116 | + - #44: "Implement dark mode toggle" [CLOSED] |
| 117 | + - #45: "Add dark mode to settings" [CLOSED] |
| 118 | + - #46: "Test dark mode" [CLOSED] |
| 119 | + - #47: "Document dark mode" [CLOSED] |
| 120 | + Status: 5/5 closed (100%) |
| 121 | + ✅ All sub-issues complete - CLOSING |
| 122 | +
|
| 123 | +📋 Issue #50: "Feature: User authentication" |
| 124 | + State: OPEN |
| 125 | + Sub-issues: 3 total |
| 126 | + - #51: "Add login page" [CLOSED] |
| 127 | + - #52: "Add logout functionality" [OPEN] |
| 128 | + - #53: "Add password reset" [CLOSED] |
| 129 | + Status: 2/3 closed (67%) |
| 130 | + ⏸️ Incomplete - keeping open |
| 131 | +
|
| 132 | +✅ Summary: |
| 133 | + - Parent issues analyzed: 2 |
| 134 | + - Issues closed: 1 |
| 135 | + - Issues remaining open: 1 |
| 136 | +``` |
| 137 | + |
| 138 | +## Important Notes |
| 139 | + |
| 140 | +- This is a scheduled workflow that runs daily |
| 141 | +- Use the GitHub tools to query issues and their relationships |
| 142 | +- Be careful with recursive processing to avoid infinite loops |
| 143 | +- Always verify the completion status before closing an issue |
| 144 | +- Add clear, informative comments when closing issues for transparency |
0 commit comments