Skip to content

Commit 53276d3

Browse files
wolfogreGiteaBot
andauthored
Check ctx.Written() for GetActionIssue (#25698) (#25714)
Backport #25698. Fix #25697. Just avoid panic, maybe there's another bug to trigger this case. Co-authored-by: Giteabot <[email protected]>
1 parent e6801df commit 53276d3

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

routers/web/repo/issue.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,7 @@ func GetActionIssue(ctx *context.Context) *issues_model.Issue {
18881888
return nil
18891889
}
18901890
if err = issue.LoadAttributes(ctx); err != nil {
1891-
ctx.ServerError("LoadAttributes", nil)
1891+
ctx.ServerError("LoadAttributes", err)
18921892
return nil
18931893
}
18941894
return issue
@@ -3185,6 +3185,9 @@ func filterXRefComments(ctx *context.Context, issue *issues_model.Issue) error {
31853185
// GetIssueAttachments returns attachments for the issue
31863186
func GetIssueAttachments(ctx *context.Context) {
31873187
issue := GetActionIssue(ctx)
3188+
if ctx.Written() {
3189+
return
3190+
}
31883191
attachments := make([]*api.Attachment, len(issue.Attachments))
31893192
for i := 0; i < len(issue.Attachments); i++ {
31903193
attachments[i] = convert.ToAttachment(issue.Attachments[i])

routers/web/repo/issue_content_history.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
// GetContentHistoryOverview get overview
2525
func GetContentHistoryOverview(ctx *context.Context) {
2626
issue := GetActionIssue(ctx)
27-
if issue == nil {
27+
if ctx.Written() {
2828
return
2929
}
3030

@@ -43,11 +43,11 @@ func GetContentHistoryOverview(ctx *context.Context) {
4343
// GetContentHistoryList get list
4444
func GetContentHistoryList(ctx *context.Context) {
4545
issue := GetActionIssue(ctx)
46-
commentID := ctx.FormInt64("comment_id")
47-
if issue == nil {
46+
if ctx.Written() {
4847
return
4948
}
5049

50+
commentID := ctx.FormInt64("comment_id")
5151
items, _ := issues_model.FetchIssueContentHistoryList(ctx, issue.ID, commentID)
5252

5353
// render history list to HTML for frontend dropdown items: (name, value)
@@ -113,7 +113,7 @@ func canSoftDeleteContentHistory(ctx *context.Context, issue *issues_model.Issue
113113
// GetContentHistoryDetail get detail
114114
func GetContentHistoryDetail(ctx *context.Context) {
115115
issue := GetActionIssue(ctx)
116-
if issue == nil {
116+
if ctx.Written() {
117117
return
118118
}
119119

@@ -179,7 +179,7 @@ func GetContentHistoryDetail(ctx *context.Context) {
179179
// SoftDeleteContentHistory soft delete
180180
func SoftDeleteContentHistory(ctx *context.Context) {
181181
issue := GetActionIssue(ctx)
182-
if issue == nil {
182+
if ctx.Written() {
183183
return
184184
}
185185

routers/web/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,10 +1455,10 @@ func DownloadPullDiffOrPatch(ctx *context.Context, patch bool) {
14551455
// UpdatePullRequestTarget change pull request's target branch
14561456
func UpdatePullRequestTarget(ctx *context.Context) {
14571457
issue := GetActionIssue(ctx)
1458-
pr := issue.PullRequest
14591458
if ctx.Written() {
14601459
return
14611460
}
1461+
pr := issue.PullRequest
14621462
if !issue.IsPull {
14631463
ctx.Error(http.StatusNotFound)
14641464
return

routers/web/repo/pull_review.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ const (
2828
// RenderNewCodeCommentForm will render the form for creating a new review comment
2929
func RenderNewCodeCommentForm(ctx *context.Context) {
3030
issue := GetActionIssue(ctx)
31+
if ctx.Written() {
32+
return
33+
}
3134
if !issue.IsPull {
3235
return
3336
}
@@ -52,10 +55,10 @@ func RenderNewCodeCommentForm(ctx *context.Context) {
5255
func CreateCodeComment(ctx *context.Context) {
5356
form := web.GetForm(ctx).(*forms.CodeCommentForm)
5457
issue := GetActionIssue(ctx)
55-
if !issue.IsPull {
58+
if ctx.Written() {
5659
return
5760
}
58-
if ctx.Written() {
61+
if !issue.IsPull {
5962
return
6063
}
6164

@@ -185,10 +188,10 @@ func renderConversation(ctx *context.Context, comment *issues_model.Comment) {
185188
func SubmitReview(ctx *context.Context) {
186189
form := web.GetForm(ctx).(*forms.SubmitReviewForm)
187190
issue := GetActionIssue(ctx)
188-
if !issue.IsPull {
191+
if ctx.Written() {
189192
return
190193
}
191-
if ctx.Written() {
194+
if !issue.IsPull {
192195
return
193196
}
194197
if ctx.HasError() {

0 commit comments

Comments
 (0)