@ -51,29 +51,31 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
}
}
apiPullRequest := & api . PullRequest {
apiPullRequest := & api . PullRequest {
ID : pr . ID ,
ID : pr . ID ,
URL : pr . Issue . HTMLURL ( ) ,
URL : pr . Issue . HTMLURL ( ) ,
Index : pr . Index ,
Index : pr . Index ,
Poster : apiIssue . Poster ,
Poster : apiIssue . Poster ,
Title : apiIssue . Title ,
Title : apiIssue . Title ,
Body : apiIssue . Body ,
Body : apiIssue . Body ,
Labels : apiIssue . Labels ,
Labels : apiIssue . Labels ,
Milestone : apiIssue . Milestone ,
Milestone : apiIssue . Milestone ,
Assignee : apiIssue . Assignee ,
Assignee : apiIssue . Assignee ,
Assignees : apiIssue . Assignees ,
Assignees : apiIssue . Assignees ,
State : apiIssue . State ,
State : apiIssue . State ,
IsLocked : apiIssue . IsLocked ,
Draft : pr . IsWorkInProgress ( ctx ) ,
Comments : apiIssue . Comments ,
IsLocked : apiIssue . IsLocked ,
HTMLURL : pr . Issue . HTMLURL ( ) ,
Comments : apiIssue . Comments ,
DiffURL : pr . Issue . DiffURL ( ) ,
ReviewComments : pr . GetReviewCommentsCount ( ctx ) ,
PatchURL : pr . Issue . PatchURL ( ) ,
HTMLURL : pr . Issue . HTMLURL ( ) ,
HasMerged : pr . HasMerged ,
DiffURL : pr . Issue . DiffURL ( ) ,
MergeBase : pr . MergeBase ,
PatchURL : pr . Issue . PatchURL ( ) ,
Mergeable : pr . Mergeable ( ctx ) ,
HasMerged : pr . HasMerged ,
Deadline : apiIssue . Deadline ,
MergeBase : pr . MergeBase ,
Created : pr . Issue . CreatedUnix . AsTimePtr ( ) ,
Mergeable : pr . Mergeable ( ctx ) ,
Updated : pr . Issue . UpdatedUnix . AsTimePtr ( ) ,
Deadline : apiIssue . Deadline ,
PinOrder : apiIssue . PinOrder ,
Created : pr . Issue . CreatedUnix . AsTimePtr ( ) ,
Updated : pr . Issue . UpdatedUnix . AsTimePtr ( ) ,
PinOrder : apiIssue . PinOrder ,
AllowMaintainerEdit : pr . AllowMaintainerEdit ,
AllowMaintainerEdit : pr . AllowMaintainerEdit ,
@ -168,6 +170,12 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
return nil
return nil
}
}
// Outer scope variables to be used in diff calculation
var (
startCommitID string
endCommitID string
)
if git . IsErrBranchNotExist ( err ) {
if git . IsErrBranchNotExist ( err ) {
headCommitID , err := headGitRepo . GetRefCommitID ( apiPullRequest . Head . Ref )
headCommitID , err := headGitRepo . GetRefCommitID ( apiPullRequest . Head . Ref )
if err != nil && ! git . IsErrNotExist ( err ) {
if err != nil && ! git . IsErrNotExist ( err ) {
@ -176,6 +184,7 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
}
}
if err == nil {
if err == nil {
apiPullRequest . Head . Sha = headCommitID
apiPullRequest . Head . Sha = headCommitID
endCommitID = headCommitID
}
}
} else {
} else {
commit , err := headBranch . GetCommit ( )
commit , err := headBranch . GetCommit ( )
@ -186,8 +195,17 @@ func ToAPIPullRequest(ctx context.Context, pr *issues_model.PullRequest, doer *u
if err == nil {
if err == nil {
apiPullRequest . Head . Ref = pr . HeadBranch
apiPullRequest . Head . Ref = pr . HeadBranch
apiPullRequest . Head . Sha = commit . ID . String ( )
apiPullRequest . Head . Sha = commit . ID . String ( )
endCommitID = commit . ID . String ( )
}
}
}
}
// Calculate diff
startCommitID = pr . MergeBase
apiPullRequest . ChangedFiles , apiPullRequest . Additions , apiPullRequest . Deletions , err = gitRepo . GetDiffShortStat ( startCommitID , endCommitID )
if err != nil {
log . Error ( "GetDiffShortStat: %v" , err )
}
}
}
if len ( apiPullRequest . Head . Sha ) == 0 && len ( apiPullRequest . Head . Ref ) != 0 {
if len ( apiPullRequest . Head . Sha ) == 0 && len ( apiPullRequest . Head . Ref ) != 0 {