-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
chore(triage-skill): Add GitHub parsing python util script #19405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+89
−4
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| """ | ||
| Parse GitHub API JSON (single issue or search/issues) and print a concise summary. | ||
| Reads from stdin if no argument, else from the file path given as first argument. | ||
| Used by the triage-issue skill in CI so the AI does not need inline python3 -c in Bash. | ||
| """ | ||
| import json | ||
| import sys | ||
|
|
||
|
|
||
| def _sanitize_title(title: str) -> str: | ||
| """One line, no leading/trailing whitespace, newlines replaced with space.""" | ||
| if not title: | ||
| return "" | ||
| return " ".join(str(title).split()) | ||
|
|
||
|
|
||
| def _format_single_issue(data: dict) -> None: | ||
| num = data.get("number") | ||
| title = _sanitize_title(data.get("title", "")) | ||
| state = data.get("state", "") | ||
| print(f"#{num} {state} {title}") | ||
| labels = data.get("labels", []) | ||
| if labels: | ||
| names = [l.get("name", "") for l in labels if isinstance(l, dict)] | ||
| print(f"Labels: {', '.join(names)}") | ||
| body = data.get("body") or "" | ||
| if body: | ||
| snippet = body[:200].replace("\n", " ") | ||
| if len(body) > 200: | ||
| snippet += "..." | ||
| print(f"Body: {snippet}") | ||
|
|
||
|
|
||
| def _format_search_items(data: dict) -> None: | ||
| items = data.get("items", []) | ||
| for i in items: | ||
| if not isinstance(i, dict): | ||
| continue | ||
| num = i.get("number", "") | ||
| title = _sanitize_title(i.get("title", "")) | ||
| state = i.get("state", "") | ||
| print(f"{num} {title} {state}") | ||
|
|
||
|
|
||
| def main() -> None: | ||
| if len(sys.argv) > 1: | ||
| path = sys.argv[1] | ||
| try: | ||
| with open(path, encoding="utf-8") as f: | ||
| data = json.load(f) | ||
| except (OSError, json.JSONDecodeError) as e: | ||
| print(f"parse_gh_issues: {e}", file=sys.stderr) | ||
| sys.exit(1) | ||
| else: | ||
| try: | ||
| data = json.load(sys.stdin) | ||
| except json.JSONDecodeError as e: | ||
| print(f"parse_gh_issues: {e}", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| if not isinstance(data, dict): | ||
| print("parse_gh_issues: expected a JSON object", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
| if "items" in data: | ||
| _format_search_items(data) | ||
| elif "number" in data: | ||
| _format_single_issue(data) | ||
| else: | ||
| print("parse_gh_issues: expected 'items' (search) or 'number' (single issue)", file=sys.stderr) | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent field ordering between output format functions
Low Severity
_format_single_issueoutputs fields as#{num} {state} {title}while_format_search_itemsoutputs{num} {title} {state}— the order ofstateandtitleis swapped between the two functions. The SKILL.md documentation describes the expected output as "issue number, title, and state," which matches the search format but contradicts the single-issue format. This inconsistency makes the output harder to parse reliably by the AI consumer.Additional Locations (1)
.claude/skills/triage-issue/scripts/parse_gh_issues.py#L41-L42