Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: move part of updating protected branch logic to service layer #33742

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lunny
Copy link
Member

@lunny lunny commented Feb 27, 2025

No description provided.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Feb 27, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 27, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Feb 27, 2025
@lunny lunny requested a review from Copilot February 27, 2025 18:00
@lunny lunny added the type/refactoring Existing code has been cleaned up. There should be no new functionality. label Feb 27, 2025
@lunny lunny added this to the 1.24.0 milestone Feb 27, 2025

Choose a reason for hiding this comment

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

PR Overview

This PR refactors the protected branch update logic by moving part of it to the service layer, centralizing functionality and reducing redundancy. Key changes include:

  • Introducing a new service function (CreateOrUpdateProtectedBranch) in services/pull/protected_branch.go to encapsulate the update and PR recheck logic.
  • Updating the web and API route handlers to call the new service function instead of duplicating the branch-check logic.
  • Removing redundant inline recheck logic and cleaning up obsolete comments.

Reviewed Changes

File Description
services/pull/protected_branch.go New service function for creating or updating protected branches.
routers/web/repo/setting/protected_branch.go Updated to use the new service function for protected branch updates.
routers/api/v1/repo/branch.go Removed duplicate branch-check logic in favor of the new service.
services/forms/repo_form.go Removed extraneous ASCII art comments.

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

services/pull/protected_branch.go:22

  • [nitpick] Consider renaming 'isPlainRule' to 'isRegularRule' for improved clarity on the branch rule type.
isPlainRule := !git_model.IsRuleNameSpecial(protectBranch.RuleName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/refactoring Existing code has been cleaned up. There should be no new functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants