Skip to content

Commit 24fbf4e

Browse files
authored
1 parent 049e400 commit 24fbf4e

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

routers/web/repo/pull.go

+28-27
Original file line numberDiff line numberDiff line change
@@ -299,51 +299,51 @@ func ForkPost(ctx *context.Context) {
299299
ctx.Redirect(ctxUser.HomeLink() + "/" + url.PathEscape(repo.Name))
300300
}
301301

302-
func checkPullInfo(ctx *context.Context) *issues_model.Issue {
302+
func getPullInfo(ctx *context.Context) (issue *issues_model.Issue, ok bool) {
303303
issue, err := issues_model.GetIssueByIndex(ctx, ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
304304
if err != nil {
305305
if issues_model.IsErrIssueNotExist(err) {
306306
ctx.NotFound("GetIssueByIndex", err)
307307
} else {
308308
ctx.ServerError("GetIssueByIndex", err)
309309
}
310-
return nil
310+
return nil, false
311311
}
312312
if err = issue.LoadPoster(ctx); err != nil {
313313
ctx.ServerError("LoadPoster", err)
314-
return nil
314+
return nil, false
315315
}
316316
if err := issue.LoadRepo(ctx); err != nil {
317317
ctx.ServerError("LoadRepo", err)
318-
return nil
318+
return nil, false
319319
}
320320
ctx.Data["Title"] = fmt.Sprintf("#%d - %s", issue.Index, issue.Title)
321321
ctx.Data["Issue"] = issue
322322

323323
if !issue.IsPull {
324324
ctx.NotFound("ViewPullCommits", nil)
325-
return nil
325+
return nil, false
326326
}
327327

328328
if err = issue.LoadPullRequest(ctx); err != nil {
329329
ctx.ServerError("LoadPullRequest", err)
330-
return nil
330+
return nil, false
331331
}
332332

333333
if err = issue.PullRequest.LoadHeadRepo(ctx); err != nil {
334334
ctx.ServerError("LoadHeadRepo", err)
335-
return nil
335+
return nil, false
336336
}
337337

338338
if ctx.IsSigned {
339339
// Update issue-user.
340340
if err = activities_model.SetIssueReadBy(ctx, issue.ID, ctx.Doer.ID); err != nil {
341341
ctx.ServerError("ReadBy", err)
342-
return nil
342+
return nil, false
343343
}
344344
}
345345

346-
return issue
346+
return issue, true
347347
}
348348

349349
func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) {
@@ -361,14 +361,15 @@ func setMergeTarget(ctx *context.Context, pull *issues_model.PullRequest) {
361361

362362
// GetPullDiffStats get Pull Requests diff stats
363363
func GetPullDiffStats(ctx *context.Context) {
364-
issue := checkPullInfo(ctx)
364+
issue, ok := getPullInfo(ctx)
365+
if !ok {
366+
return
367+
}
365368
pull := issue.PullRequest
366369

367370
mergeBaseCommitID := GetMergedBaseCommitID(ctx, issue)
368371

369-
if ctx.Written() {
370-
return
371-
} else if mergeBaseCommitID == "" {
372+
if mergeBaseCommitID == "" {
372373
ctx.NotFound("PullFiles", nil)
373374
return
374375
}
@@ -702,8 +703,8 @@ type pullCommitList struct {
702703

703704
// GetPullCommits get all commits for given pull request
704705
func GetPullCommits(ctx *context.Context) {
705-
issue := checkPullInfo(ctx)
706-
if ctx.Written() {
706+
issue, ok := getPullInfo(ctx)
707+
if !ok {
707708
return
708709
}
709710
resp := &pullCommitList{}
@@ -735,8 +736,8 @@ func ViewPullCommits(ctx *context.Context) {
735736
ctx.Data["PageIsPullList"] = true
736737
ctx.Data["PageIsPullCommits"] = true
737738

738-
issue := checkPullInfo(ctx)
739-
if ctx.Written() {
739+
issue, ok := getPullInfo(ctx)
740+
if !ok {
740741
return
741742
}
742743
pull := issue.PullRequest
@@ -779,8 +780,8 @@ func viewPullFiles(ctx *context.Context, specifiedStartCommit, specifiedEndCommi
779780
ctx.Data["PageIsPullList"] = true
780781
ctx.Data["PageIsPullFiles"] = true
781782

782-
issue := checkPullInfo(ctx)
783-
if ctx.Written() {
783+
issue, ok := getPullInfo(ctx)
784+
if !ok {
784785
return
785786
}
786787
pull := issue.PullRequest
@@ -1016,8 +1017,8 @@ func ViewPullFilesForAllCommitsOfPr(ctx *context.Context) {
10161017

10171018
// UpdatePullRequest merge PR's baseBranch into headBranch
10181019
func UpdatePullRequest(ctx *context.Context) {
1019-
issue := checkPullInfo(ctx)
1020-
if ctx.Written() {
1020+
issue, ok := getPullInfo(ctx)
1021+
if !ok {
10211022
return
10221023
}
10231024
if issue.IsClosed {
@@ -1101,8 +1102,8 @@ func UpdatePullRequest(ctx *context.Context) {
11011102
// MergePullRequest response for merging pull request
11021103
func MergePullRequest(ctx *context.Context) {
11031104
form := web.GetForm(ctx).(*forms.MergePullRequestForm)
1104-
issue := checkPullInfo(ctx)
1105-
if ctx.Written() {
1105+
issue, ok := getPullInfo(ctx)
1106+
if !ok {
11061107
return
11071108
}
11081109

@@ -1308,8 +1309,8 @@ func MergePullRequest(ctx *context.Context) {
13081309

13091310
// CancelAutoMergePullRequest cancels a scheduled pr
13101311
func CancelAutoMergePullRequest(ctx *context.Context) {
1311-
issue := checkPullInfo(ctx)
1312-
if ctx.Written() {
1312+
issue, ok := getPullInfo(ctx)
1313+
if !ok {
13131314
return
13141315
}
13151316

@@ -1447,8 +1448,8 @@ func CompareAndPullRequestPost(ctx *context.Context) {
14471448

14481449
// CleanUpPullRequest responses for delete merged branch when PR has been merged
14491450
func CleanUpPullRequest(ctx *context.Context) {
1450-
issue := checkPullInfo(ctx)
1451-
if ctx.Written() {
1451+
issue, ok := getPullInfo(ctx)
1452+
if !ok {
14521453
return
14531454
}
14541455

routers/web/repo/pull_review.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ type viewedFilesUpdate struct {
259259

260260
func UpdateViewedFiles(ctx *context.Context) {
261261
// Find corresponding PR
262-
issue := checkPullInfo(ctx)
263-
if ctx.Written() {
262+
issue, ok := getPullInfo(ctx)
263+
if !ok {
264264
return
265265
}
266266
pull := issue.PullRequest

0 commit comments

Comments
 (0)