1
1
mirror of https://github.com/go-gitea/gitea synced 2025-12-07 13:28:25 +00:00

Move all checks into DeleteBranch and PushUpdate

This commit is contained in:
Lunny Xiao
2024-11-09 18:07:58 -08:00
parent 75623936e9
commit e70e375996
8 changed files with 26 additions and 76 deletions
+7 -19
View File
@@ -31,7 +31,6 @@ import (
"code.gitea.io/gitea/modules/util"
webhook_module "code.gitea.io/gitea/modules/webhook"
notify_service "code.gitea.io/gitea/services/notify"
pull_service "code.gitea.io/gitea/services/pull"
files_service "code.gitea.io/gitea/services/repository/files"
"xorm.io/builder"
@@ -468,7 +467,7 @@ var (
)
// DeleteBranch delete branch
func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string) error {
func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.Repository, gitRepo *git.Repository, branchName string, pr *issues_model.PullRequest) error {
perm, err := access_model.GetUserRepoPermission(ctx, repo, doer)
if err != nil {
return err
@@ -515,6 +514,12 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
}
}
if pr != nil {
if err := issues_model.AddDeletePRBranchComment(ctx, doer, pr.BaseRepo, pr.Issue.ID, pr.HeadBranch); err != nil {
return fmt.Errorf("DeleteBranch: %v", err)
}
}
return gitRepo.DeleteBranch(branchName, git.DeleteBranchOptions{
Force: true,
})
@@ -541,23 +546,6 @@ func DeleteBranch(ctx context.Context, doer *user_model.User, repo *repo_model.R
return nil
}
func DeletePullRequestHeadBranch(ctx context.Context, pr *issues_model.PullRequest, doer *user_model.User, headGitRepo *git.Repository) error {
if err := pull_service.RetargetChildrenOnMerge(ctx, doer, pr); err != nil {
return err
}
if err := DeleteBranch(ctx, doer, pr.HeadRepo, headGitRepo, pr.HeadBranch); err != nil {
return err
}
if err := issues_model.AddDeletePRBranchComment(ctx, doer, pr.BaseRepo, pr.IssueID, pr.HeadBranch); err != nil {
// Do not fail here as branch has already been deleted
log.Error("AddDeletePRBranchComment: %v", err)
}
return nil
}
type BranchSyncOptions struct {
RepoID int64
}
+7
View File
@@ -275,6 +275,13 @@ func pushUpdates(optsList []*repo_module.PushUpdateOptions) error {
}
} else {
notify_service.DeleteRef(ctx, pusher, repo, opts.RefFullName)
if setting.Repository.PullRequest.RetargetChildrenOnMerge {
if err := pull_service.RetargetBranchPulls(ctx, pusher, repo.ID, branch, repo.DefaultBranch); err != nil {
return err
}
}
if err = pull_service.CloseBranchPulls(ctx, pusher, repo.ID, branch); err != nil {
// close all related pulls
log.Error("close related pull request failed: %v", err)