@@ -299,51 +299,51 @@ func ForkPost(ctx *context.Context) {
299
299
ctx .Redirect (ctxUser .HomeLink () + "/" + url .PathEscape (repo .Name ))
300
300
}
301
301
302
- func checkPullInfo (ctx * context.Context ) * issues_model.Issue {
302
+ func getPullInfo (ctx * context.Context ) ( issue * issues_model.Issue , ok bool ) {
303
303
issue , err := issues_model .GetIssueByIndex (ctx , ctx .Repo .Repository .ID , ctx .ParamsInt64 (":index" ))
304
304
if err != nil {
305
305
if issues_model .IsErrIssueNotExist (err ) {
306
306
ctx .NotFound ("GetIssueByIndex" , err )
307
307
} else {
308
308
ctx .ServerError ("GetIssueByIndex" , err )
309
309
}
310
- return nil
310
+ return nil , false
311
311
}
312
312
if err = issue .LoadPoster (ctx ); err != nil {
313
313
ctx .ServerError ("LoadPoster" , err )
314
- return nil
314
+ return nil , false
315
315
}
316
316
if err := issue .LoadRepo (ctx ); err != nil {
317
317
ctx .ServerError ("LoadRepo" , err )
318
- return nil
318
+ return nil , false
319
319
}
320
320
ctx .Data ["Title" ] = fmt .Sprintf ("#%d - %s" , issue .Index , issue .Title )
321
321
ctx .Data ["Issue" ] = issue
322
322
323
323
if ! issue .IsPull {
324
324
ctx .NotFound ("ViewPullCommits" , nil )
325
- return nil
325
+ return nil , false
326
326
}
327
327
328
328
if err = issue .LoadPullRequest (ctx ); err != nil {
329
329
ctx .ServerError ("LoadPullRequest" , err )
330
- return nil
330
+ return nil , false
331
331
}
332
332
333
333
if err = issue .PullRequest .LoadHeadRepo (ctx ); err != nil {
334
334
ctx .ServerError ("LoadHeadRepo" , err )
335
- return nil
335
+ return nil , false
336
336
}
337
337
338
338
if ctx .IsSigned {
339
339
// Update issue-user.
340
340
if err = activities_model .SetIssueReadBy (ctx , issue .ID , ctx .Doer .ID ); err != nil {
341
341
ctx .ServerError ("ReadBy" , err )
342
- return nil
342
+ return nil , false
343
343
}
344
344
}
345
345
346
- return issue
346
+ return issue , true
347
347
}
348
348
349
349
func setMergeTarget (ctx * context.Context , pull * issues_model.PullRequest ) {
@@ -361,14 +361,15 @@ func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) {
361
361
362
362
// GetPullDiffStats get Pull Requests diff stats
363
363
func GetPullDiffStats (ctx * context.Context ) {
364
- issue := checkPullInfo (ctx )
364
+ issue , ok := getPullInfo (ctx )
365
+ if ! ok {
366
+ return
367
+ }
365
368
pull := issue .PullRequest
366
369
367
370
mergeBaseCommitID := GetMergedBaseCommitID (ctx , issue )
368
371
369
- if ctx .Written () {
370
- return
371
- } else if mergeBaseCommitID == "" {
372
+ if mergeBaseCommitID == "" {
372
373
ctx .NotFound ("PullFiles" , nil )
373
374
return
374
375
}
@@ -702,8 +703,8 @@ type pullCommitList struct {
702
703
703
704
// GetPullCommits get all commits for given pull request
704
705
func GetPullCommits (ctx * context.Context ) {
705
- issue := checkPullInfo (ctx )
706
- if ctx . Written () {
706
+ issue , ok := getPullInfo (ctx )
707
+ if ! ok {
707
708
return
708
709
}
709
710
resp := & pullCommitList {}
@@ -735,8 +736,8 @@ func ViewPullCommits(ctx *context.Context) {
735
736
ctx .Data ["PageIsPullList" ] = true
736
737
ctx .Data ["PageIsPullCommits" ] = true
737
738
738
- issue := checkPullInfo (ctx )
739
- if ctx . Written () {
739
+ issue , ok := getPullInfo (ctx )
740
+ if ! ok {
740
741
return
741
742
}
742
743
pull := issue .PullRequest
@@ -779,8 +780,8 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
779
780
ctx .Data ["PageIsPullList" ] = true
780
781
ctx .Data ["PageIsPullFiles" ] = true
781
782
782
- issue := checkPullInfo (ctx )
783
- if ctx . Written () {
783
+ issue , ok := getPullInfo (ctx )
784
+ if ! ok {
784
785
return
785
786
}
786
787
pull := issue .PullRequest
@@ -1016,8 +1017,8 @@ func ViewPullFilesForAllCommitsOfPr(ctx *context.Context) {
1016
1017
1017
1018
// UpdatePullRequest merge PR's baseBranch into headBranch
1018
1019
func UpdatePullRequest (ctx * context.Context ) {
1019
- issue := checkPullInfo (ctx )
1020
- if ctx . Written () {
1020
+ issue , ok := getPullInfo (ctx )
1021
+ if ! ok {
1021
1022
return
1022
1023
}
1023
1024
if issue .IsClosed {
@@ -1101,8 +1102,8 @@ func UpdatePullRequest(ctx *context.Context) {
1101
1102
// MergePullRequest response for merging pull request
1102
1103
func MergePullRequest (ctx * context.Context ) {
1103
1104
form := web .GetForm (ctx ).(* forms.MergePullRequestForm )
1104
- issue := checkPullInfo (ctx )
1105
- if ctx . Written () {
1105
+ issue , ok := getPullInfo (ctx )
1106
+ if ! ok {
1106
1107
return
1107
1108
}
1108
1109
@@ -1308,8 +1309,8 @@ func MergePullRequest(ctx *context.Context) {
1308
1309
1309
1310
// CancelAutoMergePullRequest cancels a scheduled pr
1310
1311
func CancelAutoMergePullRequest (ctx * context.Context ) {
1311
- issue := checkPullInfo (ctx )
1312
- if ctx . Written () {
1312
+ issue , ok := getPullInfo (ctx )
1313
+ if ! ok {
1313
1314
return
1314
1315
}
1315
1316
@@ -1447,8 +1448,8 @@ func CompareAndPullRequestPost(ctx *context.Context) {
1447
1448
1448
1449
// CleanUpPullRequest responses for delete merged branch when PR has been merged
1449
1450
func CleanUpPullRequest (ctx * context.Context ) {
1450
- issue := checkPullInfo (ctx )
1451
- if ctx . Written () {
1451
+ issue , ok := getPullInfo (ctx )
1452
+ if ! ok {
1452
1453
return
1453
1454
}
1454
1455
0 commit comments