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

@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"io/ioutil"
"net/http"
"strings"
"time"
@ -51,7 +52,7 @@ func Settings(ctx *context.Context) {
ctx.Data["SigningKeyAvailable"] = len(signing) > 0
ctx.Data["SigningSettings"] = setting.Repository.Signing
ctx.HTML(200, tplSettingsOptions)
ctx.HTML(http.StatusOK, tplSettingsOptions)
}
// SettingsPost response for changes of a repository
@ -65,7 +66,7 @@ func SettingsPost(ctx *context.Context) {
switch ctx.Query("action") {
case "update":
if ctx.HasError() {
ctx.HTML(200, tplSettingsOptions)
ctx.HTML(http.StatusOK, tplSettingsOptions)
return
}
@ -366,7 +367,7 @@ func SettingsPost(ctx *context.Context) {
case "admin":
if !ctx.User.IsAdmin {
ctx.Error(403)
ctx.Error(http.StatusForbidden)
return
}
@ -386,7 +387,7 @@ func SettingsPost(ctx *context.Context) {
case "convert":
if !ctx.Repo.IsOwner() {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
return
}
if repo.Name != form.RepoName {
@ -395,7 +396,7 @@ func SettingsPost(ctx *context.Context) {
}
if !repo.IsMirror {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
return
}
repo.IsMirror = false
@ -413,7 +414,7 @@ func SettingsPost(ctx *context.Context) {
case "convert_fork":
if !ctx.Repo.IsOwner() {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
return
}
if err := repo.GetOwner(); err != nil {
@ -426,7 +427,7 @@ func SettingsPost(ctx *context.Context) {
}
if !repo.IsFork {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
return
}
@ -450,7 +451,7 @@ func SettingsPost(ctx *context.Context) {
case "transfer":
if !ctx.Repo.IsOwner() {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
return
}
if repo.Name != form.RepoName {
@ -500,7 +501,7 @@ func SettingsPost(ctx *context.Context) {
case "cancel_transfer":
if !ctx.Repo.IsOwner() {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
return
}
@ -532,7 +533,7 @@ func SettingsPost(ctx *context.Context) {
case "delete":
if !ctx.Repo.IsOwner() {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
return
}
if repo.Name != form.RepoName {
@ -551,7 +552,7 @@ func SettingsPost(ctx *context.Context) {
case "delete-wiki":
if !ctx.Repo.IsOwner() {
ctx.Error(404)
ctx.Error(http.StatusNotFound)
return
}
if repo.Name != form.RepoName {
@ -570,7 +571,7 @@ func SettingsPost(ctx *context.Context) {
case "archive":
if !ctx.Repo.IsOwner() {
ctx.Error(403)
ctx.Error(http.StatusForbidden)
return
}
@ -593,7 +594,7 @@ func SettingsPost(ctx *context.Context) {
ctx.Redirect(ctx.Repo.RepoLink + "/settings")
case "unarchive":
if !ctx.Repo.IsOwner() {
ctx.Error(403)
ctx.Error(http.StatusForbidden)
return
}
@ -638,7 +639,7 @@ func Collaboration(ctx *context.Context) {
ctx.Data["Org"] = ctx.Repo.Repository.Owner
ctx.Data["Units"] = models.Units
ctx.HTML(200, tplCollaboration)
ctx.HTML(http.StatusOK, tplCollaboration)
}
// CollaborationPost response for actions for a collaboration of a repository
@ -709,7 +710,7 @@ func DeleteCollaboration(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.settings.remove_collaborator_success"))
}
ctx.JSON(200, map[string]interface{}{
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": ctx.Repo.RepoLink + "/settings/collaboration",
})
}
@ -780,7 +781,7 @@ func DeleteTeam(ctx *context.Context) {
}
ctx.Flash.Success(ctx.Tr("repo.settings.remove_team_success"))
ctx.JSON(200, map[string]interface{}{
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": ctx.Repo.RepoLink + "/settings/collaboration",
})
}
@ -822,7 +823,7 @@ func GitHooks(ctx *context.Context) {
}
ctx.Data["Hooks"] = hooks
ctx.HTML(200, tplGithooks)
ctx.HTML(http.StatusOK, tplGithooks)
}
// GitHooksEdit render for editing a hook of repository page
@ -841,7 +842,7 @@ func GitHooksEdit(ctx *context.Context) {
return
}
ctx.Data["Hook"] = hook
ctx.HTML(200, tplGithookEdit)
ctx.HTML(http.StatusOK, tplGithookEdit)
}
// GitHooksEditPost response for editing a git hook of a repository
@ -877,7 +878,7 @@ func DeployKeys(ctx *context.Context) {
}
ctx.Data["Deploykeys"] = keys
ctx.HTML(200, tplDeployKeys)
ctx.HTML(http.StatusOK, tplDeployKeys)
}
// DeployKeysPost response for adding a deploy key of a repository
@ -894,7 +895,7 @@ func DeployKeysPost(ctx *context.Context) {
ctx.Data["Deploykeys"] = keys
if ctx.HasError() {
ctx.HTML(200, tplDeployKeys)
ctx.HTML(http.StatusOK, tplDeployKeys)
return
}
@ -948,7 +949,7 @@ func DeleteDeployKey(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.settings.deploy_key_deletion_success"))
}
ctx.JSON(200, map[string]interface{}{
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": ctx.Repo.RepoLink + "/settings/keys",
})
}