Skip to content

Add git commands pr_branches, sync-contributions, release (v0.4.0)#3

Open
ionite34 wants to merge 9 commits intomainfrom
dev
Open

Add git commands pr_branches, sync-contributions, release (v0.4.0)#3
ionite34 wants to merge 9 commits intomainfrom
dev

Conversation

@ionite34
Copy link
Copy Markdown
Member

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the project version to 0.4.0 and introduces a significant refactoring of Git-related utilities, including moving the GitHub context to a separate module and adding support for cross-repository pull requests. New commands have been added to handle merging and pushing between private, fork, and public repositories. Review feedback identifies a bug in repository URL parsing where only the host is captured, a potential failure in branch creation due to unsanitized characters in branch names, and an improvement for retrieving repository names using the full_name property instead of manual URL manipulation.

if not match.group("branch"):
return None
if host := match.group("host"):
return RepoBranch(repo=host, branch=match.group("branch"))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The try_match_repo_branch function incorrectly returns only the hostname when a full repository URL is provided. This will cause subsequent git operations (like clone) to fail because they will receive just the domain (e.g., github.com) instead of the full repository path. Using the first capturing group of the regex will capture the entire repository portion of the string.

Suggested change
return RepoBranch(repo=host, branch=match.group("branch"))
return RepoBranch(repo=match.group(1), branch=match.group("branch"))

Comment thread src/stability_matrix_tools/git.py Outdated
source_sha = git.run_cmd("rev-parse", f"source/{source.branch}").strip()

# Create a merge branch in the target repo
merge_branch_name = f"merge-{source}-to-{target.branch}-{source_sha[:7]}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The merge_branch_name is constructed using the string representation of source, which can include characters that are invalid for Git branch names (such as : in SSH URLs). This will cause the git checkout -b command to fail. You should sanitize the branch name to ensure it only contains valid characters.

Suggested change
merge_branch_name = f"merge-{source}-to-{target.branch}-{source_sha[:7]}"
safe_source = str(source).replace(":", "-").replace("@", "-")
merge_branch_name = f"merge-{safe_source}-to-{target.branch}-{source_sha[:7]}"


def format_repo(repo: Repository | str) -> str:
if isinstance(repo, Repository):
return repo.url.removeprefix("https://github.com/")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

In PyGithub, Repository.url typically returns the API URL (e.g., https://api.github.com/repos/owner/repo). To consistently get the owner/repo string, it is recommended to use the full_name property instead of manually stripping the prefix from the URL.

Suggested change
return repo.url.removeprefix("https://github.com/")
return repo.full_name

Restructure and harden the PR-creation logic for merging branches. Introduces helper builders (_make_merge_branch_name, _make_pr_title, _make_pr_body) and splits same-repo vs cross-repo flows into _pr_merge_same_repo and _pr_merge_cross_repo. Adds no-op detection (GitHub compare for same-repo and merge-base --is-ancestor for cross-repo), improves branch naming for cross-repo merges (includes source slug), and uses html_url for PR links. pr_branches CLI now has an expanded docstring and dispatches to the appropriate implementation. Also imports CalledProcessError and updates GitProcess.run_cmd to return a str, remove shell=True, and correctly pass cwd to subprocess.check_output for safer command execution.
Introduce three new CLI flows and small PR helper tweaks:

- Add pr_fork_to_private command to create a PR merging fork/main into private/main via the cross-repo helper.
- Add release command that chains push_private_to_fork → pr_fork_to_public → push_tags_private_to_public with a single confirmation; the public PR is opened but not merged programmatically.
- Add sync_contributions command that chains merge_public_to_fork → pr_fork_to_private to stage inbound contributions.
- Update pr_fork_to_public docstring and use pr.html_url when printing the created PR.
- Update CHANGELOG with descriptions of the new commands and a new git-flow planning doc.

These changes consolidate common multi-repo release/sync flows into single commands to simplify workflows and ensure the expected human-review semantics for public releases.
Split the outbound release flow: `git release` now stages the tag and opens the public PR (tag pushed to fork only), while a new `git release-finalize` command pushes tags from private -> public after the public PR is merged. push_private_to_fork now creates tags locally and defers pushing until after confirmation (so --dry-run no longer leaks tags). push_tags_private_to_public gained dry-run and confirm flags. Dry-run behavior was standardized across release and sync flows so tempdir operations run locally but abort before any remote pushes. Updated CLI prompts/messages and corresponding docs in CHANGELOG.md.
@ionite34 ionite34 changed the title Bump version to 0.4.0 and add pr_branches command Add git commands pr_branches, sync-contributions, release (v0.4.0) Apr 19, 2026
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.

1 participant