aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo
diff options
context:
space:
mode:
authorKN4CK3R <admin@oldschoolhack.me>2022-03-23 05:54:07 +0100
committerGitHub <noreply@github.com>2022-03-23 12:54:07 +0800
commit3f280f89e7471a6dcdaefccc64a8d39188970e63 (patch)
treeff09b6dcb00b4c0ff0c436c4523d89a5c13f3a94 /routers/web/repo
parent395117d3014124b9147a1aabf76ee175e720b275 (diff)
downloadgitea-3f280f89e7471a6dcdaefccc64a8d39188970e63.tar.gz
gitea-3f280f89e7471a6dcdaefccc64a8d39188970e63.zip
Update HTTP status codes to modern codes (#18063)
* 2xx/3xx/4xx/5xx -> http.Status... * http.StatusFound -> http.StatusTemporaryRedirect * http.StatusMovedPermanently -> http.StatusPermanentRedirect
Diffstat (limited to 'routers/web/repo')
-rw-r--r--routers/web/repo/editor.go4
-rw-r--r--routers/web/repo/issue.go22
-rw-r--r--routers/web/repo/issue_dependency.go4
-rw-r--r--routers/web/repo/issue_label_test.go6
-rw-r--r--routers/web/repo/issue_lock.go6
-rw-r--r--routers/web/repo/issue_watch.go2
-rw-r--r--routers/web/repo/search.go2
-rw-r--r--routers/web/repo/setting_protected_branch.go2
-rw-r--r--routers/web/repo/settings_test.go22
-rw-r--r--routers/web/repo/webhook.go6
-rw-r--r--routers/web/repo/wiki_test.go4
11 files changed, 39 insertions, 41 deletions
diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go
index a2cf070375..c10162c759 100644
--- a/routers/web/repo/editor.go
+++ b/routers/web/repo/editor.go
@@ -780,7 +780,7 @@ func UploadFileToServer(ctx *context.Context) {
func RemoveUploadFileFromServer(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.RemoveUploadFileForm)
if len(form.File) == 0 {
- ctx.Status(204)
+ ctx.Status(http.StatusNoContent)
return
}
@@ -790,7 +790,7 @@ func RemoveUploadFileFromServer(ctx *context.Context) {
}
log.Trace("Upload file removed: %s", form.File)
- ctx.Status(204)
+ ctx.Status(http.StatusNoContent)
}
// GetUniquePatchBranchName Gets a unique branch name for a new patch branch
diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go
index adf7e93eac..aeb1f0a020 100644
--- a/routers/web/repo/issue.go
+++ b/routers/web/repo/issue.go
@@ -1931,7 +1931,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
// TODO: Not support 'clear' now
if action != "attach" && action != "detach" {
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
@@ -1946,7 +1946,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
"UpdatePullReviewRequest: refusing to add review request for non-PR issue %-v#%d",
issue.Repo, issue.Index,
)
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
if reviewID < 0 {
@@ -1961,7 +1961,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
"UpdatePullReviewRequest: refusing to add team review request for %s#%d owned by non organization UID[%d]",
issue.Repo.FullName(), issue.Index, issue.Repo.ID,
)
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
@@ -1975,7 +1975,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
log.Warn(
"UpdatePullReviewRequest: refusing to add team review request for UID[%d] team %s to %s#%d owned by UID[%d]",
team.OrgID, team.Name, issue.Repo.FullName(), issue.Index, issue.Repo.ID)
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
@@ -1987,7 +1987,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
team.OrgID, team.Name, issue.Repo.FullName(), issue.Index, issue.Repo.ID,
err,
)
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
ctx.ServerError("IsValidTeamReviewRequest", err)
@@ -2010,7 +2010,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
reviewID, issue.Repo, issue.Index,
err,
)
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
ctx.ServerError("GetUserByID", err)
@@ -2025,7 +2025,7 @@ func UpdatePullReviewRequest(ctx *context.Context) {
reviewer, issue.Repo, issue.Index,
err,
)
- ctx.Status(403)
+ ctx.Status(http.StatusForbidden)
return
}
ctx.ServerError("isValidReviewRequest", err)
@@ -2117,7 +2117,7 @@ func NewComment(ctx *context.Context) {
if issue.IsLocked && !ctx.Repo.CanWriteIssuesOrPulls(issue.IsPull) && !ctx.Doer.IsAdmin {
ctx.Flash.Error(ctx.Tr("repo.issues.comment_on_locked"))
- ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
+ ctx.Redirect(issue.HTMLURL())
return
}
@@ -2170,10 +2170,10 @@ func NewComment(ctx *context.Context) {
if models.IsErrDependenciesLeft(err) {
if issue.IsPull {
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.pr_close_blocked"))
- ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index), http.StatusSeeOther)
+ ctx.Redirect(fmt.Sprintf("%s/pulls/%d", ctx.Repo.RepoLink, issue.Index))
} else {
ctx.Flash.Error(ctx.Tr("repo.issues.dependency.issue_close_blocked"))
- ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index), http.StatusSeeOther)
+ ctx.Redirect(fmt.Sprintf("%s/issues/%d", ctx.Repo.RepoLink, issue.Index))
}
return
}
@@ -2306,7 +2306,7 @@ func DeleteComment(ctx *context.Context) {
return
}
- ctx.Status(200)
+ ctx.Status(http.StatusOK)
}
// ChangeIssueReaction create a reaction for issue
diff --git a/routers/web/repo/issue_dependency.go b/routers/web/repo/issue_dependency.go
index d9084328ee..d43cb373a2 100644
--- a/routers/web/repo/issue_dependency.go
+++ b/routers/web/repo/issue_dependency.go
@@ -35,7 +35,7 @@ func AddDependency(ctx *context.Context) {
}
// Redirect
- defer ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
+ defer ctx.Redirect(issue.HTMLURL())
// Dependency
dep, err := models.GetIssueByID(depID)
@@ -125,5 +125,5 @@ func RemoveDependency(ctx *context.Context) {
}
// Redirect
- ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
+ ctx.Redirect(issue.HTMLURL())
}
diff --git a/routers/web/repo/issue_label_test.go b/routers/web/repo/issue_label_test.go
index baa34530fa..5d7a29ee93 100644
--- a/routers/web/repo/issue_label_test.go
+++ b/routers/web/repo/issue_label_test.go
@@ -36,7 +36,7 @@ func TestInitializeLabels(t *testing.T) {
test.LoadRepo(t, ctx, 2)
web.SetForm(ctx, &forms.InitializeLabelsForm{TemplateName: "Default"})
InitializeLabels(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
unittest.AssertExistsAndLoadBean(t, &models.Label{
RepoID: 2,
Name: "enhancement",
@@ -82,7 +82,7 @@ func TestNewLabel(t *testing.T) {
Color: "#abcdef",
})
NewLabel(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
unittest.AssertExistsAndLoadBean(t, &models.Label{
Name: "newlabel",
Color: "#abcdef",
@@ -101,7 +101,7 @@ func TestUpdateLabel(t *testing.T) {
Color: "#abcdef",
})
UpdateLabel(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
unittest.AssertExistsAndLoadBean(t, &models.Label{
ID: 2,
Name: "newnameforlabel",
diff --git a/routers/web/repo/issue_lock.go b/routers/web/repo/issue_lock.go
index b016818669..5ac5cac52e 100644
--- a/routers/web/repo/issue_lock.go
+++ b/routers/web/repo/issue_lock.go
@@ -5,8 +5,6 @@
package repo
import (
- "net/http"
-
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/web"
@@ -43,7 +41,7 @@ func LockIssue(ctx *context.Context) {
return
}
- ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
+ ctx.Redirect(issue.HTMLURL())
}
// UnlockIssue unlocks a previously locked issue.
@@ -67,5 +65,5 @@ func UnlockIssue(ctx *context.Context) {
return
}
- ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
+ ctx.Redirect(issue.HTMLURL())
}
diff --git a/routers/web/repo/issue_watch.go b/routers/web/repo/issue_watch.go
index 223fc72071..53fec11cdc 100644
--- a/routers/web/repo/issue_watch.go
+++ b/routers/web/repo/issue_watch.go
@@ -53,5 +53,5 @@ func IssueWatch(ctx *context.Context) {
return
}
- ctx.Redirect(issue.HTMLURL(), http.StatusSeeOther)
+ ctx.Redirect(issue.HTMLURL())
}
diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go
index e33fe38dea..c230e88d2d 100644
--- a/routers/web/repo/search.go
+++ b/routers/web/repo/search.go
@@ -18,7 +18,7 @@ const tplSearch base.TplName = "repo/search"
// Search render repository search page
func Search(ctx *context.Context) {
if !setting.Indexer.RepoIndexerEnabled {
- ctx.Redirect(ctx.Repo.RepoLink, 302)
+ ctx.Redirect(ctx.Repo.RepoLink)
return
}
language := ctx.FormTrim("l")
diff --git a/routers/web/repo/setting_protected_branch.go b/routers/web/repo/setting_protected_branch.go
index cd6cf38038..dae618a758 100644
--- a/routers/web/repo/setting_protected_branch.go
+++ b/routers/web/repo/setting_protected_branch.go
@@ -73,7 +73,7 @@ func ProtectedBranchPost(ctx *context.Context) {
branch := ctx.FormString("branch")
if !ctx.Repo.GitRepo.IsBranchExist(branch) {
- ctx.Status(404)
+ ctx.Status(http.StatusNotFound)
return
} else if repo.DefaultBranch != branch {
repo.DefaultBranch = branch
diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go
index bd29eca195..db1e905869 100644
--- a/routers/web/repo/settings_test.go
+++ b/routers/web/repo/settings_test.go
@@ -60,7 +60,7 @@ func TestAddReadOnlyDeployKey(t *testing.T) {
}
web.SetForm(ctx, &addKeyForm)
DeployKeysPost(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
unittest.AssertExistsAndLoadBean(t, &asymkey_model.DeployKey{
Name: addKeyForm.Title,
@@ -90,7 +90,7 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) {
}
web.SetForm(ctx, &addKeyForm)
DeployKeysPost(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
unittest.AssertExistsAndLoadBean(t, &asymkey_model.DeployKey{
Name: addKeyForm.Title,
@@ -127,7 +127,7 @@ func TestCollaborationPost(t *testing.T) {
CollaborationPost(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
exists, err := models.IsCollaborator(re.ID, 4)
assert.NoError(t, err)
@@ -153,7 +153,7 @@ func TestCollaborationPost_InactiveUser(t *testing.T) {
CollaborationPost(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
}
@@ -185,7 +185,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
CollaborationPost(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
exists, err := models.IsCollaborator(re.ID, 4)
assert.NoError(t, err)
@@ -194,7 +194,7 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) {
// Try adding the same collaborator again
CollaborationPost(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
}
@@ -216,7 +216,7 @@ func TestCollaborationPost_NonExistentUser(t *testing.T) {
CollaborationPost(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
}
@@ -256,7 +256,7 @@ func TestAddTeamPost(t *testing.T) {
AddTeamPost(ctx)
assert.True(t, team.HasRepository(re.ID))
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
assert.Empty(t, ctx.Flash.ErrorMsg)
}
@@ -296,7 +296,7 @@ func TestAddTeamPost_NotAllowed(t *testing.T) {
AddTeamPost(ctx)
assert.False(t, team.HasRepository(re.ID))
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
}
@@ -337,7 +337,7 @@ func TestAddTeamPost_AddTeamTwice(t *testing.T) {
AddTeamPost(ctx)
assert.True(t, team.HasRepository(re.ID))
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
}
@@ -370,7 +370,7 @@ func TestAddTeamPost_NonExistentTeam(t *testing.T) {
ctx.Repo = repo
AddTeamPost(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
assert.NotEmpty(t, ctx.Flash.ErrorMsg)
}
diff --git a/routers/web/repo/webhook.go b/routers/web/repo/webhook.go
index 7ffea1724a..81dab5a3b9 100644
--- a/routers/web/repo/webhook.go
+++ b/routers/web/repo/webhook.go
@@ -1241,7 +1241,7 @@ func TestWebhook(ctx *context.Context) {
w, err := webhook.GetWebhookByRepoID(ctx.Repo.Repository.ID, hookID)
if err != nil {
ctx.Flash.Error("GetWebhookByID: " + err.Error())
- ctx.Status(500)
+ ctx.Status(http.StatusInternalServerError)
return
}
@@ -1285,10 +1285,10 @@ func TestWebhook(ctx *context.Context) {
}
if err := webhook_service.PrepareWebhook(w, ctx.Repo.Repository, webhook.HookEventPush, p); err != nil {
ctx.Flash.Error("PrepareWebhook: " + err.Error())
- ctx.Status(500)
+ ctx.Status(http.StatusInternalServerError)
} else {
ctx.Flash.Info(ctx.Tr("repo.settings.webhook.delivery.success"))
- ctx.Status(200)
+ ctx.Status(http.StatusOK)
}
}
diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go
index b19c628a9f..41b5c0f8fd 100644
--- a/routers/web/repo/wiki_test.go
+++ b/routers/web/repo/wiki_test.go
@@ -124,7 +124,7 @@ func TestNewWikiPost(t *testing.T) {
Message: message,
})
NewWikiPost(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
assertWikiExists(t, ctx.Repo.Repository, title)
assert.Equal(t, wikiContent(t, ctx.Repo.Repository, title), content)
}
@@ -176,7 +176,7 @@ func TestEditWikiPost(t *testing.T) {
Message: message,
})
EditWikiPost(ctx)
- assert.EqualValues(t, http.StatusFound, ctx.Resp.Status())
+ assert.EqualValues(t, http.StatusSeeOther, ctx.Resp.Status())
assertWikiExists(t, ctx.Repo.Repository, title)
assert.Equal(t, wikiContent(t, ctx.Repo.Repository, title), content)
if title != "Home" {