summaryrefslogtreecommitdiffstats
path: root/services
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
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')
-rw-r--r--services/pull/merge.go30
-rw-r--r--services/pull/pull.go9
-rw-r--r--services/pull/review.go4
-rw-r--r--services/pull/temp_repo.go12
4 files changed, 25 insertions, 30 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)
diff --git a/services/pull/pull.go b/services/pull/pull.go
index 6af751856d..5c7ec91f5d 100644
--- a/services/pull/pull.go
+++ b/services/pull/pull.go
@@ -236,16 +236,15 @@ func AddTestPullRequestTask(doer *models.User, repoID int64, branch string, isSy
// checkIfPRContentChanged checks if diff to target branch has changed by push
// A commit can be considered to leave the PR untouched if the patch/diff with its merge base is unchanged
func checkIfPRContentChanged(pr *models.PullRequest, oldCommitID, newCommitID string) (hasChanged bool, err error) {
-
- if err = pr.GetHeadRepo(); err != nil {
- return false, fmt.Errorf("GetHeadRepo: %v", err)
+ if err = pr.LoadHeadRepo(); err != nil {
+ return false, fmt.Errorf("LoadHeadRepo: %v", err)
} else if pr.HeadRepo == nil {
// corrupt data assumed changed
return true, nil
}
- if err = pr.GetBaseRepo(); err != nil {
- return false, fmt.Errorf("GetBaseRepo: %v", err)
+ if err = pr.LoadBaseRepo(); err != nil {
+ return false, fmt.Errorf("LoadBaseRepo: %v", err)
}
headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
diff --git a/services/pull/review.go b/services/pull/review.go
index 2b7c9e8646..25e0ca858a 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -111,8 +111,8 @@ func createCodeComment(doer *models.User, repo *models.Repository, issue *models
return nil, fmt.Errorf("GetPullRequestByIssueID: %v", err)
}
pr := issue.PullRequest
- if err := pr.GetBaseRepo(); err != nil {
- return nil, fmt.Errorf("GetHeadRepo: %v", err)
+ if err := pr.LoadBaseRepo(); err != nil {
+ return nil, fmt.Errorf("LoadHeadRepo: %v", err)
}
gitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
if err != nil {
diff --git a/services/pull/temp_repo.go b/services/pull/temp_repo.go
index bb6ce2921e..ffac92ade5 100644
--- a/services/pull/temp_repo.go
+++ b/services/pull/temp_repo.go
@@ -17,17 +17,17 @@ import (
)
func createTemporaryRepo(pr *models.PullRequest) (string, error) {
- if err := pr.GetHeadRepo(); err != nil {
- log.Error("GetHeadRepo: %v", err)
- return "", fmt.Errorf("GetHeadRepo: %v", err)
+ if err := pr.LoadHeadRepo(); err != nil {
+ log.Error("LoadHeadRepo: %v", err)
+ return "", fmt.Errorf("LoadHeadRepo: %v", err)
} else if pr.HeadRepo == nil {
log.Error("Pr %d HeadRepo %d does not exist", pr.ID, pr.HeadRepoID)
return "", &models.ErrRepoNotExist{
ID: pr.HeadRepoID,
}
- } else if err := pr.GetBaseRepo(); err != nil {
- log.Error("GetBaseRepo: %v", err)
- return "", fmt.Errorf("GetBaseRepo: %v", err)
+ } else if err := pr.LoadBaseRepo(); err != nil {
+ log.Error("LoadBaseRepo: %v", err)
+ return "", fmt.Errorf("LoadBaseRepo: %v", err)
} else if pr.BaseRepo == nil {
log.Error("Pr %d BaseRepo %d does not exist", pr.ID, pr.BaseRepoID)
return "", &models.ErrRepoNotExist{