Skip to content

🩹 fix: correctly parse gh sub-issue JSON output in prep-next.py#609

Merged
codekiln merged 2 commits intomainfrom
claude/608-prep-nextpy-incorrectly-parses-gh-sub-issue-json-output
Dec 5, 2025
Merged

🩹 fix: correctly parse gh sub-issue JSON output in prep-next.py#609
codekiln merged 2 commits intomainfrom
claude/608-prep-nextpy-incorrectly-parses-gh-sub-issue-json-output

Conversation

@codekiln
Copy link
Owner

@codekiln codekiln commented Dec 5, 2025

Summary

Fixes the scripts/gh-milestones/prep-next.py script crash when building issue hierarchy. The script was incorrectly parsing the JSON output from gh sub-issue list, which returns data in the format {"subIssues": [...]} rather than a direct array.

Changes

  • Fixed parent parsing (lines 214-219): Correctly extract subIssues wrapper from JSON response
  • Fixed children parsing (lines 231-235): Same fix for children relationship parsing
  • Improved error handling: Added TypeError to exception handling, use .get() for safe access
  • Graceful null handling: Check if parents_data/children_data is not None before accessing

Root Cause

The gh sub-issue list command returns:

{
  "subIssues": [
    {"number": 586}
  ]
}

But the code was trying to index directly:

parents = json.loads(result.stdout)
parent_num = parents[0]["number"]  # ❌ KeyError: 0

Fix

parents_data = json.loads(result.stdout)
sub_issues = parents_data.get("subIssues", []) if parents_data else []
if sub_issues and len(sub_issues) > 0:
    parent_num = sub_issues[0]["number"]

Testing

Verified the fix by running:

/gh-milestones:prep-next ls-projects

Result: ✅ Successfully completed without errors, correctly identified next issue #586

Related Issues

Fixes #608


🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

The gh sub-issue list command returns JSON in the format:
{"subIssues": [{"number": 586}]}

Previously, the script incorrectly tried to index directly into the JSON
response as if it were an array, causing KeyError: 0.

This fix:
- Correctly extracts the "subIssues" wrapper from JSON response
- Handles None/null cases gracefully with .get() and safe checks
- Adds TypeError to exception handling for robustness
- Applies fix to both parent and children relationship parsing

Fixes #608

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings December 5, 2025 17:22
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

Unit Test Results

169 tests  ±0   169 ✅ ±0   1s ⏱️ ±0s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 8f75ef2. ± Comparison against base commit 1267f70.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

Integration Test Results

275 tests  ±0   275 ✅ ±0   2m 31s ⏱️ -1s
 10 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 8f75ef2. ± Comparison against base commit 1267f70.

♻️ This comment has been updated with latest results.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a crash in the scripts/gh-milestones/prep-next.py script caused by incorrect JSON parsing. The script was attempting to directly index the JSON response from gh sub-issue list as an array, when it actually returns a wrapped object with a subIssues field.

Key Changes:

  • Corrects JSON parsing to extract the subIssues wrapper object instead of treating response as a direct array
  • Adds defensive null checks and improved error handling with TypeError and KeyError exceptions
  • Applies consistent fix to both parent and children relationship parsing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

…andling

- Rename sub_issues → parent_issues in parent parsing for clarity
- Rename sub_issues → child_issues in children parsing for clarity
- Remove redundant len() > 0 check (more Pythonic)
- Add explanatory comment to parent parsing except clause
- Add error logging to children parsing except clause

Addresses Copilot review comments in PR #609
@codekiln codekiln merged commit be859d2 into main Dec 5, 2025
21 checks passed
@codekiln codekiln deleted the claude/608-prep-nextpy-incorrectly-parses-gh-sub-issue-json-output branch December 5, 2025 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🩹 fix: prep-next.py incorrectly parses gh sub-issue JSON output

2 participants