summaryrefslogtreecommitdiffstats
path: root/services/pull/merge.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-03-03 06:31:55 +0800
committerGitHub <noreply@github.com>2020-03-02 22:31:55 +0000
commit5abe1c52de533b52725b1e584db9fea6fb1b39ab (patch)
tree1cd49bc1a609bb919c70d6bc30727c524c3e6105 /services/pull/merge.go
parent22b750702408a39a524e011b729d0e0befb30e16 (diff)
downloadgitea-5abe1c52de533b52725b1e584db9fea6fb1b39ab.tar.gz
gitea-5abe1c52de533b52725b1e584db9fea6fb1b39ab.zip
Display pull request head branch even the branch deleted or repository deleted (#10413)
* Display pull request head branch even the branch deleted or repository deleted * Merge getHeadRepo/loadHeadRepo and getBaseRepo/loadBaseRepo on pull and fill repo when pr.Issue.Repo is available * retrieve sha from pull head when pull request branch deleted and fix tests * Fix test * Ensure MustHeadRepoName returns empty string if no head repo Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'services/pull/merge.go')
-rw-r--r--services/pull/merge.go30
1 files changed, 13 insertions, 17 deletions
diff --git a/services/pull/merge.go b/services/pull/merge.go
index 4d02d7193d..c8351ba85a 100644
--- a/services/pull/merge.go
+++ b/services/pull/merge.go
@@ -33,13 +33,12 @@ import (
// Caller should check PR is ready to be merged (review and status checks)
// FIXME: add repoWorkingPull make sure two merges does not happen at same time.
func Merge(pr *models.PullRequest, doer *models.User, baseGitRepo *git.Repository, mergeStyle models.MergeStyle, message string) (err error) {
-
- if err = pr.GetHeadRepo(); err != nil {
- log.Error("GetHeadRepo: %v", err)
- return fmt.Errorf("GetHeadRepo: %v", err)
- } else if err = pr.GetBaseRepo(); err != nil {
- log.Error("GetBaseRepo: %v", err)
- return fmt.Errorf("GetBaseRepo: %v", err)
+ if err = pr.LoadHeadRepo(); err != nil {
+ log.Error("LoadHeadRepo: %v", err)
+ return fmt.Errorf("LoadHeadRepo: %v", err)
+ } else if err = pr.LoadBaseRepo(); err != nil {
+ log.Error("LoadBaseRepo: %v", err)
+ return fmt.Errorf("LoadBaseRepo: %v", err)
}
prUnit, err := pr.BaseRepo.GetUnit(models.UnitTypePullRequests)
@@ -535,18 +534,15 @@ func IsUserAllowedToMerge(pr *models.PullRequest, p models.Permission, user *mod
// CheckPRReadyToMerge checks whether the PR is ready to be merged (reviews and status checks)
func CheckPRReadyToMerge(pr *models.PullRequest) (err error) {
- if pr.BaseRepo == nil {
- if err = pr.GetBaseRepo(); err != nil {
- return fmt.Errorf("GetBaseRepo: %v", err)
- }
+ if err = pr.LoadBaseRepo(); err != nil {
+ return fmt.Errorf("LoadBaseRepo: %v", err)
+ }
+
+ if err = pr.LoadProtectedBranch(); err != nil {
+ return fmt.Errorf("LoadProtectedBranch: %v", err)
}
if pr.ProtectedBranch == nil {
- if err = pr.LoadProtectedBranch(); err != nil {
- return fmt.Errorf("LoadProtectedBranch: %v", err)
- }
- if pr.ProtectedBranch == nil {
- return nil
- }
+ return nil
}
isPass, err := IsPullCommitStatusPass(pr)