Support automatic branch cleanup and merge-method selection for reviews #51

Merged
Christoph merged 0 commits from refs/pull/51/head into main 2026-09-18 13:25:25 +00:00
Christoph commented 2026-09-18 13:25:03 +00:00 (Migrated from git.cbsk-tech.de)

This change adds provider-aware merge payloads and an optional automatic local branch cleanup flow when accepting/merging review requests.

Summary

  • Integrations: the review/merge flow now accepts a merge-method parameter and constructs provider-specific merge payloads instead of sending a generic empty body. Azure DevOps handling is adapted to merge the provider payload with the required status and lastMergeSourceCommit fields.
  • Integrations: a new cleanup flow is introduced under src-tauri/src/integrations/cleanup.rs. When a merge action is requested and a cleanup_path is provided, the integrations layer calls into a prepare step (which verifies the PR details remotely) before performing the merge and then runs a finish step after the merge to perform local repository cleanup.
  • Git layer: a new module src-tauri/src/git/review_cleanup.rs implements the local-side cleanup plan (prepare and finish). It validates branches and remotes, checks worktree cleanliness, verifies remote/local SHAs, performs authenticated fetches, fast-forwards or checks out the target branch, and removes the PR branch both remotely (using expected-old-value deletion when safe) and locally (removing branch refs and associated branch config). Several safety checks prevent destructive actions when the local repo or remote have diverged or when the branch is in use in another worktree.
  • Tests: unit tests for the local cleanup logic are added in src-tauri/src/git/review_cleanup.rs. They cover normal deletion after merge (including squash/merge), acceptance of server-side deletion, preservation of dirty or unpushed local work, concurrent local/remote commits, and protection against mismatched remotes or active worktrees.
  • Small exports and plumbing: git::review_cleanup is exported via src-tauri/src/git.rs, and integrations::merge helpers are used for generating payloads. A minor doc/template tweak was made in src-tauri/crates/commit_ai/src/cloud.rs (Markdown formatting text).

Key behavior changes

  • run_integration_review_action now accepts two additional optional inputs: merge_method: Option<String> and cleanup_path: Option<String>.
    • If merge_method is provided for a merge action, the code validates and uses provider-specific payloads (via merge_payload) when issuing the merge request.
    • If cleanup_path is provided and the action is merge, the integrations code attempts to prepare a cleanup plan (remote PR verification + local checks) before performing the merge; on success it will call the cleanup finish step after the merge completes.
  • The local cleanup implementation will refuse to proceed if it detects uncommitted changes, an ongoing merge/rebase/cherry-pick, branch names that look invalid, a non-matching remote URL, or concurrent changes that would make deletion unsafe. Similarly, the finish step rejects concurrent remote changes and preserves branches when it cannot safely delete them.

Why this matters (evidence-based)

  • The diffs show provider-specific merge payload generation is now used for GitHub, GitLab, Gitea and Azure DevOps requests rather than an empty JSON object. Azure DevOps is handled by merging the provider payload into the final JSON body containing status and the merge commit id.
  • The new integrations/cleanup.rs module reads the PR payload from the provider API and maps it to a CleanupPlan. The git/review_cleanup.rs module contains the implementation for local verification and safe deletion operations, including comprehensive checks and explicit fetch/push operations with authentication.

Testing

  • Tests were added under src-tauri/src/git/review_cleanup.rs exercising the cleanup logic, but no test execution results were provided.

Recommended reviewer checks

  1. Unit tests: run the tauri workspace tests to execute the new cleanup tests (example):
    • From the repository root run cd src-tauri && cargo test (or run your workspace's normal test command).
  2. Manual/behavioural check of merges for each provider: verify merge_payload outputs expected JSON for github, gitlab, gitea, and azure-devops, and that the integrations code sends that payload when merge_method is set.
  3. Cleanup safety: review git/review_cleanup.rs for the intended safety invariants (worktree cleanliness, remote URL matching, expected-old-value push deletion) and confirm they align with expected repository-local policies.
  4. Call sites: update any internal callers of run_integration_review_action if they exist, since its signature now includes merge_method and cleanup_path optional parameters.

Compatibility and reviewer action

  • This introduces optional parameters to the internal run_integration_review_action interface. Any code that calls this function directly inside the codebase must be updated to pass the new parameters (or None) as appropriate.
  • The cleanup feature can delete branches locally and remotely when safety checks pass. Reviewers should confirm that callers only enable cleanup (cleanup_path) when the local repository path refers to a trusted checkout matching the PR's remote.

No test execution results were provided.

This change adds provider-aware merge payloads and an optional automatic local branch cleanup flow when accepting/merging review requests. Summary - Integrations: the review/merge flow now accepts a merge-method parameter and constructs provider-specific merge payloads instead of sending a generic empty body. Azure DevOps handling is adapted to merge the provider payload with the required `status` and `lastMergeSourceCommit` fields. - Integrations: a new cleanup flow is introduced under `src-tauri/src/integrations/cleanup.rs`. When a merge action is requested and a `cleanup_path` is provided, the integrations layer calls into a prepare step (which verifies the PR details remotely) before performing the merge and then runs a finish step after the merge to perform local repository cleanup. - Git layer: a new module `src-tauri/src/git/review_cleanup.rs` implements the local-side cleanup plan (`prepare` and `finish`). It validates branches and remotes, checks worktree cleanliness, verifies remote/local SHAs, performs authenticated fetches, fast-forwards or checks out the target branch, and removes the PR branch both remotely (using expected-old-value deletion when safe) and locally (removing branch refs and associated branch config). Several safety checks prevent destructive actions when the local repo or remote have diverged or when the branch is in use in another worktree. - Tests: unit tests for the local cleanup logic are added in `src-tauri/src/git/review_cleanup.rs`. They cover normal deletion after merge (including squash/merge), acceptance of server-side deletion, preservation of dirty or unpushed local work, concurrent local/remote commits, and protection against mismatched remotes or active worktrees. - Small exports and plumbing: `git::review_cleanup` is exported via `src-tauri/src/git.rs`, and `integrations::merge` helpers are used for generating payloads. A minor doc/template tweak was made in `src-tauri/crates/commit_ai/src/cloud.rs` (Markdown formatting text). Key behavior changes - run_integration_review_action now accepts two additional optional inputs: `merge_method: Option<String>` and `cleanup_path: Option<String>`. - If `merge_method` is provided for a merge action, the code validates and uses provider-specific payloads (via `merge_payload`) when issuing the merge request. - If `cleanup_path` is provided and the action is `merge`, the integrations code attempts to prepare a cleanup plan (remote PR verification + local checks) before performing the merge; on success it will call the cleanup finish step after the merge completes. - The local cleanup implementation will refuse to proceed if it detects uncommitted changes, an ongoing merge/rebase/cherry-pick, branch names that look invalid, a non-matching remote URL, or concurrent changes that would make deletion unsafe. Similarly, the finish step rejects concurrent remote changes and preserves branches when it cannot safely delete them. Why this matters (evidence-based) - The diffs show provider-specific merge payload generation is now used for GitHub, GitLab, Gitea and Azure DevOps requests rather than an empty JSON object. Azure DevOps is handled by merging the provider payload into the final JSON body containing `status` and the merge commit id. - The new `integrations/cleanup.rs` module reads the PR payload from the provider API and maps it to a `CleanupPlan`. The `git/review_cleanup.rs` module contains the implementation for local verification and safe deletion operations, including comprehensive checks and explicit fetch/push operations with authentication. Testing - Tests were added under `src-tauri/src/git/review_cleanup.rs` exercising the cleanup logic, but no test execution results were provided. Recommended reviewer checks 1. Unit tests: run the tauri workspace tests to execute the new cleanup tests (example): - From the repository root run `cd src-tauri && cargo test` (or run your workspace's normal test command). 2. Manual/behavioural check of merges for each provider: verify `merge_payload` outputs expected JSON for `github`, `gitlab`, `gitea`, and `azure-devops`, and that the integrations code sends that payload when `merge_method` is set. 3. Cleanup safety: review `git/review_cleanup.rs` for the intended safety invariants (worktree cleanliness, remote URL matching, expected-old-value push deletion) and confirm they align with expected repository-local policies. 4. Call sites: update any internal callers of `run_integration_review_action` if they exist, since its signature now includes `merge_method` and `cleanup_path` optional parameters. Compatibility and reviewer action - This introduces optional parameters to the internal `run_integration_review_action` interface. Any code that calls this function directly inside the codebase must be updated to pass the new parameters (or `None`) as appropriate. - The cleanup feature can delete branches locally and remotely when safety checks pass. Reviewers should confirm that callers only enable cleanup (`cleanup_path`) when the local repository path refers to a trusted checkout matching the PR's remote. No test execution results were provided.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Christoph/Gitty!51
No description provided.