Skip to content

Commit

Permalink
chore(models): rewrite code format. (#14754)
Browse files Browse the repository at this point in the history
* chore: rewrite format.

* chore: update format

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* chore: update format

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>

* chore: Adjacent parameters with the same type should be grouped together

* chore: update format.
  • Loading branch information
appleboy authored Mar 14, 2021
1 parent 164e35e commit 167b0f4
Show file tree
Hide file tree
Showing 103 changed files with 474 additions and 460 deletions.
4 changes: 2 additions & 2 deletions models/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func (user *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
}
defer rows.Close()

var repos = make(map[*Repository]AccessMode, 10)
var ownerCache = make(map[int64]*User, 10)
repos := make(map[*Repository]AccessMode, 10)
ownerCache := make(map[int64]*User, 10)
for rows.Next() {
var repo repoAccess
err = rows.Scan(&repo)
Expand Down
6 changes: 3 additions & 3 deletions models/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (a *Action) GetRepoLink() string {
}

// GetRepositoryFromMatch returns a *Repository from a username and repo strings
func GetRepositoryFromMatch(ownerName string, repoName string) (*Repository, error) {
func GetRepositoryFromMatch(ownerName, repoName string) (*Repository, error) {
var err error
refRepo, err := GetRepositoryByOwnerAndName(ownerName, repoName)
if err != nil {
Expand Down Expand Up @@ -218,7 +218,7 @@ func (a *Action) getCommentLink(e Engine) string {
if len(a.GetIssueInfos()) == 0 {
return "#"
}
//Return link to issue
// Return link to issue
issueIDString := a.GetIssueInfos()[0]
issueID, err := strconv.ParseInt(issueIDString, 10, 64)
if err != nil {
Expand Down Expand Up @@ -322,7 +322,7 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
return actions, nil
}

func activityReadable(user *User, doer *User) bool {
func activityReadable(user, doer *User) bool {
var doerID int64
if doer != nil {
doerID = doer.ID
Expand Down
4 changes: 2 additions & 2 deletions models/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
"code.gitea.io/gitea/modules/util"
)

//NoticeType describes the notice type
// NoticeType describes the notice type
type NoticeType int

const (
//NoticeRepository type
// NoticeRepository type
NoticeRepository NoticeType = iota + 1
// NoticeTask type
NoticeTask
Expand Down
6 changes: 2 additions & 4 deletions models/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
return 0, nil
}

var ids = make([]int64, 0, len(attachments))
ids := make([]int64, 0, len(attachments))
for _, a := range attachments {
ids = append(ids, a.ID)
}
Expand All @@ -216,7 +216,6 @@ func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
// DeleteAttachmentsByIssue deletes all attachments associated with the given issue.
func DeleteAttachmentsByIssue(issueID int64, remove bool) (int, error) {
attachments, err := GetAttachmentsByIssueID(issueID)

if err != nil {
return 0, err
}
Expand All @@ -227,7 +226,6 @@ func DeleteAttachmentsByIssue(issueID int64, remove bool) (int, error) {
// DeleteAttachmentsByComment deletes all attachments associated with the given comment.
func DeleteAttachmentsByComment(commentID int64, remove bool) (int, error) {
attachments, err := GetAttachmentsByCommentID(commentID)

if err != nil {
return 0, err
}
Expand Down Expand Up @@ -263,7 +261,7 @@ func IterateAttachment(f func(attach *Attachment) error) error {
var start int
const batchSize = 100
for {
var attachments = make([]*Attachment, 0, batchSize)
attachments := make([]*Attachment, 0, batchSize)
if err := x.Limit(batchSize, start).Find(&attachments); err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions models/attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ func TestUploadAttachment(t *testing.T) {

user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)

var fPath = "./attachment_test.go"
fPath := "./attachment_test.go"
f, err := os.Open(fPath)
assert.NoError(t, err)
defer f.Close()

var buf = make([]byte, 1024)
buf := make([]byte, 1024)
n, err := f.Read(buf)
assert.NoError(t, err)
buf = buf[:n]
Expand Down Expand Up @@ -152,7 +152,6 @@ func TestLinkedRepository(t *testing.T) {
assert.Equal(t, tc.expectedRepo.ID, repo.ID)
}
assert.Equal(t, tc.expectedUnitType, unitType)

})
}
}
3 changes: 1 addition & 2 deletions models/commit_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,11 @@ func FindRepoRecentCommitStatusContexts(repoID int64, before time.Duration) ([]s
return nil, err
}

var contexts = make([]string, 0, len(ids))
contexts := make([]string, 0, len(ids))
if len(ids) == 0 {
return contexts, nil
}
return contexts, x.Select("context").Table("commit_status").In("id", ids).Find(&contexts)

}

// NewCommitStatusOptions holds options for creating a CommitStatus
Expand Down
9 changes: 3 additions & 6 deletions models/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ func (err ErrNameCharsNotAllowed) Error() string {
}

// ErrSSHDisabled represents an "SSH disabled" error.
type ErrSSHDisabled struct {
}
type ErrSSHDisabled struct{}

// IsErrSSHDisabled checks if an error is a ErrSSHDisabled.
func IsErrSSHDisabled(err error) bool {
Expand Down Expand Up @@ -269,8 +268,7 @@ func (err ErrUserHasOrgs) Error() string {
}

// ErrUserNotAllowedCreateOrg represents a "UserNotAllowedCreateOrg" kind of error.
type ErrUserNotAllowedCreateOrg struct {
}
type ErrUserNotAllowedCreateOrg struct{}

// IsErrUserNotAllowedCreateOrg checks if an error is an ErrUserNotAllowedCreateOrg.
func IsErrUserNotAllowedCreateOrg(err error) bool {
Expand Down Expand Up @@ -603,8 +601,7 @@ func (err ErrAccessTokenNotExist) Error() string {
}

// ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
type ErrAccessTokenEmpty struct {
}
type ErrAccessTokenEmpty struct{}

// IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty.
func IsErrAccessTokenEmpty(err error) bool {
Expand Down
5 changes: 2 additions & 3 deletions models/external_login_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func ListAccountLinks(user *User) ([]*ExternalLoginUser, error) {
err := x.Where("user_id=?", user.ID).
Desc("login_source_id").
Find(&externalAccounts)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -87,7 +86,7 @@ func removeAllAccountLinks(e Engine, user *User) error {
}

// GetUserIDByExternalUserID get user id according to provider and userID
func GetUserIDByExternalUserID(provider string, userID string) (int64, error) {
func GetUserIDByExternalUserID(provider, userID string) (int64, error) {
var id int64
_, err := x.Table("external_login_user").
Select("user_id").
Expand Down Expand Up @@ -147,7 +146,7 @@ type FindExternalUserOptions struct {
}

func (opts FindExternalUserOptions) toConds() builder.Cond {
var cond = builder.NewCond()
cond := builder.NewCond()
if len(opts.Provider) > 0 {
cond = cond.And(builder.Eq{"provider": opts.Provider})
}
Expand Down
1 change: 0 additions & 1 deletion models/fixture_generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
// GetYamlFixturesAccess returns a string containing the contents
// for the access table, as recalculated using repo.RecalculateAccesses()
func GetYamlFixturesAccess() (string, error) {

repos := make([]*Repository, 0, 50)
if err := x.Find(&repos); err != nil {
return "", err
Expand Down
Loading

0 comments on commit 167b0f4

Please sign in to comment.