初始提交: Gitea 项目代码

This commit is contained in:
root
2026-05-30 22:47:36 +08:00
commit f288f76350
6116 changed files with 776822 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package pull
import (
"context"
git_model "gitea.dev/models/git"
repo_model "gitea.dev/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
}