summaryrefslogtreecommitdiffstats
path: root/routers/api/v1
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2022-01-20 18:46:10 +0100
committerGitHub <noreply@github.com>2022-01-20 18:46:10 +0100
commit54e9ee37a7a301dbe74d46fd3c87712e6120e9bf (patch)
tree1be12fb072625c1b896b9d72f7912b018aad502b /routers/api/v1
parent1d98d205f5825f40110e6628b61a97c91ac7f72d (diff)
downloadgitea-54e9ee37a7a301dbe74d46fd3c87712e6120e9bf.tar.gz
gitea-54e9ee37a7a301dbe74d46fd3c87712e6120e9bf.zip
format with gofumpt (#18184)
* gofumpt -w -l . * gofumpt -w -l -extra . * Add linter * manual fix * change make fmt
Diffstat (limited to 'routers/api/v1')
-rw-r--r--routers/api/v1/admin/org.go2
-rw-r--r--routers/api/v1/admin/user.go2
-rw-r--r--routers/api/v1/api.go12
-rw-r--r--routers/api/v1/misc/markdown_test.go10
-rw-r--r--routers/api/v1/org/hook.go4
-rw-r--r--routers/api/v1/org/org.go4
-rw-r--r--routers/api/v1/repo/branch.go6
-rw-r--r--routers/api/v1/repo/fork.go2
-rw-r--r--routers/api/v1/repo/issue.go2
-rw-r--r--routers/api/v1/repo/issue_reaction.go4
-rw-r--r--routers/api/v1/repo/issue_subscription.go4
-rw-r--r--routers/api/v1/repo/issue_tracked_time.go4
-rw-r--r--routers/api/v1/repo/migrate.go4
-rw-r--r--routers/api/v1/repo/milestone.go2
-rw-r--r--routers/api/v1/repo/pull.go1
-rw-r--r--routers/api/v1/repo/release_attachment.go2
-rw-r--r--routers/api/v1/repo/repo.go6
-rw-r--r--routers/api/v1/repo/repo_test.go4
-rw-r--r--routers/api/v1/repo/status.go2
-rw-r--r--routers/api/v1/repo/wiki.go5
-rw-r--r--routers/api/v1/user/gpg_key.go10
-rw-r--r--routers/api/v1/user/watch.go1
-rw-r--r--routers/api/v1/utils/git.go4
23 files changed, 45 insertions, 52 deletions
diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go
index bdfe87fd4e..aaa27afb9e 100644
--- a/routers/api/v1/admin/org.go
+++ b/routers/api/v1/admin/org.go
@@ -82,7 +82,7 @@ func CreateOrg(ctx *context.APIContext) {
ctx.JSON(http.StatusCreated, convert.ToOrganization(org))
}
-//GetAllOrgs API for getting information of all the organizations
+// GetAllOrgs API for getting information of all the organizations
func GetAllOrgs(ctx *context.APIContext) {
// swagger:operation GET /admin/orgs admin adminGetAllOrgs
// ---
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index e95ab33d77..0ecebad5d7 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -403,7 +403,7 @@ func DeleteUserPublicKey(ctx *context.APIContext) {
ctx.Status(http.StatusNoContent)
}
-//GetAllUsers API for getting information of all the users
+// GetAllUsers API for getting information of all the users
func GetAllUsers(ctx *context.APIContext) {
// swagger:operation GET /admin/users admin adminGetAllUsers
// ---
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 7a723a138a..df00a852f2 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -333,7 +333,7 @@ func reqTeamMembership() func(ctx *context.APIContext) {
return
}
- var orgID = ctx.Org.Team.OrgID
+ orgID := ctx.Org.Team.OrgID
isOwner, err := models.IsOrganizationOwner(orgID, ctx.User.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsOrganizationOwner", err)
@@ -545,12 +545,12 @@ func mustNotBeArchived(ctx *context.APIContext) {
// bind binding an obj to a func(ctx *context.APIContext)
func bind(obj interface{}) http.HandlerFunc {
- var tp = reflect.TypeOf(obj)
+ tp := reflect.TypeOf(obj)
for tp.Kind() == reflect.Ptr {
tp = tp.Elem()
}
return web.Wrap(func(ctx *context.APIContext) {
- var theObj = reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
+ theObj := reflect.New(tp).Interface() // create a new form obj for every request but not use obj directly
errs := binding.Bind(ctx.Req, theObj)
if len(errs) > 0 {
ctx.Error(http.StatusUnprocessableEntity, "validationError", fmt.Sprintf("%s: %s", errs[0].FieldNames, errs[0].Error()))
@@ -562,16 +562,16 @@ func bind(obj interface{}) http.HandlerFunc {
// Routes registers all v1 APIs routes to web application.
func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
- var m = web.NewRoute()
+ m := web.NewRoute()
m.Use(sessioner)
m.Use(securityHeaders())
if setting.CORSConfig.Enabled {
m.Use(cors.Handler(cors.Options{
- //Scheme: setting.CORSConfig.Scheme, // FIXME: the cors middleware needs scheme option
+ // Scheme: setting.CORSConfig.Scheme, // FIXME: the cors middleware needs scheme option
AllowedOrigins: setting.CORSConfig.AllowDomain,
- //setting.CORSConfig.AllowSubdomain // FIXME: the cors middleware needs allowSubdomain option
+ // setting.CORSConfig.AllowSubdomain // FIXME: the cors middleware needs allowSubdomain option
AllowedMethods: setting.CORSConfig.Methods,
AllowCredentials: setting.CORSConfig.AllowCredentials,
AllowedHeaders: []string{"Authorization", "X-CSRFToken", "X-Gitea-OTP"},
diff --git a/routers/api/v1/misc/markdown_test.go b/routers/api/v1/misc/markdown_test.go
index dc6762c4cf..349498e2ab 100644
--- a/routers/api/v1/misc/markdown_test.go
+++ b/routers/api/v1/misc/markdown_test.go
@@ -22,12 +22,14 @@ import (
"github.com/stretchr/testify/assert"
)
-const AppURL = "http://localhost:3000/"
-const Repo = "gogits/gogs"
-const AppSubURL = AppURL + Repo + "/"
+const (
+ AppURL = "http://localhost:3000/"
+ Repo = "gogits/gogs"
+ AppSubURL = AppURL + Repo + "/"
+)
func createContext(req *http.Request) (*context.Context, *httptest.ResponseRecorder) {
- var rnd = templates.HTMLRenderer()
+ rnd := templates.HTMLRenderer()
resp := httptest.NewRecorder()
c := &context.Context{
Req: req,
diff --git a/routers/api/v1/org/hook.go b/routers/api/v1/org/hook.go
index b9d1fa2f67..67957430d1 100644
--- a/routers/api/v1/org/hook.go
+++ b/routers/api/v1/org/hook.go
@@ -123,7 +123,7 @@ func CreateHook(ctx *context.APIContext) {
// "$ref": "#/responses/Hook"
form := web.GetForm(ctx).(*api.CreateHookOption)
- //TODO in body params
+ // TODO in body params
if !utils.CheckCreateHookOption(ctx, form) {
return
}
@@ -161,7 +161,7 @@ func EditHook(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.EditHookOption)
- //TODO in body params
+ // TODO in body params
hookID := ctx.ParamsInt64(":id")
utils.EditOrgHook(ctx, form, hookID)
}
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go
index 133cce3416..1f097225f2 100644
--- a/routers/api/v1/org/org.go
+++ b/routers/api/v1/org/org.go
@@ -25,7 +25,7 @@ func listUserOrgs(ctx *context.APIContext, u *user_model.User) {
listOptions := utils.GetListOptions(ctx)
showPrivate := ctx.IsSigned && (ctx.User.IsAdmin || ctx.User.ID == u.ID)
- var opts = models.FindOrgOptions{
+ opts := models.FindOrgOptions{
ListOptions: listOptions,
UserID: u.ID,
IncludePrivate: showPrivate,
@@ -357,7 +357,7 @@ func Edit(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, convert.ToOrganization(org))
}
-//Delete an organization
+// Delete an organization
func Delete(ctx *context.APIContext) {
// swagger:operation DELETE /orgs/{org} organization orgDelete
// ---
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index c5480bf2c5..3a0c3201ac 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -177,23 +177,18 @@ func CreateBranch(ctx *context.APIContext) {
}
err := repo_service.CreateNewBranch(ctx, ctx.User, ctx.Repo.Repository, opt.OldBranchName, opt.BranchName)
-
if err != nil {
if models.IsErrBranchDoesNotExist(err) {
ctx.Error(http.StatusNotFound, "", "The old branch does not exist")
}
if models.IsErrTagAlreadyExists(err) {
ctx.Error(http.StatusConflict, "", "The branch with the same tag already exists.")
-
} else if models.IsErrBranchAlreadyExists(err) || git.IsErrPushOutOfDate(err) {
ctx.Error(http.StatusConflict, "", "The branch already exists.")
-
} else if models.IsErrBranchNameConflict(err) {
ctx.Error(http.StatusConflict, "", "The branch with the same name already exists.")
-
} else {
ctx.Error(http.StatusInternalServerError, "CreateRepoBranch", err)
-
}
return
}
@@ -532,7 +527,6 @@ func CreateBranchProtection(ctx *context.APIContext) {
}
ctx.JSON(http.StatusCreated, convert.ToBranchProtection(bp))
-
}
// EditBranchProtection edits a branch protection for a repo
diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go
index b0ba5db253..d814ae909e 100644
--- a/routers/api/v1/repo/fork.go
+++ b/routers/api/v1/repo/fork.go
@@ -149,6 +149,6 @@ func CreateFork(ctx *context.APIContext) {
return
}
- //TODO change back to 201
+ // TODO change back to 201
ctx.JSON(http.StatusAccepted, convert.ToRepo(fork, perm.AccessModeOwner))
}
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index 5137c7246e..5ce0c109e6 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -599,7 +599,7 @@ func CreateIssue(ctx *context.APIContext) {
DeadlineUnix: deadlineUnix,
}
- var assigneeIDs = make([]int64, 0)
+ assigneeIDs := make([]int64, 0)
var err error
if ctx.Repo.CanWrite(unit.TypeIssues) {
issue.MilestoneID = form.Milestone
diff --git a/routers/api/v1/repo/issue_reaction.go b/routers/api/v1/repo/issue_reaction.go
index 6184ea71f0..9c5086700c 100644
--- a/routers/api/v1/repo/issue_reaction.go
+++ b/routers/api/v1/repo/issue_reaction.go
@@ -225,7 +225,7 @@ func changeIssueCommentReaction(ctx *context.APIContext, form api.EditReactionOp
ctx.Error(http.StatusInternalServerError, "DeleteCommentReaction", err)
return
}
- //ToDo respond 204
+ // ToDo respond 204
ctx.Status(http.StatusOK)
}
}
@@ -435,7 +435,7 @@ func changeIssueReaction(ctx *context.APIContext, form api.EditReactionOption, i
ctx.Error(http.StatusInternalServerError, "DeleteIssueReaction", err)
return
}
- //ToDo respond 204
+ // ToDo respond 204
ctx.Status(http.StatusOK)
}
}
diff --git a/routers/api/v1/repo/issue_subscription.go b/routers/api/v1/repo/issue_subscription.go
index 9c6b4e4647..76c668697e 100644
--- a/routers/api/v1/repo/issue_subscription.go
+++ b/routers/api/v1/repo/issue_subscription.go
@@ -127,7 +127,7 @@ func setIssueSubscription(ctx *context.APIContext, watch bool) {
return
}
- //only admin and user for itself can change subscription
+ // only admin and user for itself can change subscription
if user.ID != ctx.User.ID && !ctx.User.IsAdmin {
ctx.Error(http.StatusForbidden, "User", fmt.Errorf("%s is not permitted to change subscriptions for %s", ctx.User.Name, user.Name))
return
@@ -269,7 +269,7 @@ func GetIssueSubscribers(ctx *context.APIContext) {
return
}
- var userIDs = make([]int64, 0, len(iwl))
+ userIDs := make([]int64, 0, len(iwl))
for _, iw := range iwl {
userIDs = append(userIDs, iw.UserID)
}
diff --git a/routers/api/v1/repo/issue_tracked_time.go b/routers/api/v1/repo/issue_tracked_time.go
index 00f8e77feb..79ba59996c 100644
--- a/routers/api/v1/repo/issue_tracked_time.go
+++ b/routers/api/v1/repo/issue_tracked_time.go
@@ -201,7 +201,7 @@ func AddTime(ctx *context.APIContext) {
user := ctx.User
if form.User != "" {
if (ctx.IsUserRepoAdmin() && ctx.User.Name != form.User) || ctx.User.IsAdmin {
- //allow only RepoAdmin, Admin and User to add time
+ // allow only RepoAdmin, Admin and User to add time
user, err = user_model.GetUserByName(form.User)
if err != nil {
ctx.Error(http.StatusInternalServerError, "GetUserByName", err)
@@ -365,7 +365,7 @@ func DeleteTime(ctx *context.APIContext) {
}
if !ctx.User.IsAdmin && time.UserID != ctx.User.ID {
- //Only Admin and User itself can delete their time
+ // Only Admin and User itself can delete their time
ctx.Status(http.StatusForbidden)
return
}
diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go
index 8a6f421c87..394504a99d 100644
--- a/routers/api/v1/repo/migrate.go
+++ b/routers/api/v1/repo/migrate.go
@@ -56,7 +56,7 @@ func Migrate(ctx *context.APIContext) {
form := web.GetForm(ctx).(*api.MigrateRepoOptions)
- //get repoOwner
+ // get repoOwner
var (
repoOwner *user_model.User
err error
@@ -137,7 +137,7 @@ func Migrate(ctx *context.APIContext) {
}
}
- var opts = migrations.MigrateOptions{
+ opts := migrations.MigrateOptions{
CloneAddr: remoteAddr,
RepoName: form.RepoName,
Description: form.Description,
diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go
index be1da18c5d..3b4b85158c 100644
--- a/routers/api/v1/repo/milestone.go
+++ b/routers/api/v1/repo/milestone.go
@@ -213,7 +213,7 @@ func EditMilestone(ctx *context.APIContext) {
milestone.DeadlineUnix = timeutil.TimeStamp(form.Deadline.Unix())
}
- var oldIsClosed = milestone.IsClosed
+ oldIsClosed := milestone.IsClosed
if form.State != nil {
milestone.IsClosed = *form.State == string(api.StateClosed)
}
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go
index 52ff8425de..a494cb06cc 100644
--- a/routers/api/v1/repo/pull.go
+++ b/routers/api/v1/repo/pull.go
@@ -95,7 +95,6 @@ func ListPullRequests(ctx *context.APIContext) {
Labels: ctx.FormStrings("labels"),
MilestoneID: ctx.FormInt64("milestone"),
})
-
if err != nil {
ctx.Error(http.StatusInternalServerError, "PullRequests", err)
return
diff --git a/routers/api/v1/repo/release_attachment.go b/routers/api/v1/repo/release_attachment.go
index fe82915a94..b1bc48d30f 100644
--- a/routers/api/v1/repo/release_attachment.go
+++ b/routers/api/v1/repo/release_attachment.go
@@ -178,7 +178,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
}
defer file.Close()
- var filename = header.Filename
+ filename := header.Filename
if query := ctx.FormString("name"); query != "" {
filename = query
}
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index 5f17dc9268..c2dfc4f193 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -160,7 +160,7 @@ func Search(ctx *context.APIContext) {
opts.Collaborate = util.OptionalBoolFalse
}
- var mode = ctx.FormString("mode")
+ mode := ctx.FormString("mode")
switch mode {
case "source":
opts.Fork = util.OptionalBoolFalse
@@ -186,9 +186,9 @@ func Search(ctx *context.APIContext) {
opts.IsPrivate = util.OptionalBoolOf(ctx.FormBool("is_private"))
}
- var sortMode = ctx.FormString("sort")
+ sortMode := ctx.FormString("sort")
if len(sortMode) > 0 {
- var sortOrder = ctx.FormString("order")
+ sortOrder := ctx.FormString("order")
if len(sortOrder) == 0 {
sortOrder = "asc"
}
diff --git a/routers/api/v1/repo/repo_test.go b/routers/api/v1/repo/repo_test.go
index 17b49f7f58..652fecefbc 100644
--- a/routers/api/v1/repo/repo_test.go
+++ b/routers/api/v1/repo/repo_test.go
@@ -55,7 +55,7 @@ func TestRepoEdit(t *testing.T) {
Archived: &archived,
}
- var apiCtx = &context.APIContext{Context: ctx, Org: nil}
+ apiCtx := &context.APIContext{Context: ctx, Org: nil}
web.SetForm(apiCtx, &opts)
Edit(apiCtx)
@@ -77,7 +77,7 @@ func TestRepoEditNameChange(t *testing.T) {
Name: &name,
}
- var apiCtx = &context.APIContext{Context: ctx, Org: nil}
+ apiCtx := &context.APIContext{Context: ctx, Org: nil}
web.SetForm(apiCtx, &opts)
Edit(apiCtx)
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
diff --git a/routers/api/v1/repo/status.go b/routers/api/v1/repo/status.go
index 72d790794e..01faf5ad25 100644
--- a/routers/api/v1/repo/status.go
+++ b/routers/api/v1/repo/status.go
@@ -176,7 +176,7 @@ func GetCommitStatusesByRef(ctx *context.APIContext) {
return
}
- getCommitStatuses(ctx, filter) //By default filter is maybe the raw SHA
+ getCommitStatuses(ctx, filter) // By default filter is maybe the raw SHA
}
func getCommitStatuses(ctx *context.APIContext, sha string) {
diff --git a/routers/api/v1/repo/wiki.go b/routers/api/v1/repo/wiki.go
index 94f1dbe0ea..f7054b5067 100644
--- a/routers/api/v1/repo/wiki.go
+++ b/routers/api/v1/repo/wiki.go
@@ -167,7 +167,7 @@ func getWikiPage(ctx *context.APIContext, title string) *api.WikiPage {
return nil
}
- //lookup filename in wiki - get filecontent, real filename
+ // lookup filename in wiki - get filecontent, real filename
content, pageFilename := wikiContentsByName(ctx, commit, title, false)
if ctx.Written() {
return nil
@@ -412,7 +412,7 @@ func ListPageRevisions(ctx *context.APIContext) {
pageName = "Home"
}
- //lookup filename in wiki - get filecontent, gitTree entry , real filename
+ // lookup filename in wiki - get filecontent, gitTree entry , real filename
_, pageFilename := wikiContentsByName(ctx, commit, pageName, false)
if ctx.Written() {
return
@@ -501,7 +501,6 @@ func wikiContentsByEntry(ctx *context.APIContext, entry *git.TreeEntry) string {
func wikiContentsByName(ctx *context.APIContext, commit *git.Commit, wikiName string, isSidebarOrFooter bool) (string, string) {
pageFilename := wiki_service.NameToFilename(wikiName)
entry, err := findEntryForFile(commit, pageFilename)
-
if err != nil {
if git.IsErrNotExist(err) {
if !isSidebarOrFooter {
diff --git a/routers/api/v1/user/gpg_key.go b/routers/api/v1/user/gpg_key.go
index a90e8c30f0..26aeeeabf9 100644
--- a/routers/api/v1/user/gpg_key.go
+++ b/routers/api/v1/user/gpg_key.go
@@ -39,7 +39,7 @@ func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions)
ctx.JSON(http.StatusOK, &apiKeys)
}
-//ListGPGKeys get the GPG key list of a user
+// ListGPGKeys get the GPG key list of a user
func ListGPGKeys(ctx *context.APIContext) {
// swagger:operation GET /users/{username}/gpg_keys user userListGPGKeys
// ---
@@ -71,7 +71,7 @@ func ListGPGKeys(ctx *context.APIContext) {
listGPGKeys(ctx, user.ID, utils.GetListOptions(ctx))
}
-//ListMyGPGKeys get the GPG key list of the authenticated user
+// ListMyGPGKeys get the GPG key list of the authenticated user
func ListMyGPGKeys(ctx *context.APIContext) {
// swagger:operation GET /user/gpg_keys user userCurrentListGPGKeys
// ---
@@ -94,7 +94,7 @@ func ListMyGPGKeys(ctx *context.APIContext) {
listGPGKeys(ctx, ctx.User.ID, utils.GetListOptions(ctx))
}
-//GetGPGKey get the GPG key based on a id
+// GetGPGKey get the GPG key based on a id
func GetGPGKey(ctx *context.APIContext) {
// swagger:operation GET /user/gpg_keys/{id} user userCurrentGetGPGKey
// ---
@@ -212,7 +212,7 @@ type swaggerUserCurrentPostGPGKey struct {
Form api.CreateGPGKeyOption
}
-//CreateGPGKey create a GPG key belonging to the authenticated user
+// CreateGPGKey create a GPG key belonging to the authenticated user
func CreateGPGKey(ctx *context.APIContext) {
// swagger:operation POST /user/gpg_keys user userCurrentPostGPGKey
// ---
@@ -233,7 +233,7 @@ func CreateGPGKey(ctx *context.APIContext) {
CreateUserGPGKey(ctx, *form, ctx.User.ID)
}
-//DeleteGPGKey remove a GPG key belonging to the authenticated user
+// DeleteGPGKey remove a GPG key belonging to the authenticated user
func DeleteGPGKey(ctx *context.APIContext) {
// swagger:operation DELETE /user/gpg_keys/{id} user userCurrentDeleteGPGKey
// ---
diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go
index 6c3e1c86fa..49b1d47d95 100644
--- a/routers/api/v1/user/watch.go
+++ b/routers/api/v1/user/watch.go
@@ -170,7 +170,6 @@ func Watch(ctx *context.APIContext) {
URL: subscriptionURL(ctx.Repo.Repository),
RepositoryURL: ctx.Repo.Repository.APIURL(),
})
-
}
// Unwatch the repo specified in ctx, as the authenticated user
diff --git a/routers/api/v1/utils/git.go b/routers/api/v1/utils/git.go
index a941c1fc2c..f7a7fe83c9 100644
--- a/routers/api/v1/utils/git.go
+++ b/routers/api/v1/utils/git.go
@@ -50,12 +50,12 @@ func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, strin
}
func searchRefCommitByType(ctx *context.APIContext, refType, filter string) (string, string, error) {
- refs, lastMethodName, err := GetGitRefs(ctx, refType+"/"+filter) //Search by type
+ refs, lastMethodName, err := GetGitRefs(ctx, refType+"/"+filter) // Search by type
if err != nil {
return "", lastMethodName, err
}
if len(refs) > 0 {
- return refs[0].Object.String(), "", nil //Return found SHA
+ return refs[0].Object.String(), "", nil // Return found SHA
}
return "", "", nil
}