Skip to content

Commit 9c4601b

Browse files
authored
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
1 parent 0991f9a commit 9c4601b

33 files changed

+41
-98
lines changed

cmd/admin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func runDeleteUser(c *cli.Context) error {
512512
return models.DeleteUser(user)
513513
}
514514

515-
func runRepoSyncReleases(c *cli.Context) error {
515+
func runRepoSyncReleases(_ *cli.Context) error {
516516
if err := initDB(); err != nil {
517517
return err
518518
}
@@ -578,14 +578,14 @@ func getReleaseCount(id int64) (int64, error) {
578578
)
579579
}
580580

581-
func runRegenerateHooks(c *cli.Context) error {
581+
func runRegenerateHooks(_ *cli.Context) error {
582582
if err := initDB(); err != nil {
583583
return err
584584
}
585585
return repo_module.SyncRepositoryHooks(graceful.GetManager().ShutdownContext())
586586
}
587587

588-
func runRegenerateKeys(c *cli.Context) error {
588+
func runRegenerateKeys(_ *cli.Context) error {
589589
if err := initDB(); err != nil {
590590
return err
591591
}

cmd/hook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Gitea or set your environment appropriately.`, "")
166166
}
167167

168168
// the environment setted on serv command
169-
isWiki := (os.Getenv(models.EnvRepoIsWiki) == "true")
169+
isWiki := os.Getenv(models.EnvRepoIsWiki) == "true"
170170
username := os.Getenv(models.EnvRepoUsername)
171171
reponame := os.Getenv(models.EnvRepoName)
172172
userID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
@@ -322,7 +322,7 @@ Gitea or set your environment appropriately.`, "")
322322

323323
// the environment setted on serv command
324324
repoUser := os.Getenv(models.EnvRepoUsername)
325-
isWiki := (os.Getenv(models.EnvRepoIsWiki) == "true")
325+
isWiki := os.Getenv(models.EnvRepoIsWiki) == "true"
326326
repoName := os.Getenv(models.EnvRepoName)
327327
pusherID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
328328
pusherName := os.Getenv(models.EnvPusherName)

models/branches.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,6 @@ func (protectBranch *ProtectedBranch) IsProtectedFile(patterns []glob.Glob, path
260260
return r
261261
}
262262

263-
// GetProtectedBranchByRepoID getting protected branch by repo ID
264-
func GetProtectedBranchByRepoID(repoID int64) ([]*ProtectedBranch, error) {
265-
protectedBranches := make([]*ProtectedBranch, 0)
266-
return protectedBranches, x.Where("repo_id = ?", repoID).Desc("updated_unix").Find(&protectedBranches)
267-
}
268-
269263
// GetProtectedBranchBy getting protected branch by ID/Name
270264
func GetProtectedBranchBy(repoID int64, branchName string) (*ProtectedBranch, error) {
271265
return getProtectedBranchBy(x, repoID, branchName)
@@ -283,19 +277,6 @@ func getProtectedBranchBy(e Engine, repoID int64, branchName string) (*Protected
283277
return rel, nil
284278
}
285279

286-
// GetProtectedBranchByID getting protected branch by ID
287-
func GetProtectedBranchByID(id int64) (*ProtectedBranch, error) {
288-
rel := &ProtectedBranch{}
289-
has, err := x.ID(id).Get(rel)
290-
if err != nil {
291-
return nil, err
292-
}
293-
if !has {
294-
return nil, nil
295-
}
296-
return rel, nil
297-
}
298-
299280
// WhitelistOptions represent all sorts of whitelists used for protected branches
300281
type WhitelistOptions struct {
301282
UserIDs []int64

models/issue_label.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -510,19 +510,6 @@ func GetLabelIDsInOrgByNames(orgID int64, labelNames []string) ([]int64, error)
510510
Find(&labelIDs)
511511
}
512512

513-
// GetLabelIDsInOrgsByNames returns a list of labelIDs by names in one of the given
514-
// organization.
515-
// it silently ignores label names that do not belong to the organization.
516-
func GetLabelIDsInOrgsByNames(orgIDs []int64, labelNames []string) ([]int64, error) {
517-
labelIDs := make([]int64, 0, len(labelNames))
518-
return labelIDs, x.Table("label").
519-
In("org_id", orgIDs).
520-
In("name", labelNames).
521-
Asc("name").
522-
Cols("id").
523-
Find(&labelIDs)
524-
}
525-
526513
// GetLabelInOrgByID returns a label by ID in given organization.
527514
func GetLabelInOrgByID(orgID, labelID int64) (*Label, error) {
528515
return getLabelInOrgByID(x, orgID, labelID)

models/lfs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ func (repo *Repository) CountLFSMetaObjects() (int64, error) {
131131
func LFSObjectAccessible(user *User, oid string) (bool, error) {
132132
if user.IsAdmin {
133133
count, err := x.Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
134-
return (count > 0), err
134+
return count > 0, err
135135
}
136136
cond := accessibleRepositoryCondition(user)
137137
count, err := x.Where(cond).Join("INNER", "repository", "`lfs_meta_object`.repository_id = `repository`.id").Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
138-
return (count > 0), err
138+
return count > 0, err
139139
}
140140

141141
// LFSAutoAssociate auto associates accessible LFSMetaObjects

models/repo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestGetRepositoryCount(t *testing.T) {
7575
assert.NoError(t, err2)
7676
assert.NoError(t, err3)
7777
assert.Equal(t, int64(3), count)
78-
assert.Equal(t, (privateCount + publicCount), count)
78+
assert.Equal(t, privateCount+publicCount, count)
7979
}
8080

8181
func TestGetPublicRepositoryCount(t *testing.T) {

models/user.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ const (
7676
)
7777

7878
var (
79-
// ErrUserNotKeyOwner user does not own this key error
80-
ErrUserNotKeyOwner = errors.New("User does not own this public key")
81-
8279
// ErrEmailNotExist e-mail does not exist error
8380
ErrEmailNotExist = errors.New("E-mail does not exist")
8481

models/user_heatmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func getUserHeatmapData(user *User, team *Team, doer *User) ([]*UserHeatmapData,
6565
Select(groupBy+" AS timestamp, count(user_id) as contributions").
6666
Table("action").
6767
Where(cond).
68-
And("created_unix > ?", (timeutil.TimeStampNow() - 31536000)).
68+
And("created_unix > ?", timeutil.TimeStampNow()-31536000).
6969
GroupBy(groupByName).
7070
OrderBy("timestamp").
7171
Find(&hdata)

models/user_openid.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func GetUserOpenIDs(uid int64) ([]*UserOpenID, error) {
3535
return openids, nil
3636
}
3737

38+
// isOpenIDUsed returns true if the openid has been used.
3839
func isOpenIDUsed(e Engine, uri string) (bool, error) {
3940
if len(uri) == 0 {
4041
return true, nil
@@ -43,11 +44,6 @@ func isOpenIDUsed(e Engine, uri string) (bool, error) {
4344
return e.Get(&UserOpenID{URI: uri})
4445
}
4546

46-
// IsOpenIDUsed returns true if the openid has been used.
47-
func IsOpenIDUsed(openid string) (bool, error) {
48-
return isOpenIDUsed(x, openid)
49-
}
50-
5147
// NOTE: make sure openid.URI is normalized already
5248
func addUserOpenID(e Engine, openid *UserOpenID) error {
5349
used, err := isOpenIDUsed(e, openid.URI)

modules/markup/common/linkify.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
122122
}
123123
}
124124
}
125-
if m == nil {
126-
return nil
127-
}
125+
128126
if consumes != 0 {
129127
s := segment.WithStop(segment.Start + 1)
130128
ast.MergeOrAppendTextSegment(parent, s)

0 commit comments

Comments
 (0)