aboutsummaryrefslogtreecommitdiff
path: root/internal/db
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-03-01 14:55:03 +0800
committerGitHub <noreply@github.com>2020-03-01 14:55:03 +0800
commitf04b2d43509816ecfda93aa5d0d1fd685d9b860f (patch)
tree548c7b0b4ff2f187569e74cf99c19742a44f18aa /internal/db
parent9c65798902386341a205d52b6b3842e1dc2c751a (diff)
lint: fix some Golang CI lint issues (#5955)
Diffstat (limited to 'internal/db')
-rw-r--r--internal/db/git_diff_test.go26
-rw-r--r--internal/db/issue.go8
-rw-r--r--internal/db/login_source.go14
-rw-r--r--internal/db/mirror.go2
-rw-r--r--internal/db/org_team.go4
-rw-r--r--internal/db/repo.go16
-rw-r--r--internal/db/repo_branch.go4
-rw-r--r--internal/db/repo_editor.go4
-rw-r--r--internal/db/token.go2
-rw-r--r--internal/db/two_factor.go4
-rw-r--r--internal/db/user.go14
-rw-r--r--internal/db/user_mail.go6
-rw-r--r--internal/db/webhook.go4
13 files changed, 51 insertions, 57 deletions
diff --git a/internal/db/git_diff_test.go b/internal/db/git_diff_test.go
index d92afe9e..697e8dc7 100644
--- a/internal/db/git_diff_test.go
+++ b/internal/db/git_diff_test.go
@@ -18,24 +18,18 @@ func assertEqual(t *testing.T, s1 string, s2 template.HTML) {
}
}
-func assertLineEqual(t *testing.T, d1 *git.DiffLine, d2 *git.DiffLine) {
- if d1 != d2 {
- t.Errorf("%v should be equal %v", d1, d2)
- }
-}
-
func Test_diffToHTML(t *testing.T) {
assertEqual(t, "+foo <span class=\"added-code\">bar</span> biz", diffToHTML([]dmp.Diff{
- dmp.Diff{dmp.DiffEqual, "foo "},
- dmp.Diff{dmp.DiffInsert, "bar"},
- dmp.Diff{dmp.DiffDelete, " baz"},
- dmp.Diff{dmp.DiffEqual, " biz"},
- }, git.DIFF_LINE_ADD))
+ {Type: dmp.DiffEqual, Text: "foo "},
+ {Type: dmp.DiffInsert, Text: "bar"},
+ {Type: dmp.DiffDelete, Text: " baz"},
+ {Type: dmp.DiffEqual, Text: " biz"},
+ }, git.DiffLineAdd))
assertEqual(t, "-foo <span class=\"removed-code\">bar</span> biz", diffToHTML([]dmp.Diff{
- dmp.Diff{dmp.DiffEqual, "foo "},
- dmp.Diff{dmp.DiffDelete, "bar"},
- dmp.Diff{dmp.DiffInsert, " baz"},
- dmp.Diff{dmp.DiffEqual, " biz"},
- }, git.DIFF_LINE_DEL))
+ {Type: dmp.DiffEqual, Text: "foo "},
+ {Type: dmp.DiffDelete, Text: "bar"},
+ {Type: dmp.DiffInsert, Text: " baz"},
+ {Type: dmp.DiffEqual, Text: " biz"},
+ }, git.DiffLineDel))
}
diff --git a/internal/db/issue.go b/internal/db/issue.go
index 092395d8..93915244 100644
--- a/internal/db/issue.go
+++ b/internal/db/issue.go
@@ -15,8 +15,8 @@ import (
api "github.com/gogs/go-gogs-client"
- "gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/conf"
+ "gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/tool"
)
@@ -801,7 +801,7 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
func GetIssueByRef(ref string) (*Issue, error) {
n := strings.IndexByte(ref, byte('#'))
if n == -1 {
- return nil, errors.InvalidIssueReference{ref}
+ return nil, errors.InvalidIssueReference{Ref: ref}
}
index := com.StrTo(ref[n+1:]).MustInt64()
@@ -832,7 +832,7 @@ func GetRawIssueByIndex(repoID, index int64) (*Issue, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.IssueNotExist{0, repoID, index}
+ return nil, errors.IssueNotExist{RepoID: repoID, Index: index}
}
return issue, nil
}
@@ -852,7 +852,7 @@ func getRawIssueByID(e Engine, id int64) (*Issue, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.IssueNotExist{id, 0, 0}
+ return nil, errors.IssueNotExist{ID: id}
}
return issue, nil
}
diff --git a/internal/db/login_source.go b/internal/db/login_source.go
index 22b53a62..cb261f32 100644
--- a/internal/db/login_source.go
+++ b/internal/db/login_source.go
@@ -439,7 +439,7 @@ func (s *LocalLoginSources) GetLoginSourceByID(id int64) (*LoginSource, error) {
}
}
- return nil, errors.LoginSourceNotExist{id}
+ return nil, errors.LoginSourceNotExist{ID: id}
}
// UpdateLoginSource updates in-memory copy of the authentication source.
@@ -556,7 +556,7 @@ func LoginViaLDAP(user *User, login, password string, source *LoginSource, autoR
username, fn, sn, mail, isAdmin, succeed := source.Cfg.(*LDAPConfig).SearchEntry(login, password, source.Type == LOGIN_DLDAP)
if !succeed {
// User not in LDAP, do nothing
- return nil, errors.UserNotExist{0, login}
+ return nil, errors.UserNotExist{Name: login}
}
if !autoRegister {
@@ -674,9 +674,9 @@ func LoginViaSMTP(user *User, login, password string, sourceID int64, cfg *SMTPC
if len(cfg.AllowedDomains) > 0 {
idx := strings.Index(login, "@")
if idx == -1 {
- return nil, errors.UserNotExist{0, login}
+ return nil, errors.UserNotExist{Name: login}
} else if !com.IsSliceContainsStr(strings.Split(cfg.AllowedDomains, ","), login[idx+1:]) {
- return nil, errors.UserNotExist{0, login}
+ return nil, errors.UserNotExist{Name: login}
}
}
@@ -794,7 +794,7 @@ func LoginViaGitHub(user *User, login, password string, sourceID int64, cfg *Git
func remoteUserLogin(user *User, login, password string, source *LoginSource, autoRegister bool) (*User, error) {
if !source.IsActived {
- return nil, errors.LoginSourceNotActivated{source.ID}
+ return nil, errors.LoginSourceNotActivated{SourceID: source.ID}
}
switch source.Type {
@@ -808,7 +808,7 @@ func remoteUserLogin(user *User, login, password string, source *LoginSource, au
return LoginViaGitHub(user, login, password, source.ID, source.Cfg.(*GitHubConfig), autoRegister)
}
- return nil, errors.InvalidLoginSourceType{source.Type}
+ return nil, errors.InvalidLoginSourceType{Type: source.Type}
}
// UserLogin validates user name and password via given login source ID.
@@ -830,7 +830,7 @@ func UserLogin(username, password string, loginSourceID int64) (*User, error) {
// Note: This check is unnecessary but to reduce user confusion at login page
// and make it more consistent at user's perspective.
if loginSourceID >= 0 && user.LoginSource != loginSourceID {
- return nil, errors.LoginSourceMismatch{loginSourceID, user.LoginSource}
+ return nil, errors.LoginSourceMismatch{Expect: loginSourceID, Actual: user.LoginSource}
}
// Validate password hash fetched from database for local accounts
diff --git a/internal/db/mirror.go b/internal/db/mirror.go
index b85a62b2..dd767990 100644
--- a/internal/db/mirror.go
+++ b/internal/db/mirror.go
@@ -316,7 +316,7 @@ func getMirrorByRepoID(e Engine, repoID int64) (*Mirror, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.MirrorNotExist{repoID}
+ return nil, errors.MirrorNotExist{RepoID: repoID}
}
return m, nil
}
diff --git a/internal/db/org_team.go b/internal/db/org_team.go
index 7021e42d..accbfe5b 100644
--- a/internal/db/org_team.go
+++ b/internal/db/org_team.go
@@ -275,7 +275,7 @@ func getTeamOfOrgByName(e Engine, orgID int64, name string) (*Team, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.TeamNotExist{0, name}
+ return nil, errors.TeamNotExist{Name: name}
}
return t, nil
}
@@ -291,7 +291,7 @@ func getTeamByID(e Engine, teamID int64) (*Team, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.TeamNotExist{teamID, ""}
+ return nil, errors.TeamNotExist{TeamID: teamID}
}
return t, nil
}
diff --git a/internal/db/repo.go b/internal/db/repo.go
index e3d881d0..e28258e1 100644
--- a/internal/db/repo.go
+++ b/internal/db/repo.go
@@ -1106,7 +1106,7 @@ func createRepository(e *xorm.Session, doer, owner *User, repo *Repository) (err
// CreateRepository creates a repository for given user or organization.
func CreateRepository(doer, owner *User, opts CreateRepoOptions) (_ *Repository, err error) {
if !owner.CanCreateRepo() {
- return nil, errors.ReachLimitOfRepo{owner.RepoCreationNum()}
+ return nil, errors.ReachLimitOfRepo{Limit: owner.RepoCreationNum()}
}
repo := &Repository{
@@ -1486,7 +1486,7 @@ func DeleteRepository(uid, repoID int64) error {
if err != nil {
return err
} else if !has {
- return errors.RepoNotExist{repoID, uid, ""}
+ return errors.RepoNotExist{ID: repoID, UserID: uid}
}
// In case is a organization.
@@ -1603,7 +1603,7 @@ func DeleteRepository(uid, repoID int64) error {
func GetRepositoryByRef(ref string) (*Repository, error) {
n := strings.IndexByte(ref, byte('/'))
if n < 2 {
- return nil, errors.InvalidRepoReference{ref}
+ return nil, errors.InvalidRepoReference{Ref: ref}
}
userName, repoName := ref[:n], ref[n+1:]
@@ -1625,7 +1625,7 @@ func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.RepoNotExist{0, ownerID, name}
+ return nil, errors.RepoNotExist{UserID: ownerID, Name: name}
}
return repo, repo.LoadAttributes()
}
@@ -1636,7 +1636,7 @@ func getRepositoryByID(e Engine, id int64) (*Repository, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.RepoNotExist{id, 0, ""}
+ return nil, errors.RepoNotExist{ID: id}
}
return repo, repo.loadAttributes(e)
}
@@ -2356,7 +2356,7 @@ func HasForkedRepo(ownerID, repoID int64) (*Repository, bool, error) {
// ForkRepository creates a fork of target repository under another user domain.
func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string) (_ *Repository, err error) {
if !owner.CanCreateRepo() {
- return nil, errors.ReachLimitOfRepo{owner.RepoCreationNum()}
+ return nil, errors.ReachLimitOfRepo{Limit: owner.RepoCreationNum()}
}
repo := &Repository{
@@ -2390,14 +2390,14 @@ func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string)
fmt.Sprintf("ForkRepository 'git clone': %s/%s", owner.Name, repo.Name),
"git", "clone", "--bare", baseRepo.RepoPath(), repoPath)
if err != nil {
- return nil, fmt.Errorf("git clone: %v", stderr)
+ return nil, fmt.Errorf("git clone: %v - %s", err, stderr)
}
_, stderr, err = process.ExecDir(-1,
repoPath, fmt.Sprintf("ForkRepository 'git update-server-info': %s", repoPath),
"git", "update-server-info")
if err != nil {
- return nil, fmt.Errorf("git update-server-info: %v", err)
+ return nil, fmt.Errorf("git update-server-info: %v - %s", err, stderr)
}
if err = createDelegateHooks(repoPath); err != nil {
diff --git a/internal/db/repo_branch.go b/internal/db/repo_branch.go
index 3eb15fef..94313101 100644
--- a/internal/db/repo_branch.go
+++ b/internal/db/repo_branch.go
@@ -46,7 +46,7 @@ func GetBranchesByPath(path string) ([]*Branch, error) {
func (repo *Repository) GetBranch(br string) (*Branch, error) {
if !git.IsBranchExist(repo.RepoPath(), br) {
- return nil, errors.ErrBranchNotExist{br}
+ return nil, errors.ErrBranchNotExist{Name: br}
}
return &Branch{
RepoPath: repo.RepoPath(),
@@ -102,7 +102,7 @@ func GetProtectBranchOfRepoByName(repoID int64, name string) (*ProtectBranch, er
if err != nil {
return nil, err
} else if !has {
- return nil, errors.ErrBranchNotExist{name}
+ return nil, errors.ErrBranchNotExist{Name: name}
}
return protectBranch, nil
}
diff --git a/internal/db/repo_editor.go b/internal/db/repo_editor.go
index 38fea3f4..7aa1cd7a 100644
--- a/internal/db/repo_editor.go
+++ b/internal/db/repo_editor.go
@@ -21,10 +21,10 @@ import (
"github.com/gogs/git-module"
+ "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/osutil"
"gogs.io/gogs/internal/process"
- "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/tool"
)
@@ -136,7 +136,7 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
if opts.OldBranch != opts.NewBranch {
// Directly return error if new branch already exists in the server
if git.IsBranchExist(repoPath, opts.NewBranch) {
- return errors.BranchAlreadyExists{opts.NewBranch}
+ return errors.BranchAlreadyExists{Name: opts.NewBranch}
}
// Otherwise, delete branch from local copy in case out of sync
diff --git a/internal/db/token.go b/internal/db/token.go
index 2e2f3492..e7cb7e99 100644
--- a/internal/db/token.go
+++ b/internal/db/token.go
@@ -58,7 +58,7 @@ func NewAccessToken(t *AccessToken) error {
if err != nil {
return err
} else if has {
- return errors.AccessTokenNameAlreadyExist{t.Name}
+ return errors.AccessTokenNameAlreadyExist{Name: t.Name}
}
_, err = x.Insert(t)
diff --git a/internal/db/two_factor.go b/internal/db/two_factor.go
index 45b29705..a46fb992 100644
--- a/internal/db/two_factor.go
+++ b/internal/db/two_factor.go
@@ -118,7 +118,7 @@ func GetTwoFactorByUserID(userID int64) (*TwoFactor, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.TwoFactorNotFound{userID}
+ return nil, errors.TwoFactorNotFound{UserID: userID}
}
return t, nil
@@ -189,7 +189,7 @@ func UseRecoveryCode(userID int64, code string) error {
if err != nil {
return fmt.Errorf("get unused code: %v", err)
} else if !has {
- return errors.TwoFactorRecoveryCodeNotFound{code}
+ return errors.TwoFactorRecoveryCodeNotFound{Code: code}
}
recoveryCode.IsUsed = true
diff --git a/internal/db/user.go b/internal/db/user.go
index 603f1905..5f357e28 100644
--- a/internal/db/user.go
+++ b/internal/db/user.go
@@ -886,7 +886,7 @@ func GetUserByKeyID(keyID int64) (*User, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.UserNotKeyOwner{keyID}
+ return nil, errors.UserNotKeyOwner{KeyID: keyID}
}
return user, nil
}
@@ -897,7 +897,7 @@ func getUserByID(e Engine, id int64) (*User, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.UserNotExist{id, ""}
+ return nil, errors.UserNotExist{UserID: id}
}
return u, nil
}
@@ -913,7 +913,7 @@ func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.UserNotExist{userID, ""}
+ return nil, errors.UserNotExist{UserID: userID}
}
return GetUserByID(userID)
}
@@ -921,14 +921,14 @@ func GetAssigneeByID(repo *Repository, userID int64) (*User, error) {
// GetUserByName returns a user by given name.
func GetUserByName(name string) (*User, error) {
if len(name) == 0 {
- return nil, errors.UserNotExist{0, name}
+ return nil, errors.UserNotExist{Name: name}
}
u := &User{LowerName: strings.ToLower(name)}
has, err := x.Get(u)
if err != nil {
return nil, err
} else if !has {
- return nil, errors.UserNotExist{0, name}
+ return nil, errors.UserNotExist{Name: name}
}
return u, nil
}
@@ -1006,7 +1006,7 @@ func ValidateCommitsWithEmails(oldCommits *list.List) *list.List {
// GetUserByEmail returns the user object by given e-mail if exists.
func GetUserByEmail(email string) (*User, error) {
if len(email) == 0 {
- return nil, errors.UserNotExist{0, "email"}
+ return nil, errors.UserNotExist{Name: "email"}
}
email = strings.ToLower(email)
@@ -1030,7 +1030,7 @@ func GetUserByEmail(email string) (*User, error) {
return GetUserByID(emailAddress.UID)
}
- return nil, errors.UserNotExist{0, email}
+ return nil, errors.UserNotExist{Name: email}
}
type SearchUserOptions struct {
diff --git a/internal/db/user_mail.go b/internal/db/user_mail.go
index 5304f13b..440de084 100644
--- a/internal/db/user_mail.go
+++ b/internal/db/user_mail.go
@@ -165,11 +165,11 @@ func MakeEmailPrimary(email *EmailAddress) error {
if err != nil {
return err
} else if !has {
- return errors.EmailNotFound{email.Email}
+ return errors.EmailNotFound{Email: email.Email}
}
if !email.IsActivated {
- return errors.EmailNotVerified{email.Email}
+ return errors.EmailNotVerified{Email: email.Email}
}
user := &User{ID: email.UID}
@@ -177,7 +177,7 @@ func MakeEmailPrimary(email *EmailAddress) error {
if err != nil {
return err
} else if !has {
- return errors.UserNotExist{email.UID, ""}
+ return errors.UserNotExist{UserID: email.UID}
}
// Make sure the former primary email doesn't disappear.
diff --git a/internal/db/webhook.go b/internal/db/webhook.go
index c056f413..96a01971 100644
--- a/internal/db/webhook.go
+++ b/internal/db/webhook.go
@@ -242,7 +242,7 @@ func getWebhook(bean *Webhook) (*Webhook, error) {
if err != nil {
return nil, err
} else if !has {
- return nil, errors.WebhookNotExist{bean.ID}
+ return nil, errors.WebhookNotExist{ID: bean.ID}
}
return bean, nil
}
@@ -509,7 +509,7 @@ func GetHookTaskOfWebhookByUUID(webhookID int64, uuid string) (*HookTask, error)
if err != nil {
return nil, err
} else if !has {
- return nil, errors.HookTaskNotExist{webhookID, uuid}
+ return nil, errors.HookTaskNotExist{HookID: webhookID, UUID: uuid}
}
return hookTask, nil
}