diff options
author | 6543 <6543@obermui.de> | 2021-04-09 09:40:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-09 09:40:34 +0200 |
commit | 9c4601bdf8369ed72944085e3952111cf4aeea11 (patch) | |
tree | 2dcadaabed6dbe14ddba2d2513b736ff6b7f089f /models | |
parent | 0991f9aa427ab923544c35d73232fa53c9db9120 (diff) | |
download | gitea-9c4601bdf8369ed72944085e3952111cf4aeea11.tar.gz gitea-9c4601bdf8369ed72944085e3952111cf4aeea11.zip |
Code Formats, Nits & Unused Func/Var deletions (#15286)
* _ to unused func options
* rm useless brakets
* rm trifial non used models functions
* rm dead code
* rm dead global vars
* fix routers/api/v1/repo/issue.go
* dont overload import module
Diffstat (limited to 'models')
-rw-r--r-- | models/branches.go | 19 | ||||
-rw-r--r-- | models/issue_label.go | 13 | ||||
-rw-r--r-- | models/lfs.go | 4 | ||||
-rw-r--r-- | models/repo_test.go | 2 | ||||
-rw-r--r-- | models/user.go | 3 | ||||
-rw-r--r-- | models/user_heatmap.go | 2 | ||||
-rw-r--r-- | models/user_openid.go | 6 |
7 files changed, 5 insertions, 44 deletions
diff --git a/models/branches.go b/models/branches.go index 440c093095..1ac1fa49e5 100644 --- a/models/branches.go +++ b/models/branches.go @@ -260,12 +260,6 @@ func (protectBranch *ProtectedBranch) IsProtectedFile(patterns []glob.Glob, path return r } -// GetProtectedBranchByRepoID getting protected branch by repo ID -func GetProtectedBranchByRepoID(repoID int64) ([]*ProtectedBranch, error) { - protectedBranches := make([]*ProtectedBranch, 0) - return protectedBranches, x.Where("repo_id = ?", repoID).Desc("updated_unix").Find(&protectedBranches) -} - // GetProtectedBranchBy getting protected branch by ID/Name func GetProtectedBranchBy(repoID int64, branchName string) (*ProtectedBranch, error) { return getProtectedBranchBy(x, repoID, branchName) @@ -283,19 +277,6 @@ func getProtectedBranchBy(e Engine, repoID int64, branchName string) (*Protected return rel, nil } -// GetProtectedBranchByID getting protected branch by ID -func GetProtectedBranchByID(id int64) (*ProtectedBranch, error) { - rel := &ProtectedBranch{} - has, err := x.ID(id).Get(rel) - if err != nil { - return nil, err - } - if !has { - return nil, nil - } - return rel, nil -} - // WhitelistOptions represent all sorts of whitelists used for protected branches type WhitelistOptions struct { UserIDs []int64 diff --git a/models/issue_label.go b/models/issue_label.go index 4f082b8a6e..d1ff469236 100644 --- a/models/issue_label.go +++ b/models/issue_label.go @@ -510,19 +510,6 @@ func GetLabelIDsInOrgByNames(orgID int64, labelNames []string) ([]int64, error) Find(&labelIDs) } -// GetLabelIDsInOrgsByNames returns a list of labelIDs by names in one of the given -// organization. -// it silently ignores label names that do not belong to the organization. -func GetLabelIDsInOrgsByNames(orgIDs []int64, labelNames []string) ([]int64, error) { - labelIDs := make([]int64, 0, len(labelNames)) - return labelIDs, x.Table("label"). - In("org_id", orgIDs). - In("name", labelNames). - Asc("name"). - Cols("id"). - Find(&labelIDs) -} - // GetLabelInOrgByID returns a label by ID in given organization. func GetLabelInOrgByID(orgID, labelID int64) (*Label, error) { return getLabelInOrgByID(x, orgID, labelID) diff --git a/models/lfs.go b/models/lfs.go index 90f6523d4a..c8abb1cd49 100644 --- a/models/lfs.go +++ b/models/lfs.go @@ -131,11 +131,11 @@ func (repo *Repository) CountLFSMetaObjects() (int64, error) { func LFSObjectAccessible(user *User, oid string) (bool, error) { if user.IsAdmin { count, err := x.Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}}) - return (count > 0), err + return count > 0, err } cond := accessibleRepositoryCondition(user) count, err := x.Where(cond).Join("INNER", "repository", "`lfs_meta_object`.repository_id = `repository`.id").Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}}) - return (count > 0), err + return count > 0, err } // LFSAutoAssociate auto associates accessible LFSMetaObjects diff --git a/models/repo_test.go b/models/repo_test.go index cd4bbcccfa..10ba2c99f8 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -75,7 +75,7 @@ func TestGetRepositoryCount(t *testing.T) { assert.NoError(t, err2) assert.NoError(t, err3) assert.Equal(t, int64(3), count) - assert.Equal(t, (privateCount + publicCount), count) + assert.Equal(t, privateCount+publicCount, count) } func TestGetPublicRepositoryCount(t *testing.T) { diff --git a/models/user.go b/models/user.go index aacf2957e3..cdb82603cd 100644 --- a/models/user.go +++ b/models/user.go @@ -76,9 +76,6 @@ const ( ) var ( - // ErrUserNotKeyOwner user does not own this key error - ErrUserNotKeyOwner = errors.New("User does not own this public key") - // ErrEmailNotExist e-mail does not exist error ErrEmailNotExist = errors.New("E-mail does not exist") diff --git a/models/user_heatmap.go b/models/user_heatmap.go index 74678459cf..0e2767212e 100644 --- a/models/user_heatmap.go +++ b/models/user_heatmap.go @@ -65,7 +65,7 @@ func getUserHeatmapData(user *User, team *Team, doer *User) ([]*UserHeatmapData, Select(groupBy+" AS timestamp, count(user_id) as contributions"). Table("action"). Where(cond). - And("created_unix > ?", (timeutil.TimeStampNow() - 31536000)). + And("created_unix > ?", timeutil.TimeStampNow()-31536000). GroupBy(groupByName). OrderBy("timestamp"). Find(&hdata) diff --git a/models/user_openid.go b/models/user_openid.go index 18cf51c6b6..597f19d77d 100644 --- a/models/user_openid.go +++ b/models/user_openid.go @@ -35,6 +35,7 @@ func GetUserOpenIDs(uid int64) ([]*UserOpenID, error) { return openids, nil } +// isOpenIDUsed returns true if the openid has been used. func isOpenIDUsed(e Engine, uri string) (bool, error) { if len(uri) == 0 { return true, nil @@ -43,11 +44,6 @@ func isOpenIDUsed(e Engine, uri string) (bool, error) { return e.Get(&UserOpenID{URI: uri}) } -// IsOpenIDUsed returns true if the openid has been used. -func IsOpenIDUsed(openid string) (bool, error) { - return isOpenIDUsed(x, openid) -} - // NOTE: make sure openid.URI is normalized already func addUserOpenID(e Engine, openid *UserOpenID) error { used, err := isOpenIDUsed(e, openid.URI) |