diff options
author | a1012112796 <1012112796@qq.com> | 2023-08-21 21:13:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-21 13:13:34 +0000 |
commit | f43df2f8201c33260b65b582556a3b0f4c75b637 (patch) | |
tree | 7a6c01ab7bc5d215b0ea8d8010bec47b0d6468ef /routers/web/repo/issue.go | |
parent | fe78aabc673daf36655f0cca7e83cf2b057b8361 (diff) | |
download | gitea-f43df2f8201c33260b65b582556a3b0f4c75b637.tar.gz gitea-f43df2f8201c33260b65b582556a3b0f4c75b637.zip |
fix reopen logic for agit flow pull request (#26399) (#26613)
Backport #26399
Signed-off-by: a1012112796 <1012112796@qq.com>
Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'routers/web/repo/issue.go')
-rw-r--r-- | routers/web/repo/issue.go | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 1904ae3ba9..9d4bd07c65 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -2831,53 +2831,55 @@ func NewComment(ctx *context.Context) { // 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 // get head commit of PR - prHeadRef := pull.GetGitRefName() - if err := pull.LoadBaseRepo(ctx); err != nil { - ctx.ServerError("Unable to load base repo", err) - return - } - prHeadCommitID, err := git.GetFullCommitID(ctx, pull.BaseRepo.RepoPath(), prHeadRef) - if err != nil { - ctx.ServerError("Get head commit Id of pr fail", err) - return - } - - // get head commit of branch in the head repo - if err := pull.LoadHeadRepo(ctx); err != nil { - ctx.ServerError("Unable to load head repo", err) - return - } - if ok := git.IsBranchExist(ctx, pull.HeadRepo.RepoPath(), pull.BaseBranch); !ok { - // todo localize - ctx.Flash.Error("The origin branch is delete, cannot reopen.") - ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, pull.Index)) - return - } - headBranchRef := pull.GetGitHeadBranchRefName() - headBranchCommitID, err := git.GetFullCommitID(ctx, pull.HeadRepo.RepoPath(), headBranchRef) - if err != nil { - ctx.ServerError("Get head commit Id of head branch fail", err) - return - } + if pull.Flow == issues_model.PullRequestFlowGithub { + prHeadRef := pull.GetGitRefName() + if err := pull.LoadBaseRepo(ctx); err != nil { + ctx.ServerError("Unable to load base repo", err) + return + } + prHeadCommitID, err := git.GetFullCommitID(ctx, pull.BaseRepo.RepoPath(), prHeadRef) + if err != nil { + ctx.ServerError("Get head commit Id of pr fail", err) + return + } - err = pull.LoadIssue(ctx) - if err != nil { - ctx.ServerError("load the issue of pull request error", err) - return - } + // get head commit of branch in the head repo + if err := pull.LoadHeadRepo(ctx); err != nil { + ctx.ServerError("Unable to load head repo", err) + return + } + if ok := git.IsBranchExist(ctx, pull.HeadRepo.RepoPath(), pull.BaseBranch); !ok { + // todo localize + ctx.Flash.Error("The origin branch is delete, cannot reopen.") + ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, pull.Index)) + return + } + headBranchRef := pull.GetGitHeadBranchRefName() + headBranchCommitID, err := git.GetFullCommitID(ctx, pull.HeadRepo.RepoPath(), headBranchRef) + if err != nil { + ctx.ServerError("Get head commit Id of head branch fail", err) + return + } - if prHeadCommitID != headBranchCommitID { - // force push to base repo - err := git.Push(ctx, pull.HeadRepo.RepoPath(), git.PushOptions{ - Remote: pull.BaseRepo.RepoPath(), - Branch: pull.HeadBranch + ":" + prHeadRef, - Force: true, - Env: repo_module.InternalPushingEnvironment(pull.Issue.Poster, pull.BaseRepo), - }) + err = pull.LoadIssue(ctx) if err != nil { - ctx.ServerError("force push error", err) + ctx.ServerError("load the issue of pull request error", err) return } + + if prHeadCommitID != headBranchCommitID { + // force push to base repo + err := git.Push(ctx, pull.HeadRepo.RepoPath(), git.PushOptions{ + Remote: pull.BaseRepo.RepoPath(), + Branch: pull.HeadBranch + ":" + prHeadRef, + Force: true, + Env: repo_module.InternalPushingEnvironment(pull.Issue.Poster, pull.BaseRepo), + }) + if err != nil { + ctx.ServerError("force push error", err) + return + } + } } } |