diff --git a/README.md b/README.md index 31df65f..2a2a879 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ You can use the "/plan" agent to turn the reports into actionable issues which c - [πŸ›‘οΈ AI Moderator](docs/ai-moderator.md) - Automatically detect and moderate spam, link spam, and AI-generated content - [πŸ” Contribution Check](docs/contribution-check.md) - Regularly review batches of open PRs against contribution guidelines and create prioritized reports - [πŸ€– Repo Assist](docs/repo-assist.md) - Daily repository assistant that triages issues, fixes bugs, proposes improvements, and maintains activity summaries +- [πŸ”’ Sub-Issue Closer](docs/sub-issue-closer.md) - Automatically close parent issues when all their sub-issues are complete ## Meta-Workflows diff --git a/docs/daily-malicious-code-scan.md b/docs/daily-malicious-code-scan.md index 3593824..52c1e16 100644 --- a/docs/daily-malicious-code-scan.md +++ b/docs/daily-malicious-code-scan.md @@ -2,8 +2,6 @@ > For an overview of all available workflows, see the [main README](../README.md). -**Automatically review recent code changes for suspicious patterns indicating malicious activity or security regressions** - The [Daily Malicious Code Scan workflow](../workflows/daily-malicious-code-scan.md?plain=1) examines files changed in the past 72 hours, searching for secret exfiltration, out-of-context code, suspicious network activity, system access patterns, obfuscation, and supply chain indicators. Findings appear as GitHub code-scanning alerts with threat scores and remediation recommendations. ## Installation diff --git a/docs/sub-issue-closer.md b/docs/sub-issue-closer.md new file mode 100644 index 0000000..c1ca1d3 --- /dev/null +++ b/docs/sub-issue-closer.md @@ -0,0 +1,113 @@ +# πŸ”’ Sub-Issue Closer + +> For an overview of all available workflows, see the [main README](../README.md). + +The [Sub-Issue Closer workflow](../workflows/sub-issue-closer.md?plain=1) automatically closes parent issues when all of their sub-issues have been completed, keeping your issue tracker clean and organized. + +## Installation + +```bash +# Install the 'gh aw' extension +gh extension install github/gh-aw + +# Add the workflow to your repository +gh aw add-wizard githubnext/agentics/sub-issue-closer +``` + +This walks you through adding the workflow to your repository. + +You can start a run of this workflow immediately by running: + +```bash +gh aw run sub-issue-closer +``` + +## What It Does + +The Sub-Issue Closer workflow runs daily and: + +1. **Scans Open Parent Issues** - Finds all open issues that have sub-issues (tracked issues) +2. **Checks Completion** - Verifies whether all sub-issues are in a closed state +3. **Closes Completed Parents** - Closes parent issues where every sub-issue is done +4. **Recurses Up the Tree** - If closing a parent reveals its own parent is now complete, that parent is closed too +5. **Adds Explanatory Comments** - Posts a comment on each closed issue explaining the automatic closure + +## How It Works + +````mermaid +graph LR + A[Find Open Parent Issues] --> B[Check Sub-Issue Status] + B --> C{All Sub-Issues Closed?} + C -->|Yes| D[Close Parent Issue] + D --> E[Add Closure Comment] + E --> F{Parent Has Its Own Parent?} + F -->|Yes| B + F -->|No| G[Done] + C -->|No| H[Skip - Keep Open] +```` + +### Recursive Closure + +The workflow processes issue trees bottom-up. If you have a hierarchy like: + +``` +Epic #1: "Launch v2.0" + β”œβ”€β”€ Feature #2: "User auth" (all sub-issues closed) + β”‚ β”œβ”€β”€ #3: "Login page" [CLOSED] + β”‚ └── #4: "Logout" [CLOSED] + └── Feature #5: "Dashboard" (sub-issue still open) + └── #6: "Chart widget" [OPEN] +``` + +The workflow would close Feature #2 (all sub-issues done), then check if Epic #1 can be closed too (it cannot, because Feature #5 is still open). + +## What It Reads from GitHub + +- Open issues and their sub-issue relationships +- Sub-issue states (open/closed) + +## What It Creates + +- Closes parent issues via the `update-issue` safe output +- Adds closure comments via the `add-comment` safe output + +## When It Runs + +- **Daily** (automatic fuzzy scheduling) +- **Manually** via workflow_dispatch + +## Permissions Required + +- `contents: read` - To read repository contents +- `issues: read` - To query issue and sub-issue status + +## Configuration + +The workflow works out of the box for any repository using GitHub's sub-issues feature. You can edit it to customize: +- Maximum issues closed per run (default: 20) +- The closure comment message +- Whether to process recursively up the tree + +After editing, run `gh aw compile` to apply your changes. + +## Benefits + +1. **Automatic housekeeping** - Issue trackers stay clean without manual intervention +2. **Works recursively** - Cascades up through multi-level issue hierarchies +3. **Transparent** - Always explains why an issue was closed with a comment +4. **Conservative** - Only closes when 100% of sub-issues are done; skips on any doubt +5. **Complements event-driven workflows** - Catches cases that may have been missed by real-time triggers + +## Example Output + +When the workflow closes a parent issue, it posts a comment like: + +> πŸŽ‰ **Automatically closed by Sub-Issue Closer** +> +> All sub-issues have been completed. This parent issue is now closed automatically. +> +> **Sub-issues status:** 4/4 closed (100%) + +## Source + +This workflow is adapted from Peli's Agent Factory. Read more: [Meet the Workflows: Organization](https://github.github.io/gh-aw/blog/2026-01-13-meet-the-workflows-organization/) diff --git a/workflows/sub-issue-closer.md b/workflows/sub-issue-closer.md new file mode 100644 index 0000000..803fc14 --- /dev/null +++ b/workflows/sub-issue-closer.md @@ -0,0 +1,142 @@ +--- +description: Scheduled workflow that recursively closes parent issues when all sub-issues are 100% complete +name: Sub-Issue Closer +on: + schedule: daily + workflow_dispatch: +permissions: + contents: read + issues: read +engine: copilot +strict: true +network: + allowed: + - defaults +tools: + github: + toolsets: + - issues +safe-outputs: + update-issue: + status: + target: "*" + max: 20 + add-comment: + target: "*" + max: 20 +timeout-minutes: 15 +--- + +# Sub-Issue Closer πŸ”’ + +You are an intelligent agent that automatically closes parent issues when all their sub-issues are 100% complete. + +## Task + +Recursively process GitHub issues in repository **${{ github.repository }}** and close parent issues that have all their sub-issues completed. + +## Process + +### Step 1: Find Open Parent Issues + +Use the GitHub MCP server to search for open issues that have sub-issues. Look for: +- Issues with state = "OPEN" +- Issues that have tracked issues (sub-issues) +- Issues that appear to be tracking/parent issues based on their structure + +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. + +### Step 2: Check Sub-Issue Completion + +For each parent issue found, check the completion status of its sub-issues: + +1. Get the sub-issues for the parent issue using the GitHub API +2. Check if ALL sub-issues are in state "CLOSED" +3. Calculate the completion percentage + +**Completion Criteria:** +- A parent issue is considered "100% complete" when ALL of its sub-issues are closed +- If even one sub-issue is still open, the parent should remain open +- Empty parent issues (no sub-issues) should be skipped + +### Step 3: Recursive Processing + +After closing a parent issue: +1. Check if that issue itself is a sub-issue of another parent +2. If it has a parent issue, check that parent's completion status +3. Recursively close parent issues up the tree as they reach 100% completion + +**Important:** Process the tree bottom-up to ensure sub-issues are evaluated before their parents. + +### Step 4: Close Completed Parent Issues + +For each parent issue that is 100% complete: + +1. **Close the issue** using the `update_issue` safe output: + ```json + {"type": "update_issue", "issue_number": 123, "state": "closed", "state_reason": "completed"} + ``` + +2. **Add a comment** explaining the closure using the `add_comment` safe output: + ```json + {"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%)"} + ``` + +### Step 5: Report Summary + +At the end of processing, provide a summary of: +- Total parent issues analyzed +- Issues closed in this run +- Issues that remain open (with reason: incomplete sub-issues) +- Any errors or issues that couldn't be processed + +## Constraints + +- Maximum 20 issues closed per run (configured in safe-outputs) +- Maximum 20 comments added per run +- Only close issues when you are ABSOLUTELY certain all sub-issues are closed +- Skip issues that don't have sub-issues +- Only process open parent issues +- Be conservative: when in doubt, don't close + +## Example Output Format + +During processing, maintain clear logging: + +``` +πŸ” Analyzing parent issues... + +πŸ“‹ Issue #42: "Feature: Add dark mode" + State: OPEN + Sub-issues: 5 total + - #43: "Design dark mode colors" [CLOSED] + - #44: "Implement dark mode toggle" [CLOSED] + - #45: "Add dark mode to settings" [CLOSED] + - #46: "Test dark mode" [CLOSED] + - #47: "Document dark mode" [CLOSED] + Status: 5/5 closed (100%) + βœ… All sub-issues complete - CLOSING + +πŸ“‹ Issue #50: "Feature: User authentication" + State: OPEN + Sub-issues: 3 total + - #51: "Add login page" [CLOSED] + - #52: "Add logout functionality" [OPEN] + - #53: "Add password reset" [CLOSED] + Status: 2/3 closed (67%) + ⏸️ Incomplete - keeping open + +βœ… Summary: + - Parent issues analyzed: 2 + - Issues closed: 1 + - Issues remaining open: 1 +``` + +## Important Notes + +- This is a scheduled workflow that runs daily +- It complements event-triggered auto-close workflows by catching cases that were missed +- Use the GitHub MCP server tools to query issues and their relationships +- Be careful with recursive processing to avoid infinite loops +- Always verify the completion status before closing an issue +- Add clear, informative comments when closing issues for transparency