|
|
@ -17,6 +17,23 @@ import (
|
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
|
|
|
"code.gitea.io/gitea/modules/timeutil"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ErrHeadRepoMissed represents an error to report pull's head repository missed
|
|
|
|
|
|
|
|
type ErrHeadRepoMissed struct {
|
|
|
|
|
|
|
|
PullID int64
|
|
|
|
|
|
|
|
HeadRepoID int64
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Error implements the interface
|
|
|
|
|
|
|
|
func (err ErrHeadRepoMissed) Error() string {
|
|
|
|
|
|
|
|
return fmt.Sprintf("Head repository [%d] of pull id [%d] missed", err.HeadRepoID, err.PullID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// IsErrHeadRepoMissed returns true if head repository missed
|
|
|
|
|
|
|
|
func IsErrHeadRepoMissed(err error) bool {
|
|
|
|
|
|
|
|
_, ok := err.(ErrHeadRepoMissed)
|
|
|
|
|
|
|
|
return ok
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// PullRequestType defines pull request type
|
|
|
|
// PullRequestType defines pull request type
|
|
|
|
type PullRequestType int
|
|
|
|
type PullRequestType int
|
|
|
|
|
|
|
|
|
|
|
@ -63,6 +80,8 @@ type PullRequest struct {
|
|
|
|
MergerID int64 `xorm:"INDEX"`
|
|
|
|
MergerID int64 `xorm:"INDEX"`
|
|
|
|
Merger *User `xorm:"-"`
|
|
|
|
Merger *User `xorm:"-"`
|
|
|
|
MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"`
|
|
|
|
MergedUnix timeutil.TimeStamp `xorm:"updated INDEX"`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
isHeadRepoLoaded bool `xorm:"-"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// MustHeadUserName returns the HeadRepo's username if failed return blank
|
|
|
|
// MustHeadUserName returns the HeadRepo's username if failed return blank
|
|
|
@ -75,6 +94,9 @@ func (pr *PullRequest) MustHeadUserName() string {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if pr.HeadRepo == nil {
|
|
|
|
|
|
|
|
return ""
|
|
|
|
|
|
|
|
}
|
|
|
|
return pr.HeadRepo.MustOwnerName()
|
|
|
|
return pr.HeadRepo.MustOwnerName()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -98,38 +120,57 @@ func (pr *PullRequest) LoadAttributes() error {
|
|
|
|
return pr.loadAttributes(x)
|
|
|
|
return pr.loadAttributes(x)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// LoadBaseRepo loads pull request base repository from database
|
|
|
|
func (pr *PullRequest) loadHeadRepo(e Engine) error {
|
|
|
|
func (pr *PullRequest) LoadBaseRepo() error {
|
|
|
|
if !pr.isHeadRepoLoaded && pr.HeadRepo == nil && pr.HeadRepoID > 0 {
|
|
|
|
if pr.BaseRepo == nil {
|
|
|
|
if pr.HeadRepoID == pr.BaseRepoID {
|
|
|
|
if pr.HeadRepoID == pr.BaseRepoID && pr.HeadRepo != nil {
|
|
|
|
if pr.BaseRepo != nil {
|
|
|
|
pr.BaseRepo = pr.HeadRepo
|
|
|
|
pr.HeadRepo = pr.BaseRepo
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
|
|
|
|
} else if pr.Issue != nil && pr.Issue.Repo != nil {
|
|
|
|
|
|
|
|
pr.HeadRepo = pr.Issue.Repo
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var repo Repository
|
|
|
|
|
|
|
|
if has, err := x.ID(pr.BaseRepoID).Get(&repo); err != nil {
|
|
|
|
var err error
|
|
|
|
return err
|
|
|
|
pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
|
|
|
|
} else if !has {
|
|
|
|
if err != nil && !IsErrRepoNotExist(err) { // Head repo maybe deleted, but it should still work
|
|
|
|
return ErrRepoNotExist{ID: pr.BaseRepoID}
|
|
|
|
return fmt.Errorf("getRepositoryByID(head): %v", err)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pr.BaseRepo = &repo
|
|
|
|
pr.isHeadRepoLoaded = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// LoadHeadRepo loads pull request head repository from database
|
|
|
|
// LoadHeadRepo loads the head repository
|
|
|
|
func (pr *PullRequest) LoadHeadRepo() error {
|
|
|
|
func (pr *PullRequest) LoadHeadRepo() error {
|
|
|
|
if pr.HeadRepo == nil {
|
|
|
|
return pr.loadHeadRepo(x)
|
|
|
|
if pr.HeadRepoID == pr.BaseRepoID && pr.BaseRepo != nil {
|
|
|
|
}
|
|
|
|
pr.HeadRepo = pr.BaseRepo
|
|
|
|
|
|
|
|
return nil
|
|
|
|
// LoadBaseRepo loads the target repository
|
|
|
|
}
|
|
|
|
func (pr *PullRequest) LoadBaseRepo() error {
|
|
|
|
var repo Repository
|
|
|
|
return pr.loadBaseRepo(x)
|
|
|
|
if has, err := x.ID(pr.HeadRepoID).Get(&repo); err != nil {
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
|
|
|
|
} else if !has {
|
|
|
|
func (pr *PullRequest) loadBaseRepo(e Engine) (err error) {
|
|
|
|
return ErrRepoNotExist{ID: pr.HeadRepoID}
|
|
|
|
if pr.BaseRepo != nil {
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
pr.HeadRepo = &repo
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pr.HeadRepoID == pr.BaseRepoID && pr.HeadRepo != nil {
|
|
|
|
|
|
|
|
pr.BaseRepo = pr.HeadRepo
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pr.Issue != nil && pr.Issue.Repo != nil {
|
|
|
|
|
|
|
|
pr.BaseRepo = pr.Issue.Repo
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pr.BaseRepo, err = getRepositoryByID(e, pr.BaseRepoID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return fmt.Errorf("GetRepositoryByID(base): %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -425,7 +466,6 @@ func (pr *PullRequest) apiFormat(e Engine) *api.PullRequest {
|
|
|
|
baseBranch *git.Branch
|
|
|
|
baseBranch *git.Branch
|
|
|
|
headBranch *git.Branch
|
|
|
|
headBranch *git.Branch
|
|
|
|
baseCommit *git.Commit
|
|
|
|
baseCommit *git.Commit
|
|
|
|
headCommit *git.Commit
|
|
|
|
|
|
|
|
err error
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if err = pr.Issue.loadRepo(e); err != nil {
|
|
|
|
if err = pr.Issue.loadRepo(e); err != nil {
|
|
|
@ -433,19 +473,14 @@ func (pr *PullRequest) apiFormat(e Engine) *api.PullRequest {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
apiIssue := pr.Issue.apiFormat(e)
|
|
|
|
apiIssue := pr.Issue.apiFormat(e)
|
|
|
|
if pr.BaseRepo == nil {
|
|
|
|
if err := pr.loadBaseRepo(e); err != nil {
|
|
|
|
pr.BaseRepo, err = getRepositoryByID(e, pr.BaseRepoID)
|
|
|
|
log.Error("loadBaseRepo[%d]: %v", pr.ID, err)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
log.Error("GetRepositoryById[%d]: %v", pr.ID, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if pr.HeadRepoID != 0 && pr.HeadRepo == nil {
|
|
|
|
|
|
|
|
pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
|
|
|
|
if err := pr.loadHeadRepo(e); err != nil {
|
|
|
|
if err != nil && !IsErrRepoNotExist(err) {
|
|
|
|
log.Error("loadHeadRepo[%d]: %v", pr.ID, err)
|
|
|
|
log.Error("GetRepositoryById[%d]: %v", pr.ID, err)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
apiPullRequest := &api.PullRequest{
|
|
|
|
apiPullRequest := &api.PullRequest{
|
|
|
@ -469,71 +504,17 @@ func (pr *PullRequest) apiFormat(e Engine) *api.PullRequest {
|
|
|
|
Deadline: apiIssue.Deadline,
|
|
|
|
Deadline: apiIssue.Deadline,
|
|
|
|
Created: pr.Issue.CreatedUnix.AsTimePtr(),
|
|
|
|
Created: pr.Issue.CreatedUnix.AsTimePtr(),
|
|
|
|
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
|
|
|
|
Updated: pr.Issue.UpdatedUnix.AsTimePtr(),
|
|
|
|
}
|
|
|
|
Base: &api.PRBranchInfo{
|
|
|
|
baseBranch, err = pr.BaseRepo.GetBranch(pr.BaseBranch)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
if git.IsErrBranchNotExist(err) {
|
|
|
|
|
|
|
|
apiPullRequest.Base = nil
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.Error("GetBranch[%s]: %v", pr.BaseBranch, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
apiBaseBranchInfo := &api.PRBranchInfo{
|
|
|
|
|
|
|
|
Name: pr.BaseBranch,
|
|
|
|
Name: pr.BaseBranch,
|
|
|
|
Ref: pr.BaseBranch,
|
|
|
|
Ref: pr.BaseBranch,
|
|
|
|
RepoID: pr.BaseRepoID,
|
|
|
|
RepoID: pr.BaseRepoID,
|
|
|
|
Repository: pr.BaseRepo.innerAPIFormat(e, AccessModeNone, false),
|
|
|
|
Repository: pr.BaseRepo.innerAPIFormat(e, AccessModeNone, false),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
baseCommit, err = baseBranch.GetCommit()
|
|
|
|
Head: &api.PRBranchInfo{
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
if git.IsErrNotExist(err) {
|
|
|
|
|
|
|
|
apiBaseBranchInfo.Sha = ""
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.Error("GetCommit[%s]: %v", baseBranch.Name, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
apiBaseBranchInfo.Sha = baseCommit.ID.String()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
apiPullRequest.Base = apiBaseBranchInfo
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if pr.HeadRepo != nil {
|
|
|
|
|
|
|
|
headBranch, err = pr.HeadRepo.GetBranch(pr.HeadBranch)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
if git.IsErrBranchNotExist(err) {
|
|
|
|
|
|
|
|
apiPullRequest.Head = nil
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.Error("GetBranch[%s]: %v", pr.HeadBranch, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
apiHeadBranchInfo := &api.PRBranchInfo{
|
|
|
|
|
|
|
|
Name: pr.HeadBranch,
|
|
|
|
|
|
|
|
Ref: pr.HeadBranch,
|
|
|
|
|
|
|
|
RepoID: pr.HeadRepoID,
|
|
|
|
|
|
|
|
Repository: pr.HeadRepo.innerAPIFormat(e, AccessModeNone, false),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
headCommit, err = headBranch.GetCommit()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
if git.IsErrNotExist(err) {
|
|
|
|
|
|
|
|
apiHeadBranchInfo.Sha = ""
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.Error("GetCommit[%s]: %v", headBranch.Name, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
apiHeadBranchInfo.Sha = headCommit.ID.String()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
apiPullRequest.Head = apiHeadBranchInfo
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
apiPullRequest.Head = &api.PRBranchInfo{
|
|
|
|
|
|
|
|
Name: pr.HeadBranch,
|
|
|
|
Name: pr.HeadBranch,
|
|
|
|
Ref: fmt.Sprintf("refs/pull/%d/head", pr.Index),
|
|
|
|
Ref: fmt.Sprintf("refs/pull/%d/head", pr.Index),
|
|
|
|
RepoID: -1,
|
|
|
|
RepoID: -1,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if pr.Status != PullRequestStatusChecking {
|
|
|
|
if pr.Status != PullRequestStatusChecking {
|
|
|
@ -546,33 +527,78 @@ func (pr *PullRequest) apiFormat(e Engine) *api.PullRequest {
|
|
|
|
apiPullRequest.MergedBy = pr.Merger.APIFormat()
|
|
|
|
apiPullRequest.MergedBy = pr.Merger.APIFormat()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return apiPullRequest
|
|
|
|
baseRepoPath := pr.BaseRepo.repoPath(e)
|
|
|
|
}
|
|
|
|
baseGitRepo, err := git.OpenRepository(baseRepoPath)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error("OpenRepository[%s]: %v", baseRepoPath, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer baseGitRepo.Close()
|
|
|
|
|
|
|
|
|
|
|
|
func (pr *PullRequest) getHeadRepo(e Engine) (err error) {
|
|
|
|
baseBranch, err = baseGitRepo.GetBranch(pr.BaseBranch)
|
|
|
|
pr.HeadRepo, err = getRepositoryByID(e, pr.HeadRepoID)
|
|
|
|
if err != nil && !git.IsErrBranchNotExist(err) {
|
|
|
|
if err != nil && !IsErrRepoNotExist(err) {
|
|
|
|
log.Error("GetBranch[%s]: %v", pr.BaseBranch, err)
|
|
|
|
return fmt.Errorf("getRepositoryByID(head): %v", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GetHeadRepo loads the head repository
|
|
|
|
if err == nil {
|
|
|
|
func (pr *PullRequest) GetHeadRepo() error {
|
|
|
|
baseCommit, err = baseBranch.GetCommit()
|
|
|
|
return pr.getHeadRepo(x)
|
|
|
|
if err != nil && !git.IsErrNotExist(err) {
|
|
|
|
}
|
|
|
|
log.Error("GetCommit[%s]: %v", baseBranch.Name, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// GetBaseRepo loads the target repository
|
|
|
|
if err == nil {
|
|
|
|
func (pr *PullRequest) GetBaseRepo() (err error) {
|
|
|
|
apiPullRequest.Base.Sha = baseCommit.ID.String()
|
|
|
|
if pr.BaseRepo != nil {
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pr.BaseRepo, err = GetRepositoryByID(pr.BaseRepoID)
|
|
|
|
if pr.HeadRepo != nil {
|
|
|
|
if err != nil {
|
|
|
|
apiPullRequest.Head.RepoID = pr.HeadRepo.ID
|
|
|
|
return fmt.Errorf("GetRepositoryByID(base): %v", err)
|
|
|
|
apiPullRequest.Head.Repository = pr.HeadRepo.innerAPIFormat(e, AccessModeNone, false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var headGitRepo *git.Repository
|
|
|
|
|
|
|
|
if pr.HeadRepoID == pr.BaseRepoID {
|
|
|
|
|
|
|
|
headGitRepo = baseGitRepo
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
headRepoPath := pr.HeadRepo.repoPath(e)
|
|
|
|
|
|
|
|
headGitRepo, err = git.OpenRepository(headRepoPath)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
log.Error("OpenRepository[%s]: %v", headRepoPath, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer headGitRepo.Close()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
headBranch, err = headGitRepo.GetBranch(pr.HeadBranch)
|
|
|
|
|
|
|
|
if err != nil && !git.IsErrBranchNotExist(err) {
|
|
|
|
|
|
|
|
log.Error("GetBranch[%s]: %v", pr.HeadBranch, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if git.IsErrBranchNotExist(err) {
|
|
|
|
|
|
|
|
headCommitID, err := headGitRepo.GetRefCommitID(apiPullRequest.Head.Ref)
|
|
|
|
|
|
|
|
if err != nil && !git.IsErrNotExist(err) {
|
|
|
|
|
|
|
|
log.Error("GetCommit[%s]: %v", headBranch.Name, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
apiPullRequest.Head.Sha = headCommitID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
commit, err := headBranch.GetCommit()
|
|
|
|
|
|
|
|
if err != nil && !git.IsErrNotExist(err) {
|
|
|
|
|
|
|
|
log.Error("GetCommit[%s]: %v", headBranch.Name, err)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
apiPullRequest.Head.Ref = pr.HeadBranch
|
|
|
|
|
|
|
|
apiPullRequest.Head.Sha = commit.ID.String()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
|
|
|
|
return apiPullRequest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// IsChecking returns true if this pull request is still checking conflict.
|
|
|
|
// IsChecking returns true if this pull request is still checking conflict.
|
|
|
@ -587,7 +613,7 @@ func (pr *PullRequest) CanAutoMerge() bool {
|
|
|
|
|
|
|
|
|
|
|
|
// GetLastCommitStatus returns the last commit status for this pull request.
|
|
|
|
// GetLastCommitStatus returns the last commit status for this pull request.
|
|
|
|
func (pr *PullRequest) GetLastCommitStatus() (status *CommitStatus, err error) {
|
|
|
|
func (pr *PullRequest) GetLastCommitStatus() (status *CommitStatus, err error) {
|
|
|
|
if err = pr.GetHeadRepo(); err != nil {
|
|
|
|
if err = pr.LoadHeadRepo(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -641,8 +667,8 @@ func (pr *PullRequest) CheckUserAllowedToMerge(doer *User) (err error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if pr.BaseRepo == nil {
|
|
|
|
if pr.BaseRepo == nil {
|
|
|
|
if err = pr.GetBaseRepo(); err != nil {
|
|
|
|
if err = pr.LoadBaseRepo(); err != nil {
|
|
|
|
return fmt.Errorf("GetBaseRepo: %v", err)
|
|
|
|
return fmt.Errorf("LoadBaseRepo: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -921,7 +947,7 @@ func (pr *PullRequest) GetWorkInProgressPrefix() string {
|
|
|
|
// IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head
|
|
|
|
// IsHeadEqualWithBranch returns if the commits of branchName are available in pull request head
|
|
|
|
func (pr *PullRequest) IsHeadEqualWithBranch(branchName string) (bool, error) {
|
|
|
|
func (pr *PullRequest) IsHeadEqualWithBranch(branchName string) (bool, error) {
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
if err = pr.GetBaseRepo(); err != nil {
|
|
|
|
if err = pr.LoadBaseRepo(); err != nil {
|
|
|
|
return false, err
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
|
|
|
|
baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
|
|
|
@ -933,9 +959,12 @@ func (pr *PullRequest) IsHeadEqualWithBranch(branchName string) (bool, error) {
|
|
|
|
return false, err
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err = pr.GetHeadRepo(); err != nil {
|
|
|
|
if err = pr.LoadHeadRepo(); err != nil {
|
|
|
|
return false, err
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if pr.HeadRepo == nil {
|
|
|
|
|
|
|
|
return false, ErrHeadRepoMissed{pr.ID, pr.HeadRepoID}
|
|
|
|
|
|
|
|
}
|
|
|
|
headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
|
|
|
|
headGitRepo, err := git.OpenRepository(pr.HeadRepo.RepoPath())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
return false, err
|
|
|
|