Skip to content

Commit f00fdd1

Browse files
authored
fix reopen logic for agit flow pull request (#26399)
the head branch is meaningless for a agit flow pull request, so should not check it when reopen it. related: #24231 fix #26334 Signed-off-by: a1012112796 <[email protected]>
1 parent 5feef6d commit f00fdd1

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

routers/web/repo/issue.go

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,52 +2935,54 @@ func NewComment(ctx *context.Context) {
29352935

29362936
// check whether the ref of PR <refs/pulls/pr_index/head> in base repo is consistent with the head commit of head branch in the head repo
29372937
// get head commit of PR
2938-
prHeadRef := pull.GetGitRefName()
2939-
if err := pull.LoadBaseRepo(ctx); err != nil {
2940-
ctx.ServerError("Unable to load base repo", err)
2941-
return
2942-
}
2943-
prHeadCommitID, err := git.GetFullCommitID(ctx, pull.BaseRepo.RepoPath(), prHeadRef)
2944-
if err != nil {
2945-
ctx.ServerError("Get head commit Id of pr fail", err)
2946-
return
2947-
}
2948-
2949-
// get head commit of branch in the head repo
2950-
if err := pull.LoadHeadRepo(ctx); err != nil {
2951-
ctx.ServerError("Unable to load head repo", err)
2952-
return
2953-
}
2954-
if ok := git.IsBranchExist(ctx, pull.HeadRepo.RepoPath(), pull.BaseBranch); !ok {
2955-
// todo localize
2956-
ctx.JSONError("The origin branch is delete, cannot reopen.")
2957-
return
2958-
}
2959-
headBranchRef := pull.GetGitHeadBranchRefName()
2960-
headBranchCommitID, err := git.GetFullCommitID(ctx, pull.HeadRepo.RepoPath(), headBranchRef)
2961-
if err != nil {
2962-
ctx.ServerError("Get head commit Id of head branch fail", err)
2963-
return
2964-
}
2938+
if pull.Flow == issues_model.PullRequestFlowGithub {
2939+
prHeadRef := pull.GetGitRefName()
2940+
if err := pull.LoadBaseRepo(ctx); err != nil {
2941+
ctx.ServerError("Unable to load base repo", err)
2942+
return
2943+
}
2944+
prHeadCommitID, err := git.GetFullCommitID(ctx, pull.BaseRepo.RepoPath(), prHeadRef)
2945+
if err != nil {
2946+
ctx.ServerError("Get head commit Id of pr fail", err)
2947+
return
2948+
}
29652949

2966-
err = pull.LoadIssue(ctx)
2967-
if err != nil {
2968-
ctx.ServerError("load the issue of pull request error", err)
2969-
return
2970-
}
2950+
// get head commit of branch in the head repo
2951+
if err := pull.LoadHeadRepo(ctx); err != nil {
2952+
ctx.ServerError("Unable to load head repo", err)
2953+
return
2954+
}
2955+
if ok := git.IsBranchExist(ctx, pull.HeadRepo.RepoPath(), pull.BaseBranch); !ok {
2956+
// todo localize
2957+
ctx.JSONError("The origin branch is delete, cannot reopen.")
2958+
return
2959+
}
2960+
headBranchRef := pull.GetGitHeadBranchRefName()
2961+
headBranchCommitID, err := git.GetFullCommitID(ctx, pull.HeadRepo.RepoPath(), headBranchRef)
2962+
if err != nil {
2963+
ctx.ServerError("Get head commit Id of head branch fail", err)
2964+
return
2965+
}
29712966

2972-
if prHeadCommitID != headBranchCommitID {
2973-
// force push to base repo
2974-
err := git.Push(ctx, pull.HeadRepo.RepoPath(), git.PushOptions{
2975-
Remote: pull.BaseRepo.RepoPath(),
2976-
Branch: pull.HeadBranch + ":" + prHeadRef,
2977-
Force: true,
2978-
Env: repo_module.InternalPushingEnvironment(pull.Issue.Poster, pull.BaseRepo),
2979-
})
2967+
err = pull.LoadIssue(ctx)
29802968
if err != nil {
2981-
ctx.ServerError("force push error", err)
2969+
ctx.ServerError("load the issue of pull request error", err)
29822970
return
29832971
}
2972+
2973+
if prHeadCommitID != headBranchCommitID {
2974+
// force push to base repo
2975+
err := git.Push(ctx, pull.HeadRepo.RepoPath(), git.PushOptions{
2976+
Remote: pull.BaseRepo.RepoPath(),
2977+
Branch: pull.HeadBranch + ":" + prHeadRef,
2978+
Force: true,
2979+
Env: repo_module.InternalPushingEnvironment(pull.Issue.Poster, pull.BaseRepo),
2980+
})
2981+
if err != nil {
2982+
ctx.ServerError("force push error", err)
2983+
return
2984+
}
2985+
}
29842986
}
29852987
}
29862988

0 commit comments

Comments
 (0)