mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package pull
|
|
|
|
import (
|
|
"context"
|
|
|
|
git_model "github.com/hanzoai/git/models/git"
|
|
repo_model "github.com/hanzoai/git/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
|
|
}
|