mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	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
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user