Some checks failed
Build and Release / Create Release (push) Successful in 0s
Trigger Vault Plugin Rebuild / Trigger Vault Rebuild (push) Successful in 0s
Build and Release / Integration Tests (PostgreSQL) (push) Successful in 2m48s
Build and Release / Lint (push) Failing after 5m2s
Build and Release / Build Binaries (amd64, windows, windows-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (amd64, linux, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, darwin, linux-latest) (push) Has been skipped
Build and Release / Build Binaries (arm64, linux, linux-latest) (push) Has been skipped
Build and Release / Unit Tests (push) Successful in 5m37s
Go's semantic import versioning requires v2+ modules to include the major version in the module path. This enables using proper version tags (v3.x.x) instead of pseudo-versions. Updated module path: code.gitcaddy.com/server/v3
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright 2025 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package pull
|
|
|
|
import (
|
|
"context"
|
|
|
|
git_model "code.gitcaddy.com/server/v3/models/git"
|
|
repo_model "code.gitcaddy.com/server/v3/models/repo"
|
|
)
|
|
|
|
func CreateOrUpdateProtectedBranch(ctx context.Context, repo *repo_model.Repository,
|
|
protectBranch *git_model.ProtectedBranch, whitelistOptions git_model.WhitelistOptions,
|
|
) error {
|
|
err := git_model.UpdateProtectBranch(ctx, repo, protectBranch, whitelistOptions)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
isPlainRule := !git_model.IsRuleNameSpecial(protectBranch.RuleName)
|
|
var isBranchExist bool
|
|
if isPlainRule {
|
|
isBranchExist, _ = git_model.IsBranchExist(ctx, repo.ID, protectBranch.RuleName)
|
|
}
|
|
|
|
if isBranchExist {
|
|
if err := CheckPRsForBaseBranch(ctx, repo, protectBranch.RuleName); err != nil {
|
|
return err
|
|
}
|
|
} else {
|
|
if !isPlainRule {
|
|
// FIXME: since we only need to recheck files protected rules, we could improve this
|
|
matchedBranches, err := git_model.FindAllMatchedBranches(ctx, repo.ID, protectBranch.RuleName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, branchName := range matchedBranches {
|
|
if err = CheckPRsForBaseBranch(ctx, repo, branchName); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|