Add delete branch from git#8616
Open
solababs wants to merge 4 commits intosb-13032026-delete-infrahub-branch-after-merge-ifc-2336from
Open
Add delete branch from git#8616solababs wants to merge 4 commits intosb-13032026-delete-infrahub-branch-after-merge-ifc-2336from
solababs wants to merge 4 commits intosb-13032026-delete-infrahub-branch-after-merge-ifc-2336from
Conversation
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (4)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…' into sb-13032026-delete-git-branch-after-merge-ifc-2336
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
When
delete_branch_after_mergeis enabled and a branch hassync_with_git=True, the Infrahub branch is cleaned up automatically but the corresponding branch in the Git repositories is left behind. There is no way to have both sides cleaned up automatically today.This PR adds the
GIT_REPOSITORIES_DELETE_BRANCHworkflow and wiresdelete_git_branch_after_mergeinto thedelete_branch()flow so that all synced Git repositories have the branch removed after the Infrahub branch is deleted. Per-repo failures are logged but never block the deletion.What changed
backend/infrahub/git/base.py— two new methods onInfrahubRepositoryBase:origin_has_branch(branch_name)(checks whether a branch exists on the remote) anddelete_remote_branch(branch_name)(pushes--deleteto origin and removes the local tracking ref).backend/infrahub/git/tasks.py— newdelete_git_branch()flow andgit_branch_deletetask. The flow fans out across allCoreRepositoryinstances via a batch; the task skips repos that don't have the branch and logs (without re-raising) any deletion failures.backend/infrahub/workflows/catalogue.py— newGIT_REPOSITORIES_DELETE_BRANCHworkflow definition registered in theWORKFLOWSlist.backend/infrahub/core/branch/tasks.py— afterBranchDeletedEventis sent indelete_branch(), submitsGIT_REPOSITORIES_DELETE_BRANCHwhendelete_git_branch_after_merge=Trueand the branch hassync_with_git=True.backend/tests/component/git/test_delete_git_branch.py— 4 component tests fororigin_has_branchanddelete_remote_branchagainst a real local Git repo.backend/tests/functional/branch/test_delete_git_branch.py— 3 functional tests: config enabled +sync_with_git=Truetriggers workflow; config disabled does not;sync_with_git=Falsedoes not.No schema, API contract, or database changes. Default for
delete_git_branch_after_mergeremainsFalse.Suggested review order
origin_has_branch+delete_remote_branchdelete_git_branchflow +git_branch_deletetaskdelete_branch()How to review
git_branch_deletetask: confirm that swallowing exceptions withlog.exceptionis the right behaviour (FR-013 says per-repo failures must not block deletion). Theasync with lock.registry.get(...)mirrorsgit_branch_createand prevents concurrent git ops on the same repo.origin_has_branchis synchronous — do not addawaitwhen calling it in the task.should_delete_gitguard indelete_branch()checks both the config flag andobj.sync_with_git— branches not tracked in Git are silently skipped.How to test
Manual flow:
delete_branch_after_merge = trueanddelete_git_branch_after_merge = trueininfrahub.toml, restart.sync_with_git=True, push a commit, merge viaBranchMerge.delete_git_branch_after_merge = false— Git branch is retained.Impact & rollout
delete_git_branch_after_mergedefaults tofalse; requiresdelete_branch_after_merge=trueto be set (validated at startup).delete_git_branch_after_mergeinMainSettings(Phase 1).Checklist
uv run towncrier create ...)