diff options
Diffstat (limited to 'routers/web')
43 files changed, 104 insertions, 135 deletions
diff --git a/routers/web/admin/admin.go b/routers/web/admin/admin.go index 7e25f96ee0..276e1939ad 100644 --- a/routers/web/admin/admin.go +++ b/routers/web/admin/admin.go @@ -209,7 +209,7 @@ func shadowPassword(provider, cfgItem string) string { case "redis": return shadowPasswordKV(cfgItem, ",") case "mysql": - //root:@tcp(localhost:3306)/macaron?charset=utf8 + // root:@tcp(localhost:3306)/macaron?charset=utf8 atIdx := strings.Index(cfgItem, "@") if atIdx > 0 { colonIdx := strings.Index(cfgItem[:atIdx], ":") diff --git a/routers/web/admin/admin_test.go b/routers/web/admin/admin_test.go index da404e50d7..1bc43998b2 100644 --- a/routers/web/admin/admin_test.go +++ b/routers/web/admin/admin_test.go @@ -11,7 +11,7 @@ import ( ) func TestShadowPassword(t *testing.T) { - var kases = []struct { + kases := []struct { Provider string CfgItem string Result string diff --git a/routers/web/admin/emails.go b/routers/web/admin/emails.go index cbf0ec5e98..b94f9d72c4 100644 --- a/routers/web/admin/emails.go +++ b/routers/web/admin/emails.go @@ -101,9 +101,7 @@ func Emails(ctx *context.Context) { ctx.HTML(http.StatusOK, tplEmails) } -var ( - nullByte = []byte{0x00} -) +var nullByte = []byte{0x00} func isKeywordValid(keyword string) bool { return !bytes.Contains([]byte(keyword), nullByte) @@ -111,7 +109,6 @@ func isKeywordValid(keyword string) bool { // ActivateEmail serves a POST request for activating/deactivating a user's email func ActivateEmail(ctx *context.Context) { - truefalse := map[string]bool{"1": true, "0": false} uid := ctx.FormInt64("uid") diff --git a/routers/web/admin/users_test.go b/routers/web/admin/users_test.go index 1849781bc4..46133688a5 100644 --- a/routers/web/admin/users_test.go +++ b/routers/web/admin/users_test.go @@ -19,7 +19,6 @@ import ( ) func TestNewUserPost_MustChangePassword(t *testing.T) { - unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "admin/users/new") diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index d6b3635584..ce8ec8a1e3 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -297,7 +297,7 @@ func handleSignIn(ctx *context.Context, u *user_model.User, remember bool) { ctx.Redirect(redirect) } -func handleSignInFull(ctx *context.Context, u *user_model.User, remember bool, obeyRedirect bool) string { +func handleSignInFull(ctx *context.Context, u *user_model.User, remember, obeyRedirect bool) string { if remember { days := 86400 * setting.LogInRememberDays ctx.SetCookie(setting.CookieUserName, u.Name, days) @@ -417,7 +417,7 @@ func SignUp(ctx *context.Context) { ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey ctx.Data["PageIsSignUp"] = true - //Show Disabled Registration message if DisableRegistration or AllowOnlyExternalRegistration options are true + // Show Disabled Registration message if DisableRegistration or AllowOnlyExternalRegistration options are true ctx.Data["DisableRegistration"] = setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration ctx.HTML(http.StatusOK, tplSignUp) @@ -438,7 +438,7 @@ func SignUpPost(ctx *context.Context) { ctx.Data["HcaptchaSitekey"] = setting.Service.HcaptchaSitekey ctx.Data["PageIsSignUp"] = true - //Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true + // Permission denied if DisableRegistration or AllowOnlyExternalRegistration options are true if setting.Service.DisableRegistration || setting.Service.AllowOnlyExternalRegistration { ctx.Error(http.StatusForbidden) return diff --git a/routers/web/auth/linkaccount.go b/routers/web/auth/linkaccount.go index 27eb954a58..bf5fb83265 100644 --- a/routers/web/auth/linkaccount.go +++ b/routers/web/auth/linkaccount.go @@ -27,9 +27,7 @@ import ( "github.com/markbates/goth" ) -var ( - tplLinkAccount base.TplName = "user/auth/link_account" -) +var tplLinkAccount base.TplName = "user/auth/link_account" // LinkAccount shows the page where the user can decide to login or create a new account func LinkAccount(ctx *context.Context) { diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index fa2b0aa65f..7bf1adf308 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -1158,5 +1158,4 @@ func oAuth2UserLoginCallback(authSource *auth.Source, request *http.Request, res // no user found to login return nil, gothUser, nil - } diff --git a/routers/web/auth/openid.go b/routers/web/auth/openid.go index 4395641795..e0c6069546 100644 --- a/routers/web/auth/openid.go +++ b/routers/web/auth/openid.go @@ -67,7 +67,6 @@ func SignInOpenID(ctx *context.Context) { // Check if the given OpenID URI is allowed by blacklist/whitelist func allowedOpenIDURI(uri string) (err error) { - // In case a Whitelist is present, URI must be in it // in order to be accepted if len(setting.Service.OpenIDWhitelist) != 0 { @@ -144,13 +143,12 @@ func SignInOpenIDPost(ctx *context.Context) { // signInOpenIDVerify handles response from OpenID provider func signInOpenIDVerify(ctx *context.Context) { - log.Trace("Incoming call to: %s", ctx.Req.URL.String()) fullURL := setting.AppURL + ctx.Req.URL.String()[1:] log.Trace("Full URL: %s", fullURL) - var id, err = openid.Verify(fullURL) + id, err := openid.Verify(fullURL) if err != nil { ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{ Openid: id, diff --git a/routers/web/auth/webauthn.go b/routers/web/auth/webauthn.go index 77b1bee18a..bedbe7ddc3 100644 --- a/routers/web/auth/webauthn.go +++ b/routers/web/auth/webauthn.go @@ -33,7 +33,7 @@ func WebAuthn(ctx *context.Context) { return } - //Ensure user is in a 2FA session. + // Ensure user is in a 2FA session. if ctx.Session.Get("twofaUid") == nil { ctx.ServerError("UserSignIn", errors.New("not in WebAuthn session")) return diff --git a/routers/web/base.go b/routers/web/base.go index fd942d3c87..f7eb003cc4 100644 --- a/routers/web/base.go +++ b/routers/web/base.go @@ -92,7 +92,7 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor return } - //If we have matched and access to release or issue + // If we have matched and access to release or issue fr, err := objStore.Open(rPath) if err != nil { if os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) { @@ -125,7 +125,7 @@ func (d *dataStore) GetData() map[string]interface{} { // Recovery returns a middleware that recovers from any panics and writes a 500 and a log if so. // This error will be created with the gitea 500 page. func Recovery() func(next http.Handler) http.Handler { - var rnd = templates.HTMLRenderer() + rnd := templates.HTMLRenderer() return func(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { defer func() { @@ -136,14 +136,14 @@ func Recovery() func(next http.Handler) http.Handler { sessionStore := session.GetSession(req) - var lc = middleware.Locale(w, req) - var store = dataStore{ + lc := middleware.Locale(w, req) + store := dataStore{ "Language": lc.Language(), "CurrentURL": setting.AppSubURL + req.URL.RequestURI(), "i18n": lc, } - var user = context.GetContextUser(req) + user := context.GetContextUser(req) if user == nil { // Get user from session if logged in - do not attempt to sign-in user = auth.SessionUser(sessionStore) diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index b61f25a96c..d2acefde92 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -76,7 +76,7 @@ func Code(ctx *context.Context) { return } - var rightRepoMap = make(map[int64]*repo_model.Repository, len(repoMaps)) + rightRepoMap := make(map[int64]*repo_model.Repository, len(repoMaps)) repoIDs = make([]int64, 0, len(repoMaps)) for id, repo := range repoMaps { if models.CheckRepoUnitUser(repo, ctx.User, unit.TypeCode) { @@ -100,7 +100,7 @@ func Code(ctx *context.Context) { return } - var loadRepoIDs = make([]int64, 0, len(searchResults)) + loadRepoIDs := make([]int64, 0, len(searchResults)) for _, result := range searchResults { var find bool for _, id := range loadRepoIDs { diff --git a/routers/web/explore/user.go b/routers/web/explore/user.go index 27634c3d4e..b264bf1b4a 100644 --- a/routers/web/explore/user.go +++ b/routers/web/explore/user.go @@ -25,9 +25,7 @@ const ( // UserSearchDefaultSortType is the default sort type for user search const UserSearchDefaultSortType = "alphabetically" -var ( - nullByte = []byte{0x00} -) +var nullByte = []byte{0x00} func isKeywordValid(keyword string) bool { return !bytes.Contains([]byte(keyword), nullByte) diff --git a/routers/web/org/home.go b/routers/web/org/home.go index 43f6211af3..cf23a1e291 100644 --- a/routers/web/org/home.go +++ b/routers/web/org/home.go @@ -110,7 +110,7 @@ func Home(ctx *context.Context) { return } - var opts = &models.FindOrgMembersOpts{ + opts := &models.FindOrgMembersOpts{ OrgID: org.ID, PublicOnly: true, ListOptions: db.ListOptions{Page: 1, PageSize: 25}, diff --git a/routers/web/org/members.go b/routers/web/org/members.go index e9b7317c98..b8e7fa1ff5 100644 --- a/routers/web/org/members.go +++ b/routers/web/org/members.go @@ -31,7 +31,7 @@ func Members(ctx *context.Context) { page = 1 } - var opts = &models.FindOrgMembersOpts{ + opts := &models.FindOrgMembersOpts{ OrgID: org.ID, PublicOnly: true, } diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index 747a5134b4..404aac8894 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -117,7 +117,8 @@ func SettingsPost(ctx *context.Context) { // update forks visibility if visibilityChanged { repos, _, err := models.GetUserRepositories(&models.SearchRepoOptions{ - Actor: org.AsUser(), Private: true, ListOptions: db.ListOptions{Page: 1, PageSize: org.NumRepos}}) + Actor: org.AsUser(), Private: true, ListOptions: db.ListOptions{Page: 1, PageSize: org.NumRepos}, + }) if err != nil { ctx.ServerError("GetRepositories", err) return diff --git a/routers/web/repo/attachment.go b/routers/web/repo/attachment.go index 303eee24d1..4101d81ac5 100644 --- a/routers/web/repo/attachment.go +++ b/routers/web/repo/attachment.go @@ -100,12 +100,12 @@ func GetAttachment(ctx *context.Context) { return } - if repository == nil { //If not linked - if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) { //We block if not the uploader + if repository == nil { // If not linked + if !(ctx.IsSigned && attach.UploaderID == ctx.User.ID) { // We block if not the uploader ctx.Error(http.StatusNotFound) return } - } else { //If we have the repository we check access + } else { // If we have the repository we check access perm, err := models.GetUserRepoPermission(repository, ctx.User) if err != nil { ctx.Error(http.StatusInternalServerError, "GetUserRepoPermission", err.Error()) @@ -123,7 +123,7 @@ func GetAttachment(ctx *context.Context) { } if setting.Attachment.ServeDirect { - //If we have a signed url (S3, object storage), redirect to this directly. + // If we have a signed url (S3, object storage), redirect to this directly. u, err := storage.Attachments.URL(attach.RelativePath(), attach.Name) if u != nil && err == nil { @@ -136,7 +136,7 @@ func GetAttachment(ctx *context.Context) { return } - //If we have matched and access to release or issue + // If we have matched and access to release or issue fr, err := storage.Attachments.Open(attach.RelativePath()) if err != nil { ctx.ServerError("Open", err) diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go index bff6a039e8..588e432e3a 100644 --- a/routers/web/repo/blame.go +++ b/routers/web/repo/blame.go @@ -233,12 +233,12 @@ func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames m language = "" } } - var lines = make([]string, 0) + lines := make([]string, 0) rows := make([]*blameRow, 0) escapeStatus := charset.EscapeStatus{} - var i = 0 - var commitCnt = 0 + i := 0 + commitCnt := 0 for _, part := range blameParts { for index, line := range part.Lines { i++ diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index ed1b2a9b1a..5d19fd1185 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -203,7 +203,7 @@ func loadBranches(ctx *context.Context, skip, limit int) (*Branch, []*Branch, in continue } - var branch = loadOneBranch(ctx, rawBranches[i], defaultBranch, protectedBranches, repoIDToRepo, repoIDToGitRepo) + branch := loadOneBranch(ctx, rawBranches[i], defaultBranch, protectedBranches, repoIDToRepo, repoIDToGitRepo) if branch == nil { return nil, nil, 0 } diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 22e6be2021..cdb6f9d7fe 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -111,7 +111,7 @@ func setCsvCompareContext(ctx *context.Context) { Error string } - ctx.Data["CreateCsvDiff"] = func(diffFile *gitdiff.DiffFile, baseCommit *git.Commit, headCommit *git.Commit) CsvDiffResult { + ctx.Data["CreateCsvDiff"] = func(diffFile *gitdiff.DiffFile, baseCommit, headCommit *git.Commit) CsvDiffResult { if diffFile == nil || baseCommit == nil || headCommit == nil { return CsvDiffResult{nil, ""} } @@ -541,8 +541,8 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { func PrepareCompareDiff( ctx *context.Context, ci *CompareInfo, - whitespaceBehavior string) bool { - + whitespaceBehavior string, +) bool { var ( repo = ctx.Repo.Repository err error @@ -839,7 +839,8 @@ func ExcerptBlob(ctx *context.Context) { RightIdx: idxRight, LeftHunkSize: leftHunkSize, RightHunkSize: rightHunkSize, - }} + }, + } if direction == "up" { section.Lines = append([]*gitdiff.DiffLine{lineSection}, section.Lines...) } else if direction == "down" { diff --git a/routers/web/repo/download.go b/routers/web/repo/download.go index 430de24c69..72d34cb937 100644 --- a/routers/web/repo/download.go +++ b/routers/web/repo/download.go @@ -52,7 +52,7 @@ func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob) error { } if setting.LFS.ServeDirect { - //If we have a signed url (S3, object storage), redirect to this directly. + // If we have a signed url (S3, object storage), redirect to this directly. u, err := storage.LFS.URL(pointer.RelativePath(), blob.Name()) if u != nil && err == nil { ctx.Redirect(u.String()) diff --git a/routers/web/repo/editor_test.go b/routers/web/repo/editor_test.go index 77f94ff550..ab7532ebb5 100644 --- a/routers/web/repo/editor_test.go +++ b/routers/web/repo/editor_test.go @@ -17,7 +17,7 @@ import ( func TestCleanUploadName(t *testing.T) { unittest.PrepareTestEnv(t) - var kases = map[string]string{ + kases := map[string]string{ ".git/refs/master": "", "/root/abc": "root/abc", "./../../abc": "abc", diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index 5e73843920..3805ceea76 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -104,7 +104,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { } isWiki := false - var unitType = unit.TypeCode + unitType := unit.TypeCode var wikiRepoName string if strings.HasSuffix(reponame, ".wiki") { isWiki = true @@ -457,7 +457,6 @@ func serviceRPC(ctx gocontext.Context, h serviceHandler, service string) { if err := h.r.Body.Close(); err != nil { log.Error("serviceRPC: Close: %v", err) } - }() if !hasAccess(ctx, service, h, true) { @@ -468,7 +467,7 @@ func serviceRPC(ctx gocontext.Context, h serviceHandler, service string) { h.w.Header().Set("Content-Type", fmt.Sprintf("application/x-git-%s-result", service)) var err error - var reqBody = h.r.Body + reqBody := h.r.Body // Handle GZIP. if h.r.Header.Get("Content-Encoding") == "gzip" { diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index ba871127f7..aff5fa8498 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -57,17 +57,15 @@ const ( issueTemplateTitleKey = "IssueTemplateTitle" ) -var ( - // IssueTemplateCandidates issue templates - IssueTemplateCandidates = []string{ - "ISSUE_TEMPLATE.md", - "issue_template.md", - ".gitea/ISSUE_TEMPLATE.md", - ".gitea/issue_template.md", - ".github/ISSUE_TEMPLATE.md", - ".github/issue_template.md", - } -) +// IssueTemplateCandidates issue templates +var IssueTemplateCandidates = []string{ + "ISSUE_TEMPLATE.md", + "issue_template.md", + ".gitea/ISSUE_TEMPLATE.md", + ".gitea/issue_template.md", + ".github/ISSUE_TEMPLATE.md", + ".github/issue_template.md", +} // MustAllowUserComment checks to make sure if an issue is locked. // If locked and user has permissions to write to the repository, @@ -245,7 +243,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti } } - var issueList = models.IssueList(issues) + issueList := models.IssueList(issues) approvalCounts, err := issueList.GetApprovalCounts() if err != nil { ctx.ServerError("ApprovalCounts", err) @@ -311,8 +309,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti assigneeID = 0 // Reset ID to prevent unexpected selection of assignee. } - ctx.Data["IssueRefEndNames"], ctx.Data["IssueRefURLs"] = - issue_service.GetRefEndNamesAndURLs(issues, ctx.Repo.RepoLink) + ctx.Data["IssueRefEndNames"], ctx.Data["IssueRefURLs"] = issue_service.GetRefEndNamesAndURLs(issues, ctx.Repo.RepoLink) ctx.Data["ApprovalCounts"] = func(issueID int64, typ string) int64 { counts, ok := approvalCounts[issueID] @@ -442,7 +439,6 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R } func retrieveProjects(ctx *context.Context, repo *repo_model.Repository) { - var err error ctx.Data["OpenProjects"], _, err = models.GetProjects(models.ProjectSearchOptions{ @@ -2508,7 +2504,7 @@ func filterXRefComments(ctx *context.Context, issue *models.Issue) error { // GetIssueAttachments returns attachments for the issue func GetIssueAttachments(ctx *context.Context) { issue := GetActionIssue(ctx) - var attachments = make([]*api.Attachment, len(issue.Attachments)) + attachments := make([]*api.Attachment, len(issue.Attachments)) for i := 0; i < len(issue.Attachments); i++ { attachments[i] = convert.ToReleaseAttachment(issue.Attachments[i]) } @@ -2522,7 +2518,7 @@ func GetCommentAttachments(ctx *context.Context) { ctx.NotFoundOrServerError("GetCommentByID", models.IsErrCommentNotExist, err) return } - var attachments = make([]*api.Attachment, 0) + attachments := make([]*api.Attachment, 0) if comment.Type == models.CommentTypeComment { if err := comment.LoadAttachments(); err != nil { ctx.ServerError("LoadAttachments", err) @@ -2667,7 +2663,7 @@ func handleTeamMentions(ctx *context.Context) { var isAdmin bool var err error var teams []*models.Team - var org = models.OrgFromUser(ctx.Repo.Owner) + org := models.OrgFromUser(ctx.Repo.Owner) // Admin has super access. if ctx.User.IsAdmin { isAdmin = true diff --git a/routers/web/repo/issue_content_history.go b/routers/web/repo/issue_content_history.go index 08eb98acb8..75951ca25b 100644 --- a/routers/web/repo/issue_content_history.go +++ b/routers/web/repo/issue_content_history.go @@ -83,8 +83,8 @@ func GetContentHistoryList(ctx *context.Context) { // canSoftDeleteContentHistory checks whether current user can soft-delete a history revision // Admins or owners can always delete history revisions. Normal users can only delete own history revisions. func canSoftDeleteContentHistory(ctx *context.Context, issue *models.Issue, comment *models.Comment, - history *issuesModel.ContentHistory) bool { - + history *issuesModel.ContentHistory, +) bool { canSoftDelete := false if ctx.Repo.IsOwner() { canSoftDelete = true @@ -103,7 +103,7 @@ func canSoftDeleteContentHistory(ctx *context.Context, issue *models.Issue, comm return canSoftDelete } -//GetContentHistoryDetail get detail +// GetContentHistoryDetail get detail func GetContentHistoryDetail(ctx *context.Context) { issue := GetActionIssue(ctx) if issue == nil { @@ -169,7 +169,7 @@ func GetContentHistoryDetail(ctx *context.Context) { }) } -//SoftDeleteContentHistory soft delete +// SoftDeleteContentHistory soft delete func SoftDeleteContentHistory(ctx *context.Context) { issue := GetActionIssue(ctx) if issue == nil { diff --git a/routers/web/repo/issue_lock.go b/routers/web/repo/issue_lock.go index 36894b4be3..103b60c65d 100644 --- a/routers/web/repo/issue_lock.go +++ b/routers/web/repo/issue_lock.go @@ -48,7 +48,6 @@ func LockIssue(ctx *context.Context) { // UnlockIssue unlocks a previously locked issue. func UnlockIssue(ctx *context.Context) { - issue := GetActionIssue(ctx) if ctx.Written() { return diff --git a/routers/web/repo/issue_test.go b/routers/web/repo/issue_test.go index b8862cf43d..debd2a8a3c 100644 --- a/routers/web/repo/issue_test.go +++ b/routers/web/repo/issue_test.go @@ -13,7 +13,7 @@ import ( ) func TestCombineLabelComments(t *testing.T) { - var kases = []struct { + kases := []struct { name string beforeCombined []*models.Comment afterCombined []*models.Comment @@ -366,7 +366,7 @@ func TestCombineLabelComments(t *testing.T) { for _, kase := range kases { t.Run(kase.name, func(t *testing.T) { - var issue = models.Issue{ + issue := models.Issue{ Comments: kase.beforeCombined, } combineLabelComments(&issue) diff --git a/routers/web/repo/lfs.go b/routers/web/repo/lfs.go index 6b5e1dd624..2cb4330c08 100644 --- a/routers/web/repo/lfs.go +++ b/routers/web/repo/lfs.go @@ -305,7 +305,7 @@ func LFSFileGet(ctx *context.Context) { var output bytes.Buffer lines := strings.Split(escapedContent.String(), "\n") - //Remove blank line at the end of file + // Remove blank line at the end of file if len(lines) > 0 && lines[len(lines)-1] == "" { lines = lines[:len(lines)-1] } @@ -536,7 +536,7 @@ func LFSAutoAssociate(ctx *context.Context) { return } metas[i].Oid = oid[:idx] - //metas[i].RepositoryID = ctx.Repo.Repository.ID + // metas[i].RepositoryID = ctx.Repo.Repository.ID } if err := models.LFSAutoAssociate(metas, ctx.User, ctx.Repo.Repository.ID); err != nil { ctx.ServerError("LFSAutoAssociate", err) diff --git a/routers/web/repo/migrate.go b/routers/web/repo/migrate.go index 23e5b21b48..9a31d809d4 100644 --- a/routers/web/repo/migrate.go +++ b/routers/web/repo/migrate.go @@ -203,7 +203,7 @@ func MigratePost(ctx *context.Context) { } } - var opts = migrations.MigrateOptions{ + opts := migrations.MigrateOptions{ OriginalURL: form.CloneAddr, GitServiceType: form.Service, CloneAddr: remoteAddr, diff --git a/routers/web/repo/projects.go b/routers/web/repo/projects.go index f6be8add0b..3836a00d04 100644 --- a/routers/web/repo/projects.go +++ b/routers/web/repo/projects.go @@ -531,7 +531,6 @@ func EditProjectBoard(ctx *context.Context) { // SetDefaultProjectBoard set default board for uncategorized issues/pulls func SetDefaultProjectBoard(ctx *context.Context) { - project, board := checkProjectBoardChangePermissions(ctx) if ctx.Written() { return diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 517156863e..0aea66ca67 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -48,16 +48,14 @@ const ( pullRequestTemplateKey = "PullRequestTemplate" ) -var ( - pullRequestTemplateCandidates = []string{ - "PULL_REQUEST_TEMPLATE.md", - "pull_request_template.md", - ".gitea/PULL_REQUEST_TEMPLATE.md", - ".gitea/pull_request_template.md", - ".github/PULL_REQUEST_TEMPLATE.md", - ".github/pull_request_template.md", - } -) +var pullRequestTemplateCandidates = []string{ + "PULL_REQUEST_TEMPLATE.md", + "pull_request_template.md", + ".gitea/PULL_REQUEST_TEMPLATE.md", + ".gitea/pull_request_template.md", + ".github/PULL_REQUEST_TEMPLATE.md", + ".github/pull_request_template.md", +} func getRepository(ctx *context.Context, repoID int64) *repo_model.Repository { repo, err := repo_model.GetRepositoryByID(repoID) @@ -125,7 +123,7 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository { } } - var traverseParentRepo = forkRepo + traverseParentRepo := forkRepo for { if ctx.User.ID == traverseParentRepo.OwnerID { canForkToUser = false @@ -195,7 +193,7 @@ func ForkPost(ctx *context.Context) { } var err error - var traverseParentRepo = forkRepo + traverseParentRepo := forkRepo for { if ctxUser.ID == traverseParentRepo.OwnerID { ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form) @@ -1085,7 +1083,6 @@ func MergePullRequest(ctx *context.Context) { } func stopTimerIfAvailable(user *user_model.User, issue *models.Issue) error { - if models.StopwatchExists(user.ID, issue.ID) { if err := models.CreateOrStopIssueStopwatch(user, issue); err != nil { return err diff --git a/routers/web/repo/release.go b/routers/web/repo/release.go index 13623e15ef..4f58ac9546 100644 --- a/routers/web/repo/release.go +++ b/routers/web/repo/release.go @@ -481,7 +481,7 @@ func EditReleasePost(ctx *context.Context) { const delPrefix = "attachment-del-" const editPrefix = "attachment-edit-" var addAttachmentUUIDs, delAttachmentUUIDs []string - var editAttachments = make(map[string]string) // uuid -> new name + editAttachments := make(map[string]string) // uuid -> new name if setting.Attachment.Enabled { addAttachmentUUIDs = form.Files for k, v := range ctx.Req.Form { diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 6bd16ff2b8..89ebef3a59 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -410,7 +410,7 @@ func Download(ctx *context.Context) { } var times int - var t = time.NewTicker(time.Second * 1) + t := time.NewTicker(time.Second * 1) defer t.Stop() for { @@ -447,7 +447,7 @@ func download(ctx *context.Context, archiveName string, archiver *repo_model.Rep } if setting.RepoArchive.ServeDirect { - //If we have a signed url (S3, object storage), redirect to this directly. + // If we have a signed url (S3, object storage), redirect to this directly. u, err := storage.RepoArchives.URL(rPath, downloadName) if u != nil && err == nil { ctx.Redirect(u.String()) @@ -455,7 +455,7 @@ func download(ctx *context.Context, archiveName string, archiver *repo_model.Rep } } - //If we have matched and access to release or issue + // If we have matched and access to release or issue fr, err := storage.RepoArchives.Open(rPath) if err != nil { ctx.ServerError("Open", err) diff --git a/routers/web/repo/settings_test.go b/routers/web/repo/settings_test.go index 5b62e1ed16..bd29eca195 100644 --- a/routers/web/repo/settings_test.go +++ b/routers/web/repo/settings_test.go @@ -100,7 +100,6 @@ func TestAddReadWriteOnlyDeployKey(t *testing.T) { } func TestCollaborationPost(t *testing.T) { - unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/issues/labels") test.LoadUser(t, ctx, 2) @@ -136,7 +135,6 @@ func TestCollaborationPost(t *testing.T) { } func TestCollaborationPost_InactiveUser(t *testing.T) { - unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/issues/labels") test.LoadUser(t, ctx, 2) @@ -160,7 +158,6 @@ func TestCollaborationPost_InactiveUser(t *testing.T) { } func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { - unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/issues/labels") test.LoadUser(t, ctx, 2) @@ -202,7 +199,6 @@ func TestCollaborationPost_AddCollaboratorTwice(t *testing.T) { } func TestCollaborationPost_NonExistentUser(t *testing.T) { - unittest.PrepareTestEnv(t) ctx := test.MockContext(t, "user2/repo1/issues/labels") test.LoadUser(t, ctx, 2) @@ -302,7 +298,6 @@ func TestAddTeamPost_NotAllowed(t *testing.T) { assert.False(t, team.HasRepository(re.ID)) assert.EqualValues(t, http.StatusFound, ctx.Resp.Status()) assert.NotEmpty(t, ctx.Flash.ErrorMsg) - } func TestAddTeamPost_AddTeamTwice(t *testing.T) { diff --git a/routers/web/repo/topic.go b/routers/web/repo/topic.go index 810b241e28..a6a7ac6c8e 100644 --- a/routers/web/repo/topic.go +++ b/routers/web/repo/topic.go @@ -22,8 +22,8 @@ func TopicsPost(ctx *context.Context) { return } - var topics = make([]string, 0) - var topicsStr = ctx.FormTrim("topics") + topics := make([]string, 0) + topicsStr := ctx.FormTrim("topics") if len(topicsStr) > 0 { topics = strings.Split(topicsStr, ",") } diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index e8c02b64b8..150ace212b 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -77,7 +77,7 @@ func getReadmeFileFromPath(commit *git.Commit, treePath string) (*namedBlob, err } var readmeFiles [4]*namedBlob - var exts = []string{".md", ".txt", ""} // sorted by priority + exts := []string{".md", ".txt", ""} // sorted by priority for _, entry := range entries { if entry.IsDir() { continue @@ -150,7 +150,7 @@ func renderDirectory(ctx *context.Context, treeLink string) { // strictly match an extension var readmeFiles [4]*namedBlob var docsEntries [3]*git.TreeEntry - var exts = []string{".md", ".txt", ""} // sorted by priority + exts := []string{".md", ".txt", ""} // sorted by priority for _, entry := range entries { if entry.IsDir() { lowerName := strings.ToLower(entry.Name()) @@ -368,7 +368,6 @@ func renderDirectory(ctx *context.Context, treeLink string) { ctx.Data["CanAddFile"] = !ctx.Repo.Repository.IsArchived ctx.Data["CanUploadFile"] = setting.Repository.Upload.Enabled && !ctx.Repo.Repository.IsArchived } - } func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink string) { @@ -399,7 +398,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st isDisplayingSource := ctx.FormString("display") == "source" isDisplayingRendered := !isDisplayingSource - //Check for LFS meta file + // Check for LFS meta file if isTextFile && setting.LFS.StartServer { pointer, _ := lfs.ReadPointerFromBuffer(buf) if pointer.IsValid() { diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go index e57aa5ec29..633458081f 100644 --- a/routers/web/repo/wiki.go +++ b/routers/web/repo/wiki.go @@ -191,7 +191,7 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) { ctx.Data["title"] = pageName ctx.Data["RequireHighlightJS"] = true - //lookup filename in wiki - get filecontent, gitTree entry , real filename + // lookup filename in wiki - get filecontent, gitTree entry , real filename data, entry, pageFilename, noEntry := wikiContentsByName(ctx, commit, pageName) if noEntry { ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages") @@ -219,7 +219,7 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) { return nil, nil } - var rctx = &markup.RenderContext{ + rctx := &markup.RenderContext{ Ctx: ctx, URLPrefix: ctx.Repo.RepoLink, Metas: ctx.Repo.Repository.ComposeDocumentMetas(), @@ -291,7 +291,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name - //lookup filename in wiki - get filecontent, gitTree entry , real filename + // lookup filename in wiki - get filecontent, gitTree entry , real filename data, entry, pageFilename, noEntry := wikiContentsByName(ctx, commit, pageName) if noEntry { ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages") @@ -365,7 +365,7 @@ func renderEditPage(ctx *context.Context) { ctx.Data["title"] = pageName ctx.Data["RequireHighlightJS"] = true - //lookup filename in wiki - get filecontent, gitTree entry , real filename + // lookup filename in wiki - get filecontent, gitTree entry , real filename data, entry, _, noEntry := wikiContentsByName(ctx, commit, pageName) if noEntry { ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages") diff --git a/routers/web/repo/wiki_test.go b/routers/web/repo/wiki_test.go index 1bfda50d19..b19c628a9f 100644 --- a/routers/web/repo/wiki_test.go +++ b/routers/web/repo/wiki_test.go @@ -20,8 +20,10 @@ import ( "github.com/stretchr/testify/assert" ) -const content = "Wiki contents for unit tests" -const message = "Wiki commit message for unit tests" +const ( + content = "Wiki contents for unit tests" + message = "Wiki commit message for unit tests" +) func wikiEntry(t *testing.T, repo *repo_model.Repository, wikiName string) *git.TreeEntry { wikiRepo, err := git.OpenRepository(repo.WikiPath()) diff --git a/routers/web/user/home.go b/routers/web/user/home.go index 04459573af..13fa9bd8c4 100644 --- a/routers/web/user/home.go +++ b/routers/web/user/home.go @@ -197,7 +197,7 @@ func Milestones(ctx *context.Context) { if issueReposQueryPattern.MatchString(reposQuery) { // remove "[" and "]" from string reposQuery = reposQuery[1 : len(reposQuery)-1] - //for each ID (delimiter ",") add to int to repoIDs + // for each ID (delimiter ",") add to int to repoIDs for _, rID := range strings.Split(reposQuery, ",") { // Ensure nonempty string entries @@ -350,7 +350,6 @@ func Issues(ctx *context.Context) { var issueReposQueryPattern = regexp.MustCompile(`^\[\d+(,\d+)*,?\]$`) func buildIssueOverview(ctx *context.Context, unitType unit.Type) { - // ---------------------------------------------------- // Determine user; can be either user or organization. // Return with NotFound or ServerError if unsuccessful. @@ -586,8 +585,7 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) { ctx.Data["IsShowClosed"] = isShowClosed - ctx.Data["IssueRefEndNames"], ctx.Data["IssueRefURLs"] = - issue_service.GetRefEndNamesAndURLs(issues, ctx.FormString("RepoLink")) + ctx.Data["IssueRefEndNames"], ctx.Data["IssueRefURLs"] = issue_service.GetRefEndNamesAndURLs(issues, ctx.FormString("RepoLink")) ctx.Data["Issues"] = issues @@ -661,7 +659,7 @@ func getRepoIDs(reposQuery string) []int64 { var repoIDs []int64 // remove "[" and "]" from string reposQuery = reposQuery[1 : len(reposQuery)-1] - //for each ID (delimiter ",") add to int to repoIDs + // for each ID (delimiter ",") add to int to repoIDs for _, rID := range strings.Split(reposQuery, ",") { // Ensure nonempty string entries if rID != "" && rID != "0" { @@ -693,8 +691,8 @@ func issueIDsFromSearch(ctxUser *user_model.User, keyword string, opts *models.I } func loadRepoByIDs(ctxUser *user_model.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*repo_model.Repository, error) { - var totalRes = make(map[int64]*repo_model.Repository, len(issueCountByRepo)) - var repoIDs = make([]int64, 0, 500) + totalRes := make(map[int64]*repo_model.Repository, len(issueCountByRepo)) + repoIDs := make([]int64, 0, 500) for id := range issueCountByRepo { if id <= 0 { continue @@ -745,7 +743,7 @@ func ShowGPGKeys(ctx *context.Context, uid int64) { if err != nil { if asymkey_model.IsErrGPGKeyImportNotExist(err) { failedEntitiesID = append(failedEntitiesID, k.KeyID) - continue //Skip previous import without backup of imported armored key + continue // Skip previous import without backup of imported armored key } ctx.ServerError("ShowGPGKeys", err) return @@ -755,12 +753,12 @@ func ShowGPGKeys(ctx *context.Context, uid int64) { var buf bytes.Buffer headers := make(map[string]string) - if len(failedEntitiesID) > 0 { //If some key need re-import to be exported + if len(failedEntitiesID) > 0 { // If some key need re-import to be exported headers["Note"] = fmt.Sprintf("The keys with the following IDs couldn't be exported and need to be reuploaded %s", strings.Join(failedEntitiesID, ", ")) } writer, _ := armor.Encode(&buf, "PGP PUBLIC KEY BLOCK", headers) for _, e := range entities { - err = e.Serialize(writer) //TODO find why key are exported with a different cipherTypeByte as original (should not be blocking but strange) + err = e.Serialize(writer) // TODO find why key are exported with a different cipherTypeByte as original (should not be blocking but strange) if err != nil { ctx.ServerError("ShowGPGKeys", err) return diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go index 40fc44ed14..86ecb7c02c 100644 --- a/routers/web/user/profile.go +++ b/routers/web/user/profile.go @@ -258,7 +258,8 @@ func Profile(ctx *context.Context) { total = ctxUser.NumFollowing case "activity": - ctx.Data["Feeds"] = feed.RetrieveFeeds(ctx, models.GetFeedsOptions{RequestedUser: ctxUser, + ctx.Data["Feeds"] = feed.RetrieveFeeds(ctx, models.GetFeedsOptions{ + RequestedUser: ctxUser, Actor: ctx.User, IncludePrivate: showPrivate, OnlyPerformedBy: true, diff --git a/routers/web/user/setting/account_test.go b/routers/web/user/setting/account_test.go index cd5c77795e..a67d09e9ed 100644 --- a/routers/web/user/setting/account_test.go +++ b/routers/web/user/setting/account_test.go @@ -20,9 +20,9 @@ import ( func TestChangePassword(t *testing.T) { oldPassword := "password" setting.MinPasswordLength = 6 - var pcALL = []string{"lower", "upper", "digit", "spec"} - var pcLUN = []string{"lower", "upper", "digit"} - var pcLU = []string{"lower", "upper"} + pcALL := []string{"lower", "upper", "digit", "spec"} + pcLUN := []string{"lower", "upper", "digit"} + pcLU := []string{"lower", "upper"} for _, req := range []struct { OldPassword string diff --git a/routers/web/user/setting/keys.go b/routers/web/user/setting/keys.go index 26bbf7c195..f926c1f311 100644 --- a/routers/web/user/setting/keys.go +++ b/routers/web/user/setting/keys.go @@ -211,7 +211,6 @@ func KeysPost(ctx *context.Context) { ctx.Flash.Warning("Function not implemented") ctx.Redirect(setting.AppSubURL + "/user/settings/keys") } - } // DeleteKey response for delete user's SSH/GPG key diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index ab156b43fc..3a61f2f92a 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -415,5 +415,4 @@ func UpdateUserLang(ctx *context.Context) { log.Trace("User settings updated: %s", ctx.User.Name) ctx.Flash.Success(i18n.Tr(ctx.User.Language, "settings.update_language_success")) ctx.Redirect(setting.AppSubURL + "/user/settings/appearance") - } diff --git a/routers/web/web.go b/routers/web/web.go index e934095b79..698f91b8ca 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -56,9 +56,9 @@ const ( func CorsHandler() func(next http.Handler) http.Handler { if setting.CORSConfig.Enabled { return 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, MaxAge: int(setting.CORSConfig.MaxAge.Seconds()), @@ -459,7 +459,6 @@ func RegisterRoutes(m *web.Route) { m.Post("/msteams/new", bindIgnErr(forms.NewMSTeamsHookForm{}), repo.MSTeamsHooksNewPost) m.Post("/feishu/new", bindIgnErr(forms.NewFeishuHookForm{}), repo.FeishuHooksNewPost) m.Post("/wechatwork/new", bindIgnErr(forms.NewWechatWorkHookForm{}), repo.WechatworkHooksNewPost) - }) m.Group("/auths", func() { @@ -691,7 +690,6 @@ func RegisterRoutes(m *web.Route) { m.Post("/{lid}/unlock", repo.LFSUnlock) }) }) - }, func(ctx *context.Context) { ctx.Data["PageIsSettings"] = true ctx.Data["LFSStartServer"] = setting.LFS.StartServer @@ -818,7 +816,6 @@ func RegisterRoutes(m *web.Route) { m.Post("/delete", repo.DeleteBranchPost) m.Post("/restore", repo.RestoreBranchPost) }, context.RepoMustNotBeArchived(), reqRepoCodeWriter, repo.MustBeNotEmpty) - }, reqSignIn, context.RepoAssignment, context.UnitTypes()) // Releases @@ -857,7 +854,6 @@ func RegisterRoutes(m *web.Route) { } ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount }) - }, ignSignIn, context.RepoAssignment, context.UnitTypes(), reqRepoReleaseReader) // to maintain compatibility with old attachments @@ -1085,5 +1081,4 @@ func RegisterRoutes(m *web.Route) { ctx := context.GetContext(req) ctx.NotFound("", nil) }) - } |