diff options
Diffstat (limited to 'services/migrations')
-rw-r--r-- | services/migrations/codebase.go | 12 | ||||
-rw-r--r-- | services/migrations/dump.go | 12 | ||||
-rw-r--r-- | services/migrations/error.go | 6 | ||||
-rw-r--r-- | services/migrations/git.go | 4 | ||||
-rw-r--r-- | services/migrations/gitbucket.go | 3 | ||||
-rw-r--r-- | services/migrations/gitea_downloader.go | 21 | ||||
-rw-r--r-- | services/migrations/gitea_uploader.go | 42 | ||||
-rw-r--r-- | services/migrations/github.go | 44 | ||||
-rw-r--r-- | services/migrations/gitlab.go | 45 | ||||
-rw-r--r-- | services/migrations/gogs.go | 21 | ||||
-rw-r--r-- | services/migrations/migrate.go | 12 | ||||
-rw-r--r-- | services/migrations/onedev.go | 9 | ||||
-rw-r--r-- | services/migrations/restore.go | 18 |
13 files changed, 118 insertions, 131 deletions
diff --git a/services/migrations/codebase.go b/services/migrations/codebase.go index 395bc6152e..13e9327c33 100644 --- a/services/migrations/codebase.go +++ b/services/migrations/codebase.go @@ -30,8 +30,7 @@ func init() { } // CodebaseDownloaderFactory defines a downloader factory -type CodebaseDownloaderFactory struct { -} +type CodebaseDownloaderFactory struct{} // New returns a downloader related to this factory according MigrateOptions func (f *CodebaseDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) { @@ -88,7 +87,7 @@ func (d *CodebaseDownloader) SetContext(ctx context.Context) { func NewCodebaseDownloader(ctx context.Context, projectURL *url.URL, project, repoName, username, password string) *CodebaseDownloader { baseURL, _ := url.Parse("https://api3.codebasehq.com") - var downloader = &CodebaseDownloader{ + downloader := &CodebaseDownloader{ ctx: ctx, baseURL: baseURL, projectURL: projectURL, @@ -206,7 +205,7 @@ func (d *CodebaseDownloader) GetMilestones() ([]*base.Milestone, error) { return nil, err } - var milestones = make([]*base.Milestone, 0, len(rawMilestones.TicketingMilestone)) + milestones := make([]*base.Milestone, 0, len(rawMilestones.TicketingMilestone)) for _, milestone := range rawMilestones.TicketingMilestone { var deadline *time.Time if len(milestone.Deadline.Value) > 0 { @@ -256,7 +255,7 @@ func (d *CodebaseDownloader) GetLabels() ([]*base.Label, error) { return nil, err } - var labels = make([]*base.Label, 0, len(rawTypes.TicketingType)) + labels := make([]*base.Label, 0, len(rawTypes.TicketingType)) for _, label := range rawTypes.TicketingType { labels = append(labels, &base.Label{ Name: label.Name, @@ -400,7 +399,8 @@ func (d *CodebaseDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, Created: issue.CreatedAt.Value, Updated: issue.UpdatedAt.Value, Labels: []*base.Label{ - {Name: issue.Type.Name}}, + {Name: issue.Type.Name}, + }, Context: codebaseIssueContext{ foreignID: issue.TicketID.Value, localID: issue.TicketID.Value, diff --git a/services/migrations/dump.go b/services/migrations/dump.go index f4e797b357..01a946673e 100644 --- a/services/migrations/dump.go +++ b/services/migrations/dump.go @@ -27,9 +27,7 @@ import ( "gopkg.in/yaml.v2" ) -var ( - _ base.Uploader = &RepositoryDumper{} -) +var _ base.Uploader = &RepositoryDumper{} // RepositoryDumper implements an Uploader to the local directory type RepositoryDumper struct { @@ -403,7 +401,7 @@ func (g *RepositoryDumper) createItems(dir string, itemFiles map[int64]*os.File, // CreateComments creates comments of issues func (g *RepositoryDumper) CreateComments(comments ...*base.Comment) error { - var commentsMap = make(map[int64][]interface{}, len(comments)) + commentsMap := make(map[int64][]interface{}, len(comments)) for _, comment := range comments { commentsMap[comment.IssueIndex] = append(commentsMap[comment.IssueIndex], comment) } @@ -532,7 +530,7 @@ func (g *RepositoryDumper) CreatePullRequests(prs ...*base.PullRequest) error { // CreateReviews create pull request reviews func (g *RepositoryDumper) CreateReviews(reviews ...*base.Review) error { - var reviewsMap = make(map[int64][]interface{}, len(reviews)) + reviewsMap := make(map[int64][]interface{}, len(reviews)) for _, review := range reviews { reviewsMap[review.IssueIndex] = append(reviewsMap[review.IssueIndex], review) } @@ -611,7 +609,7 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string, if err != nil { return err } - var uploader = NewGiteaLocalUploader(ctx, doer, ownerName, repoName) + uploader := NewGiteaLocalUploader(ctx, doer, ownerName, repoName) downloader, err := NewRepositoryRestorer(ctx, baseDir, ownerName, repoName) if err != nil { return err @@ -622,7 +620,7 @@ func RestoreRepository(ctx context.Context, baseDir, ownerName, repoName string, } tp, _ := strconv.Atoi(opts["service_type"]) - var migrateOpts = base.MigrateOptions{ + migrateOpts := base.MigrateOptions{ GitServiceType: structs.GitServiceType(tp), } updateOptionsUnits(&migrateOpts, units) diff --git a/services/migrations/error.go b/services/migrations/error.go index b90d1b6577..3b3f975012 100644 --- a/services/migrations/error.go +++ b/services/migrations/error.go @@ -11,10 +11,8 @@ import ( "github.com/google/go-github/v39/github" ) -var ( - // ErrRepoNotCreated returns the error that repository not created - ErrRepoNotCreated = errors.New("repository is not created yet") -) +// ErrRepoNotCreated returns the error that repository not created +var ErrRepoNotCreated = errors.New("repository is not created yet") // IsRateLimitError returns true if the err is github.RateLimitError func IsRateLimitError(err error) bool { diff --git a/services/migrations/git.go b/services/migrations/git.go index 37ffb674c5..3198f934ca 100644 --- a/services/migrations/git.go +++ b/services/migrations/git.go @@ -10,9 +10,7 @@ import ( base "code.gitea.io/gitea/modules/migration" ) -var ( - _ base.Downloader = &PlainGitDownloader{} -) +var _ base.Downloader = &PlainGitDownloader{} // PlainGitDownloader implements a Downloader interface to clone git from a http/https URL type PlainGitDownloader struct { diff --git a/services/migrations/gitbucket.go b/services/migrations/gitbucket.go index 27ed584aa2..c4fb0df93a 100644 --- a/services/migrations/gitbucket.go +++ b/services/migrations/gitbucket.go @@ -23,8 +23,7 @@ func init() { } // GitBucketDownloaderFactory defines a GitBucket downloader factory -type GitBucketDownloaderFactory struct { -} +type GitBucketDownloaderFactory struct{} // New returns a Downloader related to this factory according MigrateOptions func (f *GitBucketDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) { diff --git a/services/migrations/gitea_downloader.go b/services/migrations/gitea_downloader.go index 258f030726..a712b65a22 100644 --- a/services/migrations/gitea_downloader.go +++ b/services/migrations/gitea_downloader.go @@ -32,8 +32,7 @@ func init() { } // GiteaDownloaderFactory defines a gitea downloader factory -type GiteaDownloaderFactory struct { -} +type GiteaDownloaderFactory struct{} // New returns a Downloader related to this factory according MigrateOptions func (f *GiteaDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) { @@ -159,7 +158,7 @@ func (g *GiteaDownloader) GetTopics() ([]string, error) { // GetMilestones returns milestones func (g *GiteaDownloader) GetMilestones() ([]*base.Milestone, error) { - var milestones = make([]*base.Milestone, 0, g.maxPerPage) + milestones := make([]*base.Milestone, 0, g.maxPerPage) for i := 1; ; i++ { // make sure gitea can shutdown gracefully @@ -224,7 +223,7 @@ func (g *GiteaDownloader) convertGiteaLabel(label *gitea_sdk.Label) *base.Label // GetLabels returns labels func (g *GiteaDownloader) GetLabels() ([]*base.Label, error) { - var labels = make([]*base.Label, 0, g.maxPerPage) + labels := make([]*base.Label, 0, g.maxPerPage) for i := 1; ; i++ { // make sure gitea can shutdown gracefully @@ -304,7 +303,7 @@ func (g *GiteaDownloader) convertGiteaRelease(rel *gitea_sdk.Release) *base.Rele // GetReleases returns releases func (g *GiteaDownloader) GetReleases() ([]*base.Release, error) { - var releases = make([]*base.Release, 0, g.maxPerPage) + releases := make([]*base.Release, 0, g.maxPerPage) for i := 1; ; i++ { // make sure gitea can shutdown gracefully @@ -379,7 +378,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err if perPage > g.maxPerPage { perPage = g.maxPerPage } - var allIssues = make([]*base.Issue, 0, perPage) + allIssues := make([]*base.Issue, 0, perPage) issues, _, err := g.client.ListRepoIssues(g.repoOwner, g.repoName, gitea_sdk.ListIssueOption{ ListOptions: gitea_sdk.ListOptions{Page: page, PageSize: perPage}, @@ -391,7 +390,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err } for _, issue := range issues { - var labels = make([]*base.Label, 0, len(issue.Labels)) + labels := make([]*base.Label, 0, len(issue.Labels)) for i := range issue.Labels { labels = append(labels, g.convertGiteaLabel(issue.Labels[i])) } @@ -444,7 +443,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err // GetComments returns comments according issueNumber func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) { - var allComments = make([]*base.Comment, 0, g.maxPerPage) + allComments := make([]*base.Comment, 0, g.maxPerPage) for i := 1; ; i++ { // make sure gitea can shutdown gracefully @@ -496,7 +495,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques if perPage > g.maxPerPage { perPage = g.maxPerPage } - var allPRs = make([]*base.PullRequest, 0, perPage) + allPRs := make([]*base.PullRequest, 0, perPage) prs, _, err := g.client.ListRepoPullRequests(g.repoOwner, g.repoName, gitea_sdk.ListPullRequestsOptions{ ListOptions: gitea_sdk.ListOptions{ @@ -514,7 +513,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques milestone = pr.Milestone.Title } - var labels = make([]*base.Label, 0, len(pr.Labels)) + labels := make([]*base.Label, 0, len(pr.Labels)) for i := range pr.Labels { labels = append(labels, g.convertGiteaLabel(pr.Labels[i])) } @@ -620,7 +619,7 @@ func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review, return nil, nil } - var allReviews = make([]*base.Review, 0, g.maxPerPage) + allReviews := make([]*base.Review, 0, g.maxPerPage) for i := 1; ; i++ { // make sure gitea can shutdown gracefully diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index e939046e90..6e823031ed 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -33,9 +33,7 @@ import ( gouuid "github.com/google/uuid" ) -var ( - _ base.Uploader = &GiteaLocalUploader{} -) +var _ base.Uploader = &GiteaLocalUploader{} // GiteaLocalUploader implements an Uploader to gitea sites type GiteaLocalUploader struct { @@ -159,7 +157,7 @@ func (g *GiteaLocalUploader) CreateTopics(topics ...string) error { // CreateMilestones creates milestones func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) error { - var mss = make([]*models.Milestone, 0, len(milestones)) + mss := make([]*models.Milestone, 0, len(milestones)) for _, milestone := range milestones { var deadline timeutil.TimeStamp if milestone.Deadline != nil { @@ -182,7 +180,7 @@ func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) err milestone.Updated = &milestone.Created } - var ms = models.Milestone{ + ms := models.Milestone{ RepoID: g.repo.ID, Name: milestone.Title, Content: milestone.Description, @@ -210,7 +208,7 @@ func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) err // CreateLabels creates labels func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error { - var lbs = make([]*models.Label, 0, len(labels)) + lbs := make([]*models.Label, 0, len(labels)) for _, label := range labels { lbs = append(lbs, &models.Label{ RepoID: g.repo.ID, @@ -232,7 +230,7 @@ func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error { // CreateReleases creates releases func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { - var rels = make([]*models.Release, 0, len(releases)) + rels := make([]*models.Release, 0, len(releases)) for _, release := range releases { if release.Created.IsZero() { if !release.Published.IsZero() { @@ -242,7 +240,7 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { } } - var rel = models.Release{ + rel := models.Release{ RepoID: g.repo.ID, TagName: release.TagName, LowerTagName: strings.ToLower(release.TagName), @@ -297,7 +295,7 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { asset.Created = release.Created } } - var attach = repo_model.Attachment{ + attach := repo_model.Attachment{ UUID: gouuid.New().String(), Name: asset.Name, DownloadCount: int64(*asset.DownloadCount), @@ -348,7 +346,7 @@ func (g *GiteaLocalUploader) SyncTags() error { // CreateIssues creates issues func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error { - var iss = make([]*models.Issue, 0, len(issues)) + iss := make([]*models.Issue, 0, len(issues)) for _, issue := range issues { var labels []*models.Label for _, label := range issue.Labels { @@ -381,7 +379,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error { } } - var is = models.Issue{ + is := models.Issue{ RepoID: g.repo.ID, Repo: g.repo, Index: issue.Number, @@ -433,7 +431,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error { g.userMap[reaction.UserID] = userid } } - var res = models.Reaction{ + res := models.Reaction{ Type: reaction.Content, CreatedUnix: timeutil.TimeStampNow(), } @@ -464,7 +462,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error { // CreateComments creates comments of issues func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { - var cms = make([]*models.Comment, 0, len(comments)) + cms := make([]*models.Comment, 0, len(comments)) for _, comment := range comments { var issue *models.Issue issueInter, ok := g.issues.Load(comment.IssueIndex) @@ -528,7 +526,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { g.userMap[reaction.UserID] = userid } } - var res = models.Reaction{ + res := models.Reaction{ Type: reaction.Content, CreatedUnix: timeutil.TimeStampNow(), } @@ -553,7 +551,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { // CreatePullRequests creates pull requests func (g *GiteaLocalUploader) CreatePullRequests(prs ...*base.PullRequest) error { - var gprs = make([]*models.PullRequest, 0, len(prs)) + gprs := make([]*models.PullRequest, 0, len(prs)) for _, pr := range prs { gpr, err := g.newPullRequest(pr) if err != nil { @@ -652,7 +650,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR return nil, err } - var head = "unknown repository" + head := "unknown repository" if pr.IsForkPullRequest() && pr.State != "closed" { if pr.Head.OwnerName != "" { remote := pr.Head.OwnerName @@ -723,7 +721,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR pr.Updated = pr.Created } - var issue = models.Issue{ + issue := models.Issue{ RepoID: g.repo.ID, Repo: g.repo, Title: pr.Title, @@ -773,7 +771,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR g.userMap[reaction.UserID] = userid } } - var res = models.Reaction{ + res := models.Reaction{ Type: reaction.Content, CreatedUnix: timeutil.TimeStampNow(), } @@ -787,7 +785,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR issue.Reactions = append(issue.Reactions, &res) } - var pullRequest = models.PullRequest{ + pullRequest := models.PullRequest{ HeadRepoID: g.repo.ID, HeadBranch: head, BaseRepoID: g.repo.ID, @@ -830,7 +828,7 @@ func convertReviewState(state string) models.ReviewType { // CreateReviews create pull request reviews func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error { - var cms = make([]*models.Review, 0, len(reviews)) + cms := make([]*models.Review, 0, len(reviews)) for _, review := range reviews { var issue *models.Issue issueInter, ok := g.issues.Load(review.IssueIndex) @@ -862,7 +860,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error { review.CreatedAt = time.Unix(int64(issue.CreatedUnix), 0) } - var cm = models.Review{ + cm := models.Review{ Type: convertReviewState(review.State), IssueID: issue.ID, Content: review.Content, @@ -926,7 +924,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error { comment.UpdatedAt = comment.CreatedAt } - var c = models.Comment{ + c := models.Comment{ Type: models.CommentTypeCode, PosterID: comment.PosterID, IssueID: issue.ID, diff --git a/services/migrations/github.go b/services/migrations/github.go index b360b05061..a946177c90 100644 --- a/services/migrations/github.go +++ b/services/migrations/github.go @@ -37,8 +37,7 @@ func init() { } // GithubDownloaderV3Factory defines a github downloader v3 factory -type GithubDownloaderV3Factory struct { -} +type GithubDownloaderV3Factory struct{} // New returns a Downloader related to this factory according MigrateOptions func (f *GithubDownloaderV3Factory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) { @@ -80,7 +79,7 @@ type GithubDownloaderV3 struct { // NewGithubDownloaderV3 creates a github Downloader via github v3 API func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GithubDownloaderV3 { - var downloader = GithubDownloaderV3{ + downloader := GithubDownloaderV3{ userName: userName, password: password, ctx: ctx, @@ -96,7 +95,7 @@ func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, tok ts := oauth2.StaticTokenSource( &oauth2.Token{AccessToken: token}, ) - var client = &http.Client{ + client := &http.Client{ Transport: &oauth2.Transport{ Base: NewMigrationHTTPTransport(), Source: oauth2.ReuseTokenSource(nil, ts), @@ -106,12 +105,12 @@ func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, tok downloader.addClient(client, baseURL) } } else { - var transport = NewMigrationHTTPTransport() + transport := NewMigrationHTTPTransport() transport.Proxy = func(req *http.Request) (*url.URL, error) { req.SetBasicAuth(userName, password) return proxy.Proxy()(req) } - var client = &http.Client{ + client := &http.Client{ Transport: transport, } downloader.addClient(client, baseURL) @@ -218,8 +217,8 @@ func (g *GithubDownloaderV3) GetTopics() ([]string, error) { // GetMilestones returns milestones func (g *GithubDownloaderV3) GetMilestones() ([]*base.Milestone, error) { - var perPage = g.maxPerPage - var milestones = make([]*base.Milestone, 0, perPage) + perPage := g.maxPerPage + milestones := make([]*base.Milestone, 0, perPage) for i := 1; ; i++ { g.waitAndPickClient() ms, resp, err := g.getClient().Issues.ListMilestones(g.ctx, g.repoOwner, g.repoName, @@ -228,14 +227,15 @@ func (g *GithubDownloaderV3) GetMilestones() ([]*base.Milestone, error) { ListOptions: github.ListOptions{ Page: i, PerPage: perPage, - }}) + }, + }) if err != nil { return nil, err } g.setRate(&resp.Rate) for _, m := range ms { - var state = "open" + state := "open" if m.State != nil { state = *m.State } @@ -266,8 +266,8 @@ func convertGithubLabel(label *github.Label) *base.Label { // GetLabels returns labels func (g *GithubDownloaderV3) GetLabels() ([]*base.Label, error) { - var perPage = g.maxPerPage - var labels = make([]*base.Label, 0, perPage) + perPage := g.maxPerPage + labels := make([]*base.Label, 0, perPage) for i := 1; ; i++ { g.waitAndPickClient() ls, resp, err := g.getClient().Issues.ListLabels(g.ctx, g.repoOwner, g.repoName, @@ -311,7 +311,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease) httpClient := NewMigrationHTTPClient() for _, asset := range rel.Assets { - var assetID = *asset.ID // Don't optimize this, for closure we need a local variable + assetID := *asset.ID // Don't optimize this, for closure we need a local variable r.Assets = append(r.Assets, &base.ReleaseAsset{ ID: asset.GetID(), Name: asset.GetName(), @@ -357,8 +357,8 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease) // GetReleases returns releases func (g *GithubDownloaderV3) GetReleases() ([]*base.Release, error) { - var perPage = g.maxPerPage - var releases = make([]*base.Release, 0, perPage) + perPage := g.maxPerPage + releases := make([]*base.Release, 0, perPage) for i := 1; ; i++ { g.waitAndPickClient() ls, resp, err := g.getClient().Repositories.ListReleases(g.ctx, g.repoOwner, g.repoName, @@ -396,7 +396,7 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool, }, } - var allIssues = make([]*base.Issue, 0, perPage) + allIssues := make([]*base.Issue, 0, perPage) g.waitAndPickClient() issues, resp, err := g.getClient().Issues.ListByRepo(g.ctx, g.repoOwner, g.repoName, opt) if err != nil { @@ -409,7 +409,7 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool, continue } - var labels = make([]*base.Label, 0, len(issue.Labels)) + labels := make([]*base.Label, 0, len(issue.Labels)) for _, l := range issue.Labels { labels = append(labels, convertGithubLabel(l)) } @@ -573,7 +573,7 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment, if err != nil { return nil, false, fmt.Errorf("error while listing repos: %v", err) } - var isEnd = resp.NextPage == 0 + isEnd := resp.NextPage == 0 log.Trace("Request get comments %d/%d, but in fact get %d, next page is %d", perPage, page, len(comments), resp.NextPage) g.setRate(&resp.Rate) @@ -634,7 +634,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq Page: page, }, } - var allPRs = make([]*base.PullRequest, 0, perPage) + allPRs := make([]*base.PullRequest, 0, perPage) g.waitAndPickClient() prs, resp, err := g.getClient().PullRequests.List(g.ctx, g.repoOwner, g.repoName, opt) if err != nil { @@ -643,7 +643,7 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq log.Trace("Request get pull requests %d/%d, but in fact get %d", perPage, page, len(prs)) g.setRate(&resp.Rate) for _, pr := range prs { - var labels = make([]*base.Label, 0, len(pr.Labels)) + labels := make([]*base.Label, 0, len(pr.Labels)) for _, l := range pr.Labels { labels = append(labels, convertGithubLabel(l)) } @@ -729,7 +729,7 @@ func convertGithubReview(r *github.PullRequestReview) *base.Review { } func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullRequestComment) ([]*base.ReviewComment, error) { - var rcs = make([]*base.ReviewComment, 0, len(cs)) + rcs := make([]*base.ReviewComment, 0, len(cs)) for _, c := range cs { // get reactions var reactions []*base.Reaction @@ -776,7 +776,7 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques // GetReviews returns pull requests review func (g *GithubDownloaderV3) GetReviews(context base.IssueContext) ([]*base.Review, error) { - var allReviews = make([]*base.Review, 0, g.maxPerPage) + allReviews := make([]*base.Review, 0, g.maxPerPage) opt := &github.ListOptions{ PerPage: g.maxPerPage, } diff --git a/services/migrations/gitlab.go b/services/migrations/gitlab.go index 4eb7e3e47c..a9856739c2 100644 --- a/services/migrations/gitlab.go +++ b/services/migrations/gitlab.go @@ -32,8 +32,7 @@ func init() { } // GitlabDownloaderFactory defines a gitlab downloader factory -type GitlabDownloaderFactory struct { -} +type GitlabDownloaderFactory struct{} // New returns a Downloader related to this factory according MigrateOptions func (f *GitlabDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) { @@ -184,16 +183,17 @@ func (g *GitlabDownloader) GetTopics() ([]string, error) { // GetMilestones returns milestones func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) { - var perPage = g.maxPerPage - var state = "all" - var milestones = make([]*base.Milestone, 0, perPage) + perPage := g.maxPerPage + state := "all" + milestones := make([]*base.Milestone, 0, perPage) for i := 1; ; i++ { ms, _, err := g.client.Milestones.ListMilestones(g.repoID, &gitlab.ListMilestonesOptions{ State: &state, ListOptions: gitlab.ListOptions{ Page: i, PerPage: perPage, - }}, nil, gitlab.WithContext(g.ctx)) + }, + }, nil, gitlab.WithContext(g.ctx)) if err != nil { return nil, err } @@ -203,7 +203,7 @@ func (g *GitlabDownloader) GetMilestones() ([]*base.Milestone, error) { if m.Description != "" { desc = m.Description } - var state = "open" + state := "open" var closedAt *time.Time if m.State != "" { state = m.State @@ -255,8 +255,8 @@ func (g *GitlabDownloader) normalizeColor(val string) string { // GetLabels returns labels func (g *GitlabDownloader) GetLabels() ([]*base.Label, error) { - var perPage = g.maxPerPage - var labels = make([]*base.Label, 0, perPage) + perPage := g.maxPerPage + labels := make([]*base.Label, 0, perPage) for i := 1; ; i++ { ls, _, err := g.client.Labels.ListLabels(g.repoID, &gitlab.ListLabelsOptions{ListOptions: gitlab.ListOptions{ Page: i, @@ -327,8 +327,8 @@ func (g *GitlabDownloader) convertGitlabRelease(rel *gitlab.Release) *base.Relea // GetReleases returns releases func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) { - var perPage = g.maxPerPage - var releases = make([]*base.Release, 0, perPage) + perPage := g.maxPerPage + releases := make([]*base.Release, 0, perPage) for i := 1; ; i++ { ls, _, err := g.client.Releases.ListReleases(g.repoID, &gitlab.ListReleasesOptions{ Page: i, @@ -381,7 +381,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er }, } - var allIssues = make([]*base.Issue, 0, perPage) + allIssues := make([]*base.Issue, 0, perPage) issues, _, err := g.client.Issues.ListProjectIssues(g.repoID, opt, nil, gitlab.WithContext(g.ctx)) if err != nil { @@ -389,7 +389,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er } for _, issue := range issues { - var labels = make([]*base.Label, 0, len(issue.Labels)) + labels := make([]*base.Label, 0, len(issue.Labels)) for _, l := range issue.Labels { labels = append(labels, &base.Label{ Name: l, @@ -402,7 +402,7 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er } var reactions []*base.Reaction - var awardPage = 1 + awardPage := 1 for { awards, _, err := g.client.AwardEmoji.ListIssueAwardEmoji(g.repoID, issue.IID, &gitlab.ListAwardEmojiOptions{Page: awardPage, PerPage: perPage}, gitlab.WithContext(g.ctx)) if err != nil { @@ -456,9 +456,9 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com return nil, false, fmt.Errorf("unexpected context: %+v", opts.Context) } - var allComments = make([]*base.Comment, 0, g.maxPerPage) + allComments := make([]*base.Comment, 0, g.maxPerPage) - var page = 1 + page := 1 for { var comments []*gitlab.Discussion @@ -503,7 +503,6 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com Created: *c.CreatedAt, }) } - } if resp.NextPage == 0 { break @@ -526,7 +525,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque }, } - var allPRs = make([]*base.PullRequest, 0, perPage) + allPRs := make([]*base.PullRequest, 0, perPage) prs, _, err := g.client.MergeRequests.ListProjectMergeRequests(g.repoID, opt, nil, gitlab.WithContext(g.ctx)) if err != nil { @@ -534,7 +533,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque } for _, pr := range prs { - var labels = make([]*base.Label, 0, len(pr.Labels)) + labels := make([]*base.Label, 0, len(pr.Labels)) for _, l := range pr.Labels { labels = append(labels, &base.Label{ Name: l, @@ -547,12 +546,12 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque pr.State = "closed" } - var mergeTime = pr.MergedAt + mergeTime := pr.MergedAt if merged && pr.MergedAt == nil { mergeTime = pr.UpdatedAt } - var closeTime = pr.ClosedAt + closeTime := pr.ClosedAt if merged && pr.ClosedAt == nil { closeTime = pr.UpdatedAt } @@ -568,7 +567,7 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque } var reactions []*base.Reaction - var awardPage = 1 + awardPage := 1 for { awards, _, err := g.client.AwardEmoji.ListMergeRequestAwardEmoji(g.repoID, pr.IID, &gitlab.ListAwardEmojiOptions{Page: awardPage, PerPage: perPage}, gitlab.WithContext(g.ctx)) if err != nil { @@ -641,7 +640,7 @@ func (g *GitlabDownloader) GetReviews(context base.IssueContext) ([]*base.Review return nil, err } - var reviews = make([]*base.Review, 0, len(approvals.ApprovedBy)) + reviews := make([]*base.Review, 0, len(approvals.ApprovedBy)) for _, user := range approvals.ApprovedBy { reviews = append(reviews, &base.Review{ IssueIndex: context.LocalID(), diff --git a/services/migrations/gogs.go b/services/migrations/gogs.go index e103ef996e..9280427cd7 100644 --- a/services/migrations/gogs.go +++ b/services/migrations/gogs.go @@ -30,8 +30,7 @@ func init() { } // GogsDownloaderFactory defines a gogs downloader factory -type GogsDownloaderFactory struct { -} +type GogsDownloaderFactory struct{} // New returns a Downloader related to this factory according MigrateOptions func (f *GogsDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) { @@ -81,7 +80,7 @@ func (g *GogsDownloader) SetContext(ctx context.Context) { // NewGogsDownloader creates a gogs Downloader via gogs API func NewGogsDownloader(ctx context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GogsDownloader { - var downloader = GogsDownloader{ + downloader := GogsDownloader{ ctx: ctx, baseURL: baseURL, userName: userName, @@ -95,7 +94,7 @@ func NewGogsDownloader(ctx context.Context, baseURL, userName, password, token, client = gogs.NewClient(baseURL, token) downloader.userName = token } else { - var transport = NewMigrationHTTPTransport() + transport := NewMigrationHTTPTransport() transport.Proxy = func(req *http.Request) (*url.URL, error) { req.SetBasicAuth(userName, password) return proxy.Proxy()(req) @@ -139,8 +138,8 @@ func (g *GogsDownloader) GetRepoInfo() (*base.Repository, error) { // GetMilestones returns milestones func (g *GogsDownloader) GetMilestones() ([]*base.Milestone, error) { - var perPage = 100 - var milestones = make([]*base.Milestone, 0, perPage) + perPage := 100 + milestones := make([]*base.Milestone, 0, perPage) ms, err := g.client.ListRepoMilestones(g.repoOwner, g.repoName) if err != nil { @@ -162,8 +161,8 @@ func (g *GogsDownloader) GetMilestones() ([]*base.Milestone, error) { // GetLabels returns labels func (g *GogsDownloader) GetLabels() ([]*base.Label, error) { - var perPage = 100 - var labels = make([]*base.Label, 0, perPage) + perPage := 100 + labels := make([]*base.Label, 0, perPage) ls, err := g.client.ListRepoLabels(g.repoOwner, g.repoName) if err != nil { return nil, err @@ -203,7 +202,7 @@ func (g *GogsDownloader) GetIssues(page, _ int) ([]*base.Issue, bool, error) { } func (g *GogsDownloader) getIssues(page int, state string) ([]*base.Issue, bool, error) { - var allIssues = make([]*base.Issue, 0, 10) + allIssues := make([]*base.Issue, 0, 10) issues, err := g.client.ListRepoIssues(g.repoOwner, g.repoName, gogs.ListIssueOption{ Page: page, @@ -225,7 +224,7 @@ func (g *GogsDownloader) getIssues(page int, state string) ([]*base.Issue, bool, // GetComments returns comments according issueNumber func (g *GogsDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) { - var allComments = make([]*base.Comment, 0, 100) + allComments := make([]*base.Comment, 0, 100) comments, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID()) if err != nil { @@ -276,7 +275,7 @@ func convertGogsIssue(issue *gogs.Issue) *base.Issue { if issue.Milestone != nil { milestone = issue.Milestone.Title } - var labels = make([]*base.Label, 0, len(issue.Labels)) + labels := make([]*base.Label, 0, len(issue.Labels)) for _, l := range issue.Labels { labels = append(labels, convertGogsLabel(l)) } diff --git a/services/migrations/migrate.go b/services/migrations/migrate.go index 65ecceddbe..7bca128ac5 100644 --- a/services/migrations/migrate.go +++ b/services/migrations/migrate.go @@ -123,7 +123,7 @@ func MigrateRepository(ctx context.Context, doer *user_model.User, ownerName str return nil, err } - var uploader = NewGiteaLocalUploader(ctx, doer, ownerName, opts.RepoName) + uploader := NewGiteaLocalUploader(ctx, doer, ownerName, opts.RepoName) uploader.gitServiceType = opts.GitServiceType if err := migrateRepository(downloader, uploader, opts, messenger); err != nil { @@ -305,7 +305,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts if opts.Issues { log.Trace("migrating issues and comments") messenger("repo.migrate.migrating_issues") - var issueBatchSize = uploader.MaxBatchInsertSize("issue") + issueBatchSize := uploader.MaxBatchInsertSize("issue") for i := 1; ; i++ { issues, isEnd, err := downloader.GetIssues(i, issueBatchSize) @@ -322,7 +322,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts } if opts.Comments && !supportAllComments { - var allComments = make([]*base.Comment, 0, commentBatchSize) + allComments := make([]*base.Comment, 0, commentBatchSize) for _, issue := range issues { log.Trace("migrating issue %d's comments", issue.Number) comments, _, err := downloader.GetComments(base.GetCommentOptions{ @@ -362,7 +362,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts if opts.PullRequests { log.Trace("migrating pull requests and comments") messenger("repo.migrate.migrating_pulls") - var prBatchSize = uploader.MaxBatchInsertSize("pullrequest") + prBatchSize := uploader.MaxBatchInsertSize("pullrequest") for i := 1; ; i++ { prs, isEnd, err := downloader.GetPullRequests(i, prBatchSize) if err != nil { @@ -380,7 +380,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts if opts.Comments { if !supportAllComments { // plain comments - var allComments = make([]*base.Comment, 0, commentBatchSize) + allComments := make([]*base.Comment, 0, commentBatchSize) for _, pr := range prs { log.Trace("migrating pull request %d's comments", pr.Number) comments, _, err := downloader.GetComments(base.GetCommentOptions{ @@ -410,7 +410,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts } // migrate reviews - var allReviews = make([]*base.Review, 0, reviewBatchSize) + allReviews := make([]*base.Review, 0, reviewBatchSize) for _, pr := range prs { reviews, err := downloader.GetReviews(pr.Context) if err != nil { diff --git a/services/migrations/onedev.go b/services/migrations/onedev.go index bb676131f3..c8253e8947 100644 --- a/services/migrations/onedev.go +++ b/services/migrations/onedev.go @@ -29,8 +29,7 @@ func init() { } // OneDevDownloaderFactory defines a downloader factory -type OneDevDownloaderFactory struct { -} +type OneDevDownloaderFactory struct{} // New returns a downloader related to this factory according MigrateOptions func (f *OneDevDownloaderFactory) New(ctx context.Context, opts base.MigrateOptions) (base.Downloader, error) { @@ -90,7 +89,7 @@ func (d *OneDevDownloader) SetContext(ctx context.Context) { // NewOneDevDownloader creates a new downloader func NewOneDevDownloader(ctx context.Context, baseURL *url.URL, username, password, repoName string) *OneDevDownloader { - var downloader = &OneDevDownloader{ + downloader := &OneDevDownloader{ ctx: ctx, baseURL: baseURL, repoName: repoName, @@ -195,7 +194,7 @@ func (d *OneDevDownloader) GetMilestones() ([]*base.Milestone, error) { endpoint := fmt.Sprintf("/api/projects/%d/milestones", d.repoID) - var milestones = make([]*base.Milestone, 0, 100) + milestones := make([]*base.Milestone, 0, 100) offset := 0 for { err := d.callAPI( @@ -583,7 +582,7 @@ func (d *OneDevDownloader) GetReviews(context base.IssueContext) ([]*base.Review return nil, err } - var reviews = make([]*base.Review, 0, len(rawReviews)) + reviews := make([]*base.Review, 0, len(rawReviews)) for _, review := range rawReviews { state := base.ReviewStatePending content := "" diff --git a/services/migrations/restore.go b/services/migrations/restore.go index 357e995423..4499f78701 100644 --- a/services/migrations/restore.go +++ b/services/migrations/restore.go @@ -59,7 +59,7 @@ func (r *RepositoryRestorer) getRepoOptions() (map[string]string, error) { return nil, err } - var opts = make(map[string]string) + opts := make(map[string]string) err = yaml.Unmarshal(bs, &opts) if err != nil { return nil, err @@ -91,7 +91,7 @@ func (r *RepositoryRestorer) GetRepoInfo() (*base.Repository, error) { func (r *RepositoryRestorer) GetTopics() ([]string, error) { p := filepath.Join(r.baseDir, "topic.yml") - var topics = struct { + topics := struct { Topics []string `yaml:"topics"` }{} @@ -109,7 +109,7 @@ func (r *RepositoryRestorer) GetTopics() ([]string, error) { // GetMilestones returns milestones func (r *RepositoryRestorer) GetMilestones() ([]*base.Milestone, error) { - var milestones = make([]*base.Milestone, 0, 10) + milestones := make([]*base.Milestone, 0, 10) p := filepath.Join(r.baseDir, "milestone.yml") _, err := os.Stat(p) if err != nil { @@ -133,7 +133,7 @@ func (r *RepositoryRestorer) GetMilestones() ([]*base.Milestone, error) { // GetReleases returns releases func (r *RepositoryRestorer) GetReleases() ([]*base.Release, error) { - var releases = make([]*base.Release, 0, 10) + releases := make([]*base.Release, 0, 10) p := filepath.Join(r.baseDir, "release.yml") _, err := os.Stat(p) if err != nil { @@ -164,7 +164,7 @@ func (r *RepositoryRestorer) GetReleases() ([]*base.Release, error) { // GetLabels returns labels func (r *RepositoryRestorer) GetLabels() ([]*base.Label, error) { - var labels = make([]*base.Label, 0, 10) + labels := make([]*base.Label, 0, 10) p := filepath.Join(r.baseDir, "label.yml") _, err := os.Stat(p) if err != nil { @@ -188,7 +188,7 @@ func (r *RepositoryRestorer) GetLabels() ([]*base.Label, error) { // GetIssues returns issues according start and limit func (r *RepositoryRestorer) GetIssues(page, perPage int) ([]*base.Issue, bool, error) { - var issues = make([]*base.Issue, 0, 10) + issues := make([]*base.Issue, 0, 10) p := filepath.Join(r.baseDir, "issue.yml") _, err := os.Stat(p) if err != nil { @@ -215,7 +215,7 @@ func (r *RepositoryRestorer) GetIssues(page, perPage int) ([]*base.Issue, bool, // GetComments returns comments according issueNumber func (r *RepositoryRestorer) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) { - var comments = make([]*base.Comment, 0, 10) + comments := make([]*base.Comment, 0, 10) p := filepath.Join(r.commentDir(), fmt.Sprintf("%d.yml", opts.Context.ForeignID())) _, err := os.Stat(p) if err != nil { @@ -239,7 +239,7 @@ func (r *RepositoryRestorer) GetComments(opts base.GetCommentOptions) ([]*base.C // GetPullRequests returns pull requests according page and perPage func (r *RepositoryRestorer) GetPullRequests(page, perPage int) ([]*base.PullRequest, bool, error) { - var pulls = make([]*base.PullRequest, 0, 10) + pulls := make([]*base.PullRequest, 0, 10) p := filepath.Join(r.baseDir, "pull_request.yml") _, err := os.Stat(p) if err != nil { @@ -267,7 +267,7 @@ func (r *RepositoryRestorer) GetPullRequests(page, perPage int) ([]*base.PullReq // GetReviews returns pull requests review func (r *RepositoryRestorer) GetReviews(context base.IssueContext) ([]*base.Review, error) { - var reviews = make([]*base.Review, 0, 10) + reviews := make([]*base.Review, 0, 10) p := filepath.Join(r.reviewDir(), fmt.Sprintf("%d.yml", context.ForeignID())) _, err := os.Stat(p) if err != nil { |