1
0
Fork 0
forked from forgejo/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:
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

@ -167,7 +167,7 @@ func Fork(ctx *context.Context) {
return
}
ctx.HTML(200, tplFork)
ctx.HTML(http.StatusOK, tplFork)
}
// ForkPost response for forking a repository
@ -188,7 +188,7 @@ func ForkPost(ctx *context.Context) {
ctx.Data["ContextUser"] = ctxUser
if ctx.HasError() {
ctx.HTML(200, tplFork)
ctx.HTML(http.StatusOK, tplFork)
return
}
@ -221,7 +221,7 @@ func ForkPost(ctx *context.Context) {
ctx.ServerError("IsOwnedBy", err)
return
} else if !isOwner {
ctx.Error(403)
ctx.Error(http.StatusForbidden)
return
}
}
@ -570,7 +570,7 @@ func ViewPullCommits(ctx *context.Context) {
ctx.Data["CommitCount"] = commits.Len()
getBranchData(ctx, issue)
ctx.HTML(200, tplPullCommits)
ctx.HTML(http.StatusOK, tplPullCommits)
}
// ViewPullFiles render pull request changed files list page
@ -692,7 +692,7 @@ func ViewPullFiles(ctx *context.Context) {
getBranchData(ctx, issue)
ctx.Data["IsIssuePoster"] = ctx.IsSigned && issue.IsPoster(ctx.User.ID)
ctx.Data["HasIssuesOrPullsWritePermission"] = ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull)
ctx.HTML(200, tplPullFiles)
ctx.HTML(http.StatusOK, tplPullFiles)
}
// UpdatePullRequest merge PR's baseBranch into headBranch
@ -1015,7 +1015,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
return
}
ctx.HTML(200, tplCompareDiff)
ctx.HTML(http.StatusOK, tplCompareDiff)
return
}
@ -1054,7 +1054,7 @@ func CompareAndPullRequestPost(ctx *context.Context) {
if err := pull_service.NewPullRequest(repo, pullIssue, labelIDs, attachments, pullRequest, assigneeIDs); err != nil {
if models.IsErrUserDoesNotHaveAccessToRepo(err) {
ctx.Error(400, "UserDoesNotHaveAccessToRepo", err.Error())
ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err.Error())
return
} else if git.IsErrPushRejected(err) {
pushrejErr := err.(*git.ErrPushRejected)
@ -1090,7 +1090,7 @@ func TriggerTask(ctx *context.Context) {
branch := ctx.Query("branch")
secret := ctx.Query("secret")
if len(branch) == 0 || len(secret) == 0 || pusherID <= 0 {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
log.Trace("TriggerTask: branch or secret is empty, or pusher ID is not valid")
return
}
@ -1101,7 +1101,7 @@ func TriggerTask(ctx *context.Context) {
got := []byte(base.EncodeMD5(owner.Salt))
want := []byte(secret)
if subtle.ConstantTimeCompare(got, want) != 1 {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name)
return
}
@ -1109,7 +1109,7 @@ func TriggerTask(ctx *context.Context) {
pusher, err := models.GetUserByID(pusherID)
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
} else {
ctx.ServerError("GetUserByID", err)
}
@ -1179,7 +1179,7 @@ func CleanUpPullRequest(ctx *context.Context) {
defer gitBaseRepo.Close()
defer func() {
ctx.JSON(200, map[string]interface{}{
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": pr.BaseRepo.Link() + "/pulls/" + fmt.Sprint(issue.Index),
})
}()