1
0
Fork 0
forked from forgejo/forgejo

format with gofumpt (#18184)

* gofumpt -w -l .

* gofumpt -w -l -extra .

* Add linter

* manual fix

* change make fmt
This commit is contained in:
6543 2022-01-20 18:46:10 +01:00 committed by GitHub
parent 1d98d205f5
commit 54e9ee37a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
423 changed files with 1585 additions and 1758 deletions

View file

@ -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
// ---

View file

@ -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
// ---

View file

@ -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"},

View file

@ -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,

View file

@ -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)
}

View file

@ -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
// ---

View file

@ -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

View file

@ -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))
}

View file

@ -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

View file

@ -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)
}
}

View file

@ -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)
}

View file

@ -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
}

View file

@ -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,

View file

@ -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)
}

View file

@ -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

View file

@ -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
}

View file

@ -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"
}

View file

@ -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())

View file

@ -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) {

View file

@ -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 {

View file

@ -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
// ---

View file

@ -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

View file

@ -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
}