Skip to content

Tool Bug Fixes and Updates - #13

Merged
skoonin merged 5 commits into
mainfrom
feature/sync-sk-tools-fixes
Mar 31, 2026
Merged

skoonin merged 5 commits into
mainfrom
feature/sync-sk-tools-fixes

Conversation

@skoonin

@skoonin skoonin commented Mar 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

Syncs bug fixes and improvements

Changes

Security Fixes

  • ec2-state: Converted all shell=True subprocess calls to list-form (shell=False), fixed unused ThreadPoolExecutor, added None response filtering
  • github-delete-pr-comments: Reverted to original (different codebase from sk-tools)

Bug Fixes

  • git-cleanup: 3-phase squash merge detection (--merged, git cherry, gh API), conflict pre-check, cached _repo_name() with lru_cache, phase-aware -d/-D deletion
  • sort-yaml-key: Fixed dict-rooted YAML silently losing wrapper keys on output
  • asm: Fixed empty string treated as falsy in handle_update
  • git-audit: Fixed UnboundLocalError when using --sha or --file flags
  • testpod: Errors now print to stderr
  • gh-search: Safe .get() access for API responses, dead debug_token removed

Improvements

  • tfplan-all: fnmatch.translate() for proper glob-to-regex conversion
  • ec2-search: Fixed shebang, removed dead functions, restructured main()
  • README: Updated tool descriptions

Testing

  • All Python scripts pass syntax check (py_compile)
  • Pre-commit hooks pass (ruff, shellcheck, formatting)

Updated: asm, ec2-search, ec2-state, gh-search, git-audit, git-cleanup,
sort-yaml-key, testpod, tfplan-all, README.
Key fixes: ec2-state shell injection + ThreadPoolExecutor cleanup,
git-cleanup squash merge detection, sort-yaml-key dict data loss,
stderr for errors, type hint modernization.
Reverted: github-delete-pr-comments (different codebase, not a direct sync).
@skoonin skoonin changed the title Sync tool fixes from sk-tools Tool Bug Fixes and Updates Mar 19, 2026
@skoonin
skoonin requested a review from Copilot March 19, 2026 23:56

Copilot AI left a comment

Copy link
Copy Markdown

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 synchronizes a set of fixes and improvements across multiple standalone CLI tools in this repository, largely focusing on safer subprocess usage, more accurate filtering/matching behavior, and improved CLI ergonomics/output handling.

Changes:

  • Improve CLI robustness/UX by routing errors to stderr and refining usage/help text across tools.
  • Refactor/extend tooling logic (e.g., git-cleanup branch cleanup phases, tfplan-all glob handling, sort-yaml-key dict-rooted YAML output).
  • Update documentation descriptions in README.md to reflect current tool behaviors.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 12 comments.

Show a summary per file
File Description
tfplan-all/tfplan-all Adds fnmatch.translate() glob conversion and moves error messages to stderr; updates help text.
testpod/testpod Prints kubectl deployment/deletion errors to stderr.
sort-yaml-key/sort-yaml-key Refactors YAML sorting to preserve dict-root wrappers and key ordering via OrderedDict representer.
git-cleanup/git-cleanup Adds repo-prefixed logging, -C/path support, branch preservation, and enhanced merged-branch/run cleanup flows.
git-audit/git-audit Adds stderr error printing, extends output fields, and adjusts argument parsing / examples.
gh-search/gh-search Reworks token sourcing and adds repo-name search; refactors cloning/editor opening behavior.
ec2-state/ec2-state Removes shell=True patterns, improves JSON handling, and filters None responses in region-specified mode.
ec2-search/ec2-search Restructures main flow and concurrency; revises argument help and output behavior.
asm/asm Minor help-text alignment change.
README.md Updates tool descriptions to match current capabilities and wording.
Comments suppressed due to low confidence (1)

tfplan-all/tfplan-all:252

  • fnmatch.translate() produces an anchored regex (typically ending in \Z). Using regex.search(...) effectively allows matches to start at any offset, which doesn’t behave like a true glob match (e.g., prod* can match the tail of foo/prod-bar). If you intend glob semantics, switch to regex.match(...)/fullmatch(...) when using translated patterns (or explicitly anchor the regex yourself).
    if args.filter_pattern:
        pattern = args.filter_pattern
        # Convert glob-style wildcards to regex
        if any(c in pattern for c in "*?[") and not pattern.startswith("^"):
            pattern = fnmatch.translate(pattern)
        try:
            regex = re.compile(pattern)
        except re.error as e:
            print(f"{RED}Error: Invalid filter pattern: {e}{RESET}", file=sys.stderr)
            sys.exit(1)

        tf_dirs = [d for d in tf_dirs if regex.search(str(d.relative_to(target_dir)))]


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

Comment thread sort-yaml-key/sort-yaml-key Outdated
Comment on lines +72 to +73
# Dump the sorted data
sorted_yaml = yaml.dump(loaded, default_flow_style=False)

Copilot AI Mar 20, 2026

Copy link

Choose a reason for hiding this comment

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

yaml.dump(loaded, ...) uses sort_keys=True by default, which can reorder keys in the root mapping (the wrapper you’re trying to preserve). Pass sort_keys=False (and consider safe_dump with a representer registered on SafeDumper) to keep the original mapping key order stable.

Suggested change
# Dump the sorted data
sorted_yaml = yaml.dump(loaded, default_flow_style=False)
# Dump the sorted data without reordering mapping keys
sorted_yaml = yaml.dump(loaded, default_flow_style=False, sort_keys=False)

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in 3140648. Added sort_keys=False to yaml.dump() to preserve OrderedDict key ordering.

Comment thread ec2-search/ec2-search Outdated
Comment thread git-audit/git-audit
Comment thread gh-search/gh-search Outdated
Comment thread gh-search/gh-search
Comment thread gh-search/gh-search Outdated
Comment thread gh-search/gh-search Outdated
Comment thread ec2-search/ec2-search
Comment thread tfplan-all/tfplan-all Outdated
Comment thread sort-yaml-key/sort-yaml-key Outdated
sort-yaml-key: add sort_keys=False, error handling, main guard
gh-search: URL-encode search query, add timeouts, fix clone/vscode error handling
ec2-search: fix mutable default arg, epilog script name, add subprocess timeouts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 8 comments.


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

Comment thread tfplan-all/tfplan-all Outdated
Comment thread sort-yaml-key/sort-yaml-key
Comment thread gh-search/gh-search
Comment thread gh-search/gh-search Outdated
Comment thread ec2-search/ec2-search Outdated
Comment thread asm/asm Outdated
Comment thread gh-search/gh-search
Comment thread git-cleanup/git-cleanup
skoonin added 3 commits March 31, 2026 11:02
Branches created from base with no work were flagged as merged by
git branch --merged and git cherry (empty output). Partition --merged
candidates by remote tracking ref: branches with upstream go to
safe_merged, branches without require GH API PR verification.
git branch --merged also falsely flags pushed branches without PRs.
Demote it to deletion-flag selection only. Use git cherry (with output
guard) and GH API merged PRs as the sole sources of merge evidence.
SafeDumper for sort-yaml-key, error context in ec2-search futures, wasted API call in gh-search, Popen returncode check in testpod, file handle leak fix, dead code removal, docstring and help text corrections
@skoonin
skoonin merged commit 078c455 into main Mar 31, 2026
3 checks passed
@skoonin
skoonin deleted the feature/sync-sk-tools-fixes branch March 31, 2026 23:23
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.

2 participants