@ -330,25 +330,37 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
repo := ctx . Repo . Repository
repo := ctx . Repo . Repository
pull := issue . PullRequest
pull := issue . PullRequest
var err error
if err := pull . GetHeadRepo ( ) ; err != nil {
if err = pull . GetHeadRepo ( ) ; err != nil {
ctx . ServerError ( "GetHeadRepo" , err )
ctx . ServerError ( "GetHeadRepo" , err )
return nil
return nil
}
}
if err := pull . GetBaseRepo ( ) ; err != nil {
ctx . ServerError ( "GetBaseRepo" , err )
return nil
}
setMergeTarget ( ctx , pull )
setMergeTarget ( ctx , pull )
if err = pull . LoadProtectedBranch ( ) ; err != nil {
if err : = pull . LoadProtectedBranch ( ) ; err != nil {
ctx . ServerError ( "GetLatestCommitStatus" , err )
ctx . ServerError ( "GetLatestCommitStatus" , err )
return nil
return nil
}
}
ctx . Data [ "EnableStatusCheck" ] = pull . ProtectedBranch != nil && pull . ProtectedBranch . EnableStatusCheck
ctx . Data [ "EnableStatusCheck" ] = pull . ProtectedBranch != nil && pull . ProtectedBranch . EnableStatusCheck
var headGitRepo * git . Repository
baseGitRepo , err := git . OpenRepository ( pull . BaseRepo . RepoPath ( ) )
if err != nil {
ctx . ServerError ( "OpenRepository" , err )
return nil
}
defer baseGitRepo . Close ( )
var headBranchExist bool
var headBranchExist bool
var headBranchSha string
// HeadRepo may be missing
// HeadRepo may be missing
if pull . HeadRepo != nil {
if pull . HeadRepo != nil {
headGitRepo , err = git . OpenRepository ( pull . HeadRepo . RepoPath ( ) )
var err error
headGitRepo , err := git . OpenRepository ( pull . HeadRepo . RepoPath ( ) )
if err != nil {
if err != nil {
ctx . ServerError ( "OpenRepository" , err )
ctx . ServerError ( "OpenRepository" , err )
return nil
return nil
@ -358,46 +370,53 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
headBranchExist = headGitRepo . IsBranchExist ( pull . HeadBranch )
headBranchExist = headGitRepo . IsBranchExist ( pull . HeadBranch )
if headBranchExist {
if headBranchExist {
sha , err : = headGitRepo . GetBranchCommitID ( pull . HeadBranch )
headBranchSha , err = headGitRepo . GetBranchCommitID ( pull . HeadBranch )
if err != nil {
if err != nil {
ctx . ServerError ( "GetBranchCommitID" , err )
ctx . ServerError ( "GetBranchCommitID" , err )
return nil
return nil
}
}
}
}
commitStatuses , err := models . GetLatestCommitStatus ( repo , sha , 0 )
sha , err := baseGitRepo . GetRefCommitID ( pull . GetGitRefName ( ) )
if err != nil {
if err != nil {
ctx . ServerError ( "GetLatestCommitStatus" , err )
ctx . ServerError ( fmt . Sprintf ( "GetRefCommitID(%s)" , pull . GetGitRefName ( ) ) , err )
return nil
return nil
}
}
if len ( commitStatuses ) > 0 {
ctx . Data [ "LatestCommitStatuses" ] = commitStatuses
ctx . Data [ "LatestCommitStatus" ] = models . CalcCommitStatus ( commitStatuses )
}
if pull . ProtectedBranch != nil && pull . ProtectedBranch . EnableStatusCheck {
commitStatuses , err := models . GetLatestCommitStatus ( repo , sha , 0 )
ctx . Data [ "is_context_required" ] = func ( context string ) bool {
if err != nil {
for _ , c := range pull . ProtectedBranch . StatusCheckContexts {
ctx . ServerError ( "GetLatestCommitStatus" , err )
if c == context {
return nil
return true
}
}
if len ( commitStatuses ) > 0 {
}
ctx . Data [ "LatestCommitStatuses" ] = commitStatuses
return false
ctx . Data [ "LatestCommitStatus" ] = models . CalcCommitStatus ( commitStatuses )
}
if pull . ProtectedBranch != nil && pull . ProtectedBranch . EnableStatusCheck {
ctx . Data [ "is_context_required" ] = func ( context string ) bool {
for _ , c := range pull . ProtectedBranch . StatusCheckContexts {
if c == context {
return true
}
}
ctx . Data [ "IsRequiredStatusCheckSuccess" ] = pull_service . IsCommitStatusContextSuccess ( commitStatuses , pull . ProtectedBranch . StatusCheckContexts )
}
}
return false
}
}
ctx . Data [ "IsRequiredStatusCheckSuccess" ] = pull_service . IsCommitStatusContextSuccess ( commitStatuses , pull . ProtectedBranch . StatusCheckContexts )
}
}
if pull . HeadRepo == nil || ! headBranchExist {
ctx . Data [ "HeadBranchMovedOn" ] = headBranchSha != sha
ctx . Data [ "HeadBranchCommitID" ] = headBranchSha
ctx . Data [ "PullHeadCommitID" ] = sha
if pull . HeadRepo == nil || ! headBranchExist || headBranchSha != sha {
ctx . Data [ "IsPullRequestBroken" ] = true
ctx . Data [ "IsPullRequestBroken" ] = true
ctx . Data [ "HeadTarget" ] = "deleted"
ctx . Data [ "HeadTarget" ] = "deleted"
ctx . Data [ "NumCommits" ] = 0
ctx . Data [ "NumFiles" ] = 0
return nil
}
}
compareInfo , err := head GitRepo. GetCompareInfo ( models . RepoPath ( repo . Owner . Name , repo . Name ) ,
compareInfo , err := baseGitRepo . GetCompareInfo ( pull . BaseRepo . RepoPath ( ) ,
pull . BaseBranch , pull . HeadBranch )
pull . BaseBranch , pull . GetGitRefName ( ) )
if err != nil {
if err != nil {
if strings . Contains ( err . Error ( ) , "fatal: Not a valid object name" ) {
if strings . Contains ( err . Error ( ) , "fatal: Not a valid object name" ) {
ctx . Data [ "IsPullRequestBroken" ] = true
ctx . Data [ "IsPullRequestBroken" ] = true