Skip to content

Add config settings#8600

Open
solababs wants to merge 5 commits intosb-13032026-delete-branch-after-merge-ifc-2336from
sb-13032026-add-config-settings-ifc-2336
Open

Add config settings#8600
solababs wants to merge 5 commits intosb-13032026-delete-branch-after-merge-ifc-2336from
sb-13032026-add-config-settings-ifc-2336

Conversation

@solababs
Copy link
Contributor

@solababs solababs commented Mar 13, 2026

Why

There is no configuration surface for controlling automatic branch deletion after merge. Without these settings, the feature cannot be safely rolled out — behavior needs to default to off and be explicitly opt-in.

This PR adds the two config flags that gate the feature, along with a dependency validator between them. It is Phase 1 of the full implementation plan.

What changed

  • Added delete_branch_after_merge: bool (default false) to MainSettings — when enabled, the Infrahub branch is automatically deleted after a successful merge.
  • Added delete_git_branch_after_merge: bool (default false) to MainSettings — when enabled, the corresponding Git branch is also deleted; requires delete_branch_after_merge to be enabled.
  • Added a @model_validator that raises at startup if delete_git_branch_after_merge=true without delete_branch_after_merge=true, preventing a misconfigured state.
  • Added 3 unit tests covering the defaults and the validation error.

No behavioral changes beyond the new config fields — no deletion logic is wired up yet.

Suggested review order

  1. backend/infrahub/config.py — the two new fields and the validator
  2. backend/tests/unit/test_config.py — unit tests

How to review

Focus on the validator logic in config.py — specifically whether the error message and validation mode (after) are appropriate. The rest is straightforward field additions.

No schema, API, or database changes in this PR.

How to test

# Run the new tests
uv run pytest backend/tests/unit/test_config.py -v -k "delete_branch"

# Full unit suite
uv run invoke backend.test-unit

Expected: all three new tests pass. Attempting to instantiate MainSettings(delete_git_branch_after_merge=True, delete_branch_after_merge=False) raises a ValidationError with the message requires 'delete_branch_after_merge' to be enabled.

Impact & rollout

  • Backward compatibility: No breaking changes. Both settings default to false, so existing deployments are unaffected.
  • Config/env changes: Two new optional settings in MainSettings: delete_branch_after_merge and delete_git_branch_after_merge.
  • Deployment notes: Safe to deploy independently. The deletion logic is not implemented yet.

Checklist

  • Tests added/updated
  • Changelog entry added (uv run towncrier create ...)
  • External docs updated (if user-facing or ops-facing change)
  • Internal .md docs updated (internal knowledge and AI code tools knowledge)

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 13, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (4)
  • main
  • stable
  • develop
  • release-.*

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 34b87b0b-96af-4b66-8260-de93d9b64893

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added the group/backend Issue related to the backend (API Server, Git Agent) label Mar 13, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Mar 13, 2026

Merging this PR will not alter performance

✅ 12 untouched benchmarks


Comparing sb-13032026-add-config-settings-ifc-2336 (b07039d) with stable (43d16b8)1

Open in CodSpeed

Footnotes

  1. No successful run was found on sb-13032026-delete-branch-after-merge-ifc-2336 (1ac1311) during the generation of this report, so stable (43d16b8) was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@solababs solababs marked this pull request as ready for review March 17, 2026 11:26
@solababs solababs requested a review from a team as a code owner March 17, 2026 11:26
@solababs solababs requested review from a team as code owners March 17, 2026 11:50
@github-actions github-actions bot added the type/documentation Improvements or additions to documentation label Mar 17, 2026
@github-actions github-actions bot added the group/frontend Issue related to the frontend (React) label Mar 17, 2026
Comment on lines +212 to +216
delete_git_branch_after_merge: bool = Field(
default=False,
description="When enabled, the corresponding Git branch is deleted after the Infrahub branch is deleted. "
"Requires delete_branch_after_merge to be enabled.",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

probably more of a design-level question, but it seems like we should be able to delete a branch on git regardless of whether the branch is being automatically deleted after a merge or manually deleted later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ajtmccarty as seen here #8431 (comment), i think this was intentionally designed this way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

group/backend Issue related to the backend (API Server, Git Agent) group/frontend Issue related to the frontend (React) type/documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants