Add notags to fetch (#19487) (#19490)

* Add notags to fetch (#19487)

* gofumpt
This commit is contained in:
6543 2022-04-25 20:26:17 +02:00 committed by GitHub
parent 8d7f1e430a
commit 242f7f1a52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 23 deletions

View File

@ -33,9 +33,7 @@ import (
gouuid "github.com/google/uuid" gouuid "github.com/google/uuid"
) )
var ( var _ base.Uploader = &GiteaLocalUploader{}
_ base.Uploader = &GiteaLocalUploader{}
)
// GiteaLocalUploader implements an Uploader to gitea sites // GiteaLocalUploader implements an Uploader to gitea sites
type GiteaLocalUploader struct { type GiteaLocalUploader struct {
@ -159,7 +157,7 @@ func (g *GiteaLocalUploader) CreateTopics(topics ...string) error {
// CreateMilestones creates milestones // CreateMilestones creates milestones
func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) error { 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 { for _, milestone := range milestones {
var deadline timeutil.TimeStamp var deadline timeutil.TimeStamp
if milestone.Deadline != nil { if milestone.Deadline != nil {
@ -182,7 +180,7 @@ func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) err
milestone.Updated = &milestone.Created milestone.Updated = &milestone.Created
} }
var ms = models.Milestone{ ms := models.Milestone{
RepoID: g.repo.ID, RepoID: g.repo.ID,
Name: milestone.Title, Name: milestone.Title,
Content: milestone.Description, Content: milestone.Description,
@ -210,7 +208,7 @@ func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) err
// CreateLabels creates labels // CreateLabels creates labels
func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error { 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 { for _, label := range labels {
lbs = append(lbs, &models.Label{ lbs = append(lbs, &models.Label{
RepoID: g.repo.ID, RepoID: g.repo.ID,
@ -232,7 +230,7 @@ func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error {
// CreateReleases creates releases // CreateReleases creates releases
func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { 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 { for _, release := range releases {
if release.Created.IsZero() { if release.Created.IsZero() {
if !release.Published.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, RepoID: g.repo.ID,
TagName: release.TagName, TagName: release.TagName,
LowerTagName: strings.ToLower(release.TagName), LowerTagName: strings.ToLower(release.TagName),
@ -297,7 +295,7 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
asset.Created = release.Created asset.Created = release.Created
} }
} }
var attach = repo_model.Attachment{ attach := repo_model.Attachment{
UUID: gouuid.New().String(), UUID: gouuid.New().String(),
Name: asset.Name, Name: asset.Name,
DownloadCount: int64(*asset.DownloadCount), DownloadCount: int64(*asset.DownloadCount),
@ -348,7 +346,7 @@ func (g *GiteaLocalUploader) SyncTags() error {
// CreateIssues creates issues // CreateIssues creates issues
func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error { 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 { for _, issue := range issues {
var labels []*models.Label var labels []*models.Label
for _, label := range issue.Labels { 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, RepoID: g.repo.ID,
Repo: g.repo, Repo: g.repo,
Index: issue.Number, Index: issue.Number,
@ -433,7 +431,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
g.userMap[reaction.UserID] = userid g.userMap[reaction.UserID] = userid
} }
} }
var res = models.Reaction{ res := models.Reaction{
Type: reaction.Content, Type: reaction.Content,
CreatedUnix: timeutil.TimeStampNow(), CreatedUnix: timeutil.TimeStampNow(),
} }
@ -464,7 +462,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
// CreateComments creates comments of issues // CreateComments creates comments of issues
func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { 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 { for _, comment := range comments {
var issue *models.Issue var issue *models.Issue
issueInter, ok := g.issues.Load(comment.IssueIndex) issueInter, ok := g.issues.Load(comment.IssueIndex)
@ -528,7 +526,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
g.userMap[reaction.UserID] = userid g.userMap[reaction.UserID] = userid
} }
} }
var res = models.Reaction{ res := models.Reaction{
Type: reaction.Content, Type: reaction.Content,
CreatedUnix: timeutil.TimeStampNow(), CreatedUnix: timeutil.TimeStampNow(),
} }
@ -553,7 +551,7 @@ func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error {
// CreatePullRequests creates pull requests // CreatePullRequests creates pull requests
func (g *GiteaLocalUploader) CreatePullRequests(prs ...*base.PullRequest) error { 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 { for _, pr := range prs {
gpr, err := g.newPullRequest(pr) gpr, err := g.newPullRequest(pr)
if err != nil { if err != nil {
@ -652,7 +650,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
return nil, err return nil, err
} }
var head = "unknown repository" head := "unknown repository"
if pr.IsForkPullRequest() && pr.State != "closed" { if pr.IsForkPullRequest() && pr.State != "closed" {
if pr.Head.OwnerName != "" { if pr.Head.OwnerName != "" {
remote := pr.Head.OwnerName remote := pr.Head.OwnerName
@ -669,7 +667,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
} }
if ok { if ok {
_, err = git.NewCommand("fetch", remote, pr.Head.Ref).RunInDir(g.repo.RepoPath()) _, err = git.NewCommandContext(g.ctx, "fetch", "--no-tags", "--", remote, pr.Head.Ref).RunInDir(g.repo.RepoPath())
if err != nil { if err != nil {
log.Error("Fetch branch from %s failed: %v", pr.Head.CloneURL, err) log.Error("Fetch branch from %s failed: %v", pr.Head.CloneURL, err)
} else { } else {
@ -723,7 +721,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
pr.Updated = pr.Created pr.Updated = pr.Created
} }
var issue = models.Issue{ issue := models.Issue{
RepoID: g.repo.ID, RepoID: g.repo.ID,
Repo: g.repo, Repo: g.repo,
Title: pr.Title, Title: pr.Title,
@ -773,7 +771,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
g.userMap[reaction.UserID] = userid g.userMap[reaction.UserID] = userid
} }
} }
var res = models.Reaction{ res := models.Reaction{
Type: reaction.Content, Type: reaction.Content,
CreatedUnix: timeutil.TimeStampNow(), CreatedUnix: timeutil.TimeStampNow(),
} }
@ -787,7 +785,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
issue.Reactions = append(issue.Reactions, &res) issue.Reactions = append(issue.Reactions, &res)
} }
var pullRequest = models.PullRequest{ pullRequest := models.PullRequest{
HeadRepoID: g.repo.ID, HeadRepoID: g.repo.ID,
HeadBranch: head, HeadBranch: head,
BaseRepoID: g.repo.ID, BaseRepoID: g.repo.ID,
@ -830,7 +828,7 @@ func convertReviewState(state string) models.ReviewType {
// CreateReviews create pull request reviews // CreateReviews create pull request reviews
func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error { 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 { for _, review := range reviews {
var issue *models.Issue var issue *models.Issue
issueInter, ok := g.issues.Load(review.IssueIndex) 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) review.CreatedAt = time.Unix(int64(issue.CreatedUnix), 0)
} }
var cm = models.Review{ cm := models.Review{
Type: convertReviewState(review.State), Type: convertReviewState(review.State),
IssueID: issue.ID, IssueID: issue.ID,
Content: review.Content, Content: review.Content,
@ -926,7 +924,7 @@ func (g *GiteaLocalUploader) CreateReviews(reviews ...*base.Review) error {
comment.UpdatedAt = comment.CreatedAt comment.UpdatedAt = comment.CreatedAt
} }
var c = models.Comment{ c := models.Comment{
Type: models.CommentTypeCode, Type: models.CommentTypeCode,
PosterID: comment.PosterID, PosterID: comment.PosterID,
IssueID: issue.ID, IssueID: issue.ID,