[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:
6543 2021-04-05 17:30:52 +02:00 committed by GitHub
parent e9fba18a26
commit 16dea6cebd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
64 changed files with 504 additions and 441 deletions

View file

@ -11,6 +11,7 @@ import (
"fmt"
"html"
"io/ioutil"
"net/http"
"path"
"path/filepath"
"strings"
@ -632,7 +633,7 @@ func CompareDiff(ctx *context.Context) {
} else {
ctx.Data["HasPullRequest"] = true
ctx.Data["PullRequest"] = pr
ctx.HTML(200, tplCompareDiff)
ctx.HTML(http.StatusOK, tplCompareDiff)
return
}
@ -660,7 +661,7 @@ func CompareDiff(ctx *context.Context) {
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWrite(models.UnitTypePullRequests)
ctx.HTML(200, tplCompare)
ctx.HTML(http.StatusOK, tplCompare)
}
// ExcerptBlob render blob excerpt contents
@ -679,7 +680,7 @@ func ExcerptBlob(ctx *context.Context) {
chunkSize := gitdiff.BlobExcerptChunkSize
commit, err := gitRepo.GetCommit(commitID)
if err != nil {
ctx.Error(500, "GetCommit")
ctx.Error(http.StatusInternalServerError, "GetCommit")
return
}
section := &gitdiff.DiffSection{
@ -704,7 +705,7 @@ func ExcerptBlob(ctx *context.Context) {
idxRight = lastRight
}
if err != nil {
ctx.Error(500, "getExcerptLines")
ctx.Error(http.StatusInternalServerError, "getExcerptLines")
return
}
if idxRight > lastRight {
@ -735,7 +736,7 @@ func ExcerptBlob(ctx *context.Context) {
ctx.Data["fileName"] = filePath
ctx.Data["AfterCommitID"] = commitID
ctx.Data["Anchor"] = anchor
ctx.HTML(200, tplBlobExcerpt)
ctx.HTML(http.StatusOK, tplBlobExcerpt)
}
func getExcerptLines(commit *git.Commit, filePath string, idxLeft int, idxRight int, chunkSize int) ([]*gitdiff.DiffLine, error) {