Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape git fetch remote (#19487) #19490

Merged
merged 5 commits into from
Apr 25, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions services/migrations/gitea_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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() {
Expand All @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -669,7 +667,7 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
}

if ok {
_, err = git.NewCommand("fetch", remote, pr.Head.Ref).RunInDir(g.repo.RepoPath())
_, err = git.NewCommandContext(g.ctx, "fetch", remote, "--no-tags", "--", pr.Head.Ref).RunInDir(g.repo.RepoPath())
6543 marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
log.Error("Fetch branch from %s failed: %v", pr.Head.CloneURL, err)
} else {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
}
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down