diff options
author | Bo-Yi Wu <appleboy.tw@gmail.com> | 2021-03-15 02:52:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-14 19:52:12 +0100 |
commit | 167b0f46ef946fad3ca13976c3b87598f505e2ea (patch) | |
tree | 8b6a4a47a2a0149899b3eb49b296677c2dba4d36 /models/migrations | |
parent | 164e35ead3c1b9b82d4a23644f6fe96652a747eb (diff) | |
download | gitea-167b0f46ef946fad3ca13976c3b87598f505e2ea.tar.gz gitea-167b0f46ef946fad3ca13976c3b87598f505e2ea.zip |
chore(models): rewrite code format. (#14754)
* 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.
Diffstat (limited to 'models/migrations')
30 files changed, 29 insertions, 43 deletions
diff --git a/models/migrations/v100.go b/models/migrations/v100.go index 6a4e98af1f..0ff59e0044 100644 --- a/models/migrations/v100.go +++ b/models/migrations/v100.go @@ -26,7 +26,7 @@ func updateMigrationServiceTypes(x *xorm.Engine) error { var last int const batchSize = 50 for { - var results = make([]Repository, 0, batchSize) + results := make([]Repository, 0, batchSize) err := x.Where("original_url <> '' AND original_url IS NOT NULL"). And("original_service_type = 0 OR original_service_type IS NULL"). OrderBy("id"). @@ -48,7 +48,7 @@ func updateMigrationServiceTypes(x *xorm.Engine) error { if err != nil { return err } - var serviceType = PlainGitService + serviceType := PlainGitService if strings.EqualFold(u.Host, "github.com") { serviceType = GithubService } diff --git a/models/migrations/v104.go b/models/migrations/v104.go index f3ec3c88c8..72e2364040 100644 --- a/models/migrations/v104.go +++ b/models/migrations/v104.go @@ -9,7 +9,6 @@ import ( ) func removeLabelUneededCols(x *xorm.Engine) error { - // Make sure the columns exist before dropping them type Label struct { QueryString string diff --git a/models/migrations/v105.go b/models/migrations/v105.go index 6c9a5817af..5d9a98cce5 100644 --- a/models/migrations/v105.go +++ b/models/migrations/v105.go @@ -9,7 +9,6 @@ import ( ) func addTeamIncludesAllRepositories(x *xorm.Engine) error { - type Team struct { ID int64 `xorm:"pk autoincr"` IncludesAllRepositories bool `xorm:"NOT NULL DEFAULT false"` diff --git a/models/migrations/v107.go b/models/migrations/v107.go index 3d6aeebaf0..22990a0fa6 100644 --- a/models/migrations/v107.go +++ b/models/migrations/v107.go @@ -9,7 +9,6 @@ import ( ) func addTemplateToRepo(x *xorm.Engine) error { - type Repository struct { IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"` TemplateID int64 `xorm:"INDEX"` diff --git a/models/migrations/v111.go b/models/migrations/v111.go index 93831de94a..b292f0c7d3 100644 --- a/models/migrations/v111.go +++ b/models/migrations/v111.go @@ -380,7 +380,7 @@ func addBranchProtectionCanPushAndEnableWhitelist(x *xorm.Engine) error { } totalPages := totalIssues / pageSize - var executeBody = func(page, pageSize int64) error { + executeBody := func(page, pageSize int64) error { // Find latest review of each user in each pull request, and set official field if appropriate reviews := []*Review{} diff --git a/models/migrations/v114.go b/models/migrations/v114.go index 25a187f6e8..4dd07c9e59 100644 --- a/models/migrations/v114.go +++ b/models/migrations/v114.go @@ -11,7 +11,6 @@ import ( ) func sanitizeOriginalURL(x *xorm.Engine) error { - type Repository struct { ID int64 OriginalURL string `xorm:"VARCHAR(2048)"` @@ -20,7 +19,7 @@ func sanitizeOriginalURL(x *xorm.Engine) error { var last int const batchSize = 50 for { - var results = make([]Repository, 0, batchSize) + results := make([]Repository, 0, batchSize) err := x.Where("original_url <> '' AND original_url IS NOT NULL"). And("original_service_type = 0 OR original_service_type IS NULL"). OrderBy("id"). diff --git a/models/migrations/v115.go b/models/migrations/v115.go index fcec1f5495..8222a8ceea 100644 --- a/models/migrations/v115.go +++ b/models/migrations/v115.go @@ -151,7 +151,7 @@ func copyOldAvatarToNewLocation(userID int64, oldAvatar string) (string, error) return newAvatar, nil } - if err := ioutil.WriteFile(filepath.Join(setting.Avatar.Path, newAvatar), data, 0666); err != nil { + if err := ioutil.WriteFile(filepath.Join(setting.Avatar.Path, newAvatar), data, 0o666); err != nil { return "", fmt.Errorf("ioutil.WriteFile: %v", err) } diff --git a/models/migrations/v116.go b/models/migrations/v116.go index 254d4e7a19..c684c05fdd 100644 --- a/models/migrations/v116.go +++ b/models/migrations/v116.go @@ -9,7 +9,6 @@ import ( ) func extendTrackedTimes(x *xorm.Engine) error { - type TrackedTime struct { Time int64 `xorm:"NOT NULL"` Deleted bool `xorm:"NOT NULL DEFAULT false"` diff --git a/models/migrations/v122.go b/models/migrations/v122.go index e28adc1d82..7f4a49e69c 100644 --- a/models/migrations/v122.go +++ b/models/migrations/v122.go @@ -9,7 +9,6 @@ import ( ) func addRequireSignedCommits(x *xorm.Engine) error { - type ProtectedBranch struct { RequireSignedCommits bool `xorm:"NOT NULL DEFAULT false"` } diff --git a/models/migrations/v124.go b/models/migrations/v124.go index e1a9000659..0b61a04cbc 100644 --- a/models/migrations/v124.go +++ b/models/migrations/v124.go @@ -9,7 +9,6 @@ import ( ) func addUserRepoMissingColumns(x *xorm.Engine) error { - type VisibleType int type User struct { PasswdHashAlgo string `xorm:"NOT NULL DEFAULT 'pbkdf2'"` diff --git a/models/migrations/v128.go b/models/migrations/v128.go index 9f698e3e57..7467023380 100644 --- a/models/migrations/v128.go +++ b/models/migrations/v128.go @@ -40,7 +40,7 @@ func fixMergeBase(x *xorm.Engine) error { MergedCommitID string `xorm:"VARCHAR(40)"` } - var limit = setting.Database.IterateBufferSize + limit := setting.Database.IterateBufferSize if limit <= 0 { limit = 50 } diff --git a/models/migrations/v129.go b/models/migrations/v129.go index 26f8ed3432..e935f2e07c 100644 --- a/models/migrations/v129.go +++ b/models/migrations/v129.go @@ -9,7 +9,6 @@ import ( ) func purgeUnusedDependencies(x *xorm.Engine) error { - if _, err := x.Exec("DELETE FROM issue_dependency WHERE issue_id NOT IN (SELECT id FROM issue)"); err != nil { return err } diff --git a/models/migrations/v130.go b/models/migrations/v130.go index 4f044e26ab..08a8d5fca1 100644 --- a/models/migrations/v130.go +++ b/models/migrations/v130.go @@ -12,7 +12,6 @@ import ( ) func expandWebhooks(x *xorm.Engine) error { - type HookEvents struct { Create bool `json:"create"` Delete bool `json:"delete"` @@ -57,7 +56,7 @@ func expandWebhooks(x *xorm.Engine) error { if err := sess.Begin(); err != nil { return err } - var results = make([]Webhook, 0, batchSize) + results := make([]Webhook, 0, batchSize) err := x.OrderBy("id"). Limit(batchSize, last). Find(&results) diff --git a/models/migrations/v134.go b/models/migrations/v134.go index 3ad94e7368..df08cb39cc 100644 --- a/models/migrations/v134.go +++ b/models/migrations/v134.go @@ -40,7 +40,7 @@ func refixMergeBase(x *xorm.Engine) error { MergedCommitID string `xorm:"VARCHAR(40)"` } - var limit = setting.Database.IterateBufferSize + limit := setting.Database.IterateBufferSize if limit <= 0 { limit = 50 } diff --git a/models/migrations/v136.go b/models/migrations/v136.go index 2203f15386..101cf75955 100644 --- a/models/migrations/v136.go +++ b/models/migrations/v136.go @@ -65,7 +65,7 @@ func addCommitDivergenceToPulls(x *xorm.Engine) error { if err := sess.Begin(); err != nil { return err } - var results = make([]*PullRequest, 0, batchSize) + results := make([]*PullRequest, 0, batchSize) err := sess.Where("has_merged = ?", false).OrderBy("id").Limit(batchSize, last).Find(&results) if err != nil { return err diff --git a/models/migrations/v144.go b/models/migrations/v144.go index beb089dde6..311bb93e3b 100644 --- a/models/migrations/v144.go +++ b/models/migrations/v144.go @@ -11,7 +11,7 @@ import ( ) func updateMatrixWebhookHTTPMethod(x *xorm.Engine) error { - var matrixHookTaskType = 9 // value comes from the models package + matrixHookTaskType := 9 // value comes from the models package type Webhook struct { HTTPMethod string } diff --git a/models/migrations/v146.go b/models/migrations/v146.go index 847bcf567c..0925898200 100644 --- a/models/migrations/v146.go +++ b/models/migrations/v146.go @@ -11,7 +11,6 @@ import ( ) func addProjectsInfo(x *xorm.Engine) error { - // Create new tables type ( ProjectType uint8 diff --git a/models/migrations/v147.go b/models/migrations/v147.go index a39b224039..7488b370aa 100644 --- a/models/migrations/v147.go +++ b/models/migrations/v147.go @@ -83,7 +83,7 @@ func createReviewsForCodeComments(x *xorm.Engine) error { return err } - var updateComment = func(comments []*Comment) error { + updateComment := func(comments []*Comment) error { sess := x.NewSession() defer sess.Close() if err := sess.Begin(); err != nil { @@ -131,10 +131,10 @@ func createReviewsForCodeComments(x *xorm.Engine) error { return sess.Commit() } - var start = 0 - var batchSize = 100 + start := 0 + batchSize := 100 for { - var comments = make([]*Comment, 0, batchSize) + comments := make([]*Comment, 0, batchSize) if err := x.Where("review_id = 0 and type = 21").Limit(batchSize, start).Find(&comments); err != nil { return err } diff --git a/models/migrations/v156.go b/models/migrations/v156.go index 976d1a2d1b..071735f704 100644 --- a/models/migrations/v156.go +++ b/models/migrations/v156.go @@ -26,7 +26,6 @@ func userPath(userName string) string { } func fixPublisherIDforTagReleases(x *xorm.Engine) error { - type Release struct { ID int64 RepoID int64 diff --git a/models/migrations/v157.go b/models/migrations/v157.go index 9689281c89..e6738fd4df 100644 --- a/models/migrations/v157.go +++ b/models/migrations/v157.go @@ -9,7 +9,6 @@ import ( ) func fixRepoTopics(x *xorm.Engine) error { - type Topic struct { ID int64 `xorm:"pk autoincr"` Name string `xorm:"UNIQUE VARCHAR(25)"` diff --git a/models/migrations/v158.go b/models/migrations/v158.go index a6f2178f87..472516d70e 100644 --- a/models/migrations/v158.go +++ b/models/migrations/v158.go @@ -51,10 +51,12 @@ func updateCodeCommentReplies(x *xorm.Engine) error { AND comment.id != first.id AND comment.commit_sha != first.commit_sha` - var sqlCmd string - var start = 0 - var batchSize = 100 - sess := x.NewSession() + var ( + sqlCmd string + start = 0 + batchSize = 100 + sess = x.NewSession() + ) defer sess.Close() for { if err := sess.Begin(); err != nil { @@ -68,7 +70,7 @@ func updateCodeCommentReplies(x *xorm.Engine) error { } } - var comments = make([]*Comment, 0, batchSize) + comments := make([]*Comment, 0, batchSize) switch { case setting.Database.UseMySQL: diff --git a/models/migrations/v161.go b/models/migrations/v161.go index 3eff7df8a3..4ca9f01218 100644 --- a/models/migrations/v161.go +++ b/models/migrations/v161.go @@ -21,7 +21,7 @@ func convertTaskTypeToString(x *xorm.Engine) error { MATRIX ) - var hookTaskTypes = map[int]string{ + hookTaskTypes := map[int]string{ GITEA: "gitea", GOGS: "gogs", SLACK: "slack", diff --git a/models/migrations/v162.go b/models/migrations/v162.go index b65eb4cd94..9dd175cd38 100644 --- a/models/migrations/v162.go +++ b/models/migrations/v162.go @@ -21,7 +21,7 @@ func convertWebhookTaskTypeToString(x *xorm.Engine) error { MATRIX ) - var hookTaskTypes = map[int]string{ + hookTaskTypes := map[int]string{ GITEA: "gitea", GOGS: "gogs", SLACK: "slack", diff --git a/models/migrations/v70.go b/models/migrations/v70.go index ea7ead60d8..7d34c89d11 100644 --- a/models/migrations/v70.go +++ b/models/migrations/v70.go @@ -14,7 +14,6 @@ import ( ) func addIssueDependencies(x *xorm.Engine) (err error) { - type IssueDependency struct { ID int64 `xorm:"pk autoincr"` UserID int64 `xorm:"NOT NULL"` @@ -90,7 +89,7 @@ func addIssueDependencies(x *xorm.Engine) (err error) { Created time.Time `xorm:"-"` } - //Updating existing issue units + // Updating existing issue units units := make([]*RepoUnit, 0, 100) err = x.Where("`type` = ?", v16UnitTypeIssues).Find(&units) if err != nil { diff --git a/models/migrations/v71.go b/models/migrations/v71.go index 0b6aff61b2..3012dd94f5 100644 --- a/models/migrations/v71.go +++ b/models/migrations/v71.go @@ -79,7 +79,6 @@ func addScratchHash(x *xorm.Engine) error { return err } return sess.Commit() - } func hashToken(token, salt string) string { diff --git a/models/migrations/v76.go b/models/migrations/v76.go index 6bfe0c2d98..a82ae40ba7 100644 --- a/models/migrations/v76.go +++ b/models/migrations/v76.go @@ -40,7 +40,7 @@ func addPullRequestRebaseWithMerge(x *xorm.Engine) error { return err } - //Updating existing issue units + // Updating existing issue units units := make([]*RepoUnit, 0, 100) if err := sess.Where("`type` = ?", v16UnitTypePRs).Find(&units); err != nil { return fmt.Errorf("Query repo units: %v", err) diff --git a/models/migrations/v79.go b/models/migrations/v79.go index 3c3e77b8db..818bfa4a0d 100644 --- a/models/migrations/v79.go +++ b/models/migrations/v79.go @@ -11,7 +11,6 @@ import ( ) func addCanCloseIssuesViaCommitInAnyBranch(x *xorm.Engine) error { - type Repository struct { ID int64 `xorm:"pk autoincr"` CloseIssuesViaCommitInAnyBranch bool `xorm:"NOT NULL DEFAULT false"` diff --git a/models/migrations/v88.go b/models/migrations/v88.go index 7318995a8c..11cc26209a 100644 --- a/models/migrations/v88.go +++ b/models/migrations/v88.go @@ -29,9 +29,9 @@ func addCommitStatusContext(x *xorm.Engine) error { sess := x.NewSession() defer sess.Close() - var start = 0 + start := 0 for { - var statuses = make([]*CommitStatus, 0, 100) + statuses := make([]*CommitStatus, 0, 100) err := sess.OrderBy("id").Limit(100, start).Find(&statuses) if err != nil { return err diff --git a/models/migrations/v92.go b/models/migrations/v92.go index 7ad5118176..e343dedb68 100644 --- a/models/migrations/v92.go +++ b/models/migrations/v92.go @@ -10,7 +10,6 @@ import ( ) func removeLingeringIndexStatus(x *xorm.Engine) error { - _, err := x.Exec(builder.Delete(builder.NotIn("`repo_id`", builder.Select("`id`").From("`repository`"))).From("`repo_indexer_status`")) return err } diff --git a/models/migrations/v96.go b/models/migrations/v96.go index f471ac384d..eaeab72b01 100644 --- a/models/migrations/v96.go +++ b/models/migrations/v96.go @@ -25,7 +25,7 @@ func deleteOrphanedAttachments(x *xorm.Engine) error { sess := x.NewSession() defer sess.Close() - var limit = setting.Database.IterateBufferSize + limit := setting.Database.IterateBufferSize if limit <= 0 { limit = 50 } @@ -42,7 +42,7 @@ func deleteOrphanedAttachments(x *xorm.Engine) error { return nil } - var ids = make([]int64, 0, limit) + ids := make([]int64, 0, limit) for _, attachment := range attachements { ids = append(ids, attachment.ID) } |