1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

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
423 changed files with 1585 additions and 1758 deletions

View File

@@ -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], ":")

View File

@@ -11,7 +11,7 @@ import (
)
func TestShadowPassword(t *testing.T) {
var kases = []struct {
kases := []struct {
Provider string
CfgItem string
Result string

View File

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

View File

@@ -19,7 +19,6 @@ import (
)
func TestNewUserPost_MustChangePassword(t *testing.T) {
unittest.PrepareTestEnv(t)
ctx := test.MockContext(t, "admin/users/new")

View File

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

View File

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

View File

@@ -1158,5 +1158,4 @@ func oAuth2UserLoginCallback(authSource *auth.Source, request *http.Request, res
// no user found to login
return nil, gothUser, nil
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -31,7 +31,7 @@ func Members(ctx *context.Context) {
page = 1
}
var opts = &models.FindOrgMembersOpts{
opts := &models.FindOrgMembersOpts{
OrgID: org.ID,
PublicOnly: true,
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -203,7 +203,7 @@ func MigratePost(ctx *context.Context) {
}
}
var opts = migrations.MigrateOptions{
opts := migrations.MigrateOptions{
OriginalURL: form.CloneAddr,
GitServiceType: form.Service,
CloneAddr: remoteAddr,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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