forked from kevadesu/forgejo
[refactor] replace int with httpStatusCodes (#15282)
* replace "200" (int) with "http.StatusOK" (const) * ctx.Error & ctx.HTML * ctx.JSON Part1 * ctx.JSON Part2 * ctx.JSON Part3
This commit is contained in:
parent
e9fba18a26
commit
16dea6cebd
64 changed files with 504 additions and 441 deletions
|
@ -393,7 +393,7 @@ func Issues(ctx *context.Context) {
|
|||
|
||||
ctx.Data["CanWriteIssuesOrPulls"] = ctx.Repo.CanWriteIssuesOrPulls(isPullList)
|
||||
|
||||
ctx.HTML(200, tplIssues)
|
||||
ctx.HTML(http.StatusOK, tplIssues)
|
||||
}
|
||||
|
||||
// RetrieveRepoMilestonesAndAssignees find all the milestones and assignees of a repository
|
||||
|
@ -819,7 +819,7 @@ func NewIssue(ctx *context.Context) {
|
|||
|
||||
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypeIssues)
|
||||
|
||||
ctx.HTML(200, tplIssueNew)
|
||||
ctx.HTML(http.StatusOK, tplIssueNew)
|
||||
}
|
||||
|
||||
// NewIssueChooseTemplate render creating issue from template page
|
||||
|
@ -832,7 +832,7 @@ func NewIssueChooseTemplate(ctx *context.Context) {
|
|||
ctx.Data["NewIssueChooseTemplate"] = len(issueTemplates) > 0
|
||||
ctx.Data["IssueTemplates"] = issueTemplates
|
||||
|
||||
ctx.HTML(200, tplIssueChoose)
|
||||
ctx.HTML(http.StatusOK, tplIssueChoose)
|
||||
}
|
||||
|
||||
// ValidateRepoMetas check and returns repository's meta informations
|
||||
|
@ -960,7 +960,7 @@ func NewIssuePost(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if ctx.HasError() {
|
||||
ctx.HTML(200, tplIssueNew)
|
||||
ctx.HTML(http.StatusOK, tplIssueNew)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -981,7 +981,7 @@ func NewIssuePost(ctx *context.Context) {
|
|||
|
||||
if err := issue_service.NewIssue(repo, issue, labelIDs, attachments, assigneeIDs); err != nil {
|
||||
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
|
||||
ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
|
||||
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
|
||||
return
|
||||
}
|
||||
ctx.ServerError("NewIssue", err)
|
||||
|
@ -1578,7 +1578,7 @@ func ViewIssue(ctx *context.Context) {
|
|||
ctx.Data["IsRepoAdmin"] = ctx.IsSigned && (ctx.Repo.IsAdmin() || ctx.User.IsAdmin)
|
||||
ctx.Data["LockReasons"] = setting.Repository.Issue.LockReasons
|
||||
ctx.Data["RefEndName"] = git.RefEndName(issue.Ref)
|
||||
ctx.HTML(200, tplIssueView)
|
||||
ctx.HTML(http.StatusOK, tplIssueView)
|
||||
}
|
||||
|
||||
// GetActionIssue will return the issue which is used in the context.
|
||||
|
@ -1650,13 +1650,13 @@ func UpdateIssueTitle(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
title := ctx.QueryTrim("title")
|
||||
if len(title) == 0 {
|
||||
ctx.Error(204)
|
||||
ctx.Error(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1665,7 +1665,7 @@ func UpdateIssueTitle(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"title": issue.Title,
|
||||
})
|
||||
}
|
||||
|
@ -1678,7 +1678,7 @@ func UpdateIssueRef(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if !ctx.IsSigned || (!issue.IsPoster(ctx.User.ID) && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) || issue.IsPull {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1689,7 +1689,7 @@ func UpdateIssueRef(ctx *context.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ref": ref,
|
||||
})
|
||||
}
|
||||
|
@ -1702,7 +1702,7 @@ func UpdateIssueContent(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if !ctx.IsSigned || (ctx.User.ID != issue.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)) {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1717,7 +1717,7 @@ func UpdateIssueContent(ctx *context.Context) {
|
|||
ctx.ServerError("UpdateAttachments", err)
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"content": string(markdown.Render([]byte(issue.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
|
||||
"attachments": attachmentsHTML(ctx, issue.Attachments, issue.Content),
|
||||
})
|
||||
|
@ -1743,7 +1743,7 @@ func UpdateIssueMilestone(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
}
|
||||
|
@ -1789,7 +1789,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
}
|
||||
|
@ -1914,7 +1914,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
}
|
||||
|
@ -1954,7 +1954,7 @@ func UpdateIssueStatus(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"ok": true,
|
||||
})
|
||||
}
|
||||
|
@ -1986,7 +1986,7 @@ func NewComment(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -2109,17 +2109,17 @@ func UpdateCommentContent(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
} else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
|
||||
ctx.Error(204)
|
||||
ctx.Error(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
oldContent := comment.Content
|
||||
comment.Content = ctx.Query("content")
|
||||
if len(comment.Content) == 0 {
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"content": "",
|
||||
})
|
||||
return
|
||||
|
@ -2134,7 +2134,7 @@ func UpdateCommentContent(ctx *context.Context) {
|
|||
ctx.ServerError("UpdateAttachments", err)
|
||||
}
|
||||
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"content": string(markdown.Render([]byte(comment.Content), ctx.Query("context"), ctx.Repo.Repository.ComposeMetas())),
|
||||
"attachments": attachmentsHTML(ctx, comment.Attachments, comment.Content),
|
||||
})
|
||||
|
@ -2154,10 +2154,10 @@ func DeleteComment(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
} else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
|
||||
ctx.Error(204)
|
||||
ctx.Error(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -2196,7 +2196,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -2244,7 +2244,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if len(issue.Reactions) == 0 {
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"empty": true,
|
||||
"html": "",
|
||||
})
|
||||
|
@ -2260,7 +2260,7 @@ func ChangeIssueReaction(ctx *context.Context) {
|
|||
ctx.ServerError("ChangeIssueReaction.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"html": html,
|
||||
})
|
||||
}
|
||||
|
@ -2298,10 +2298,10 @@ func ChangeCommentReaction(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
ctx.Error(403)
|
||||
ctx.Error(http.StatusForbidden)
|
||||
return
|
||||
} else if comment.Type != models.CommentTypeComment && comment.Type != models.CommentTypeCode {
|
||||
ctx.Error(204)
|
||||
ctx.Error(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -2344,7 +2344,7 @@ func ChangeCommentReaction(ctx *context.Context) {
|
|||
}
|
||||
|
||||
if len(comment.Reactions) == 0 {
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"empty": true,
|
||||
"html": "",
|
||||
})
|
||||
|
@ -2360,7 +2360,7 @@ func ChangeCommentReaction(ctx *context.Context) {
|
|||
ctx.ServerError("ChangeCommentReaction.HTMLString", err)
|
||||
return
|
||||
}
|
||||
ctx.JSON(200, map[string]interface{}{
|
||||
ctx.JSON(http.StatusOK, map[string]interface{}{
|
||||
"html": html,
|
||||
})
|
||||
}
|
||||
|
@ -2406,7 +2406,7 @@ func GetIssueAttachments(ctx *context.Context) {
|
|||
for i := 0; i < len(issue.Attachments); i++ {
|
||||
attachments[i] = convert.ToReleaseAttachment(issue.Attachments[i])
|
||||
}
|
||||
ctx.JSON(200, attachments)
|
||||
ctx.JSON(http.StatusOK, attachments)
|
||||
}
|
||||
|
||||
// GetCommentAttachments returns attachments for the comment
|
||||
|
@ -2426,7 +2426,7 @@ func GetCommentAttachments(ctx *context.Context) {
|
|||
attachments = append(attachments, convert.ToReleaseAttachment(comment.Attachments[i]))
|
||||
}
|
||||
}
|
||||
ctx.JSON(200, attachments)
|
||||
ctx.JSON(http.StatusOK, attachments)
|
||||
}
|
||||
|
||||
func updateAttachments(item interface{}, files []string) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue