|
|
@ -76,238 +76,280 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, includeWiki bool) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// CreateMilestone creates milestone
|
|
|
|
// CreateMilestones creates milestones
|
|
|
|
func (g *GiteaLocalUploader) CreateMilestone(milestone *base.Milestone) error { |
|
|
|
func (g *GiteaLocalUploader) CreateMilestones(milestones ...*base.Milestone) error { |
|
|
|
var deadline util.TimeStamp |
|
|
|
var mss = make([]*models.Milestone, 0, len(milestones)) |
|
|
|
if milestone.Deadline != nil { |
|
|
|
for _, milestone := range milestones { |
|
|
|
deadline = util.TimeStamp(milestone.Deadline.Unix()) |
|
|
|
var deadline util.TimeStamp |
|
|
|
} |
|
|
|
if milestone.Deadline != nil { |
|
|
|
if deadline == 0 { |
|
|
|
deadline = util.TimeStamp(milestone.Deadline.Unix()) |
|
|
|
deadline = util.TimeStamp(time.Date(9999, 1, 1, 0, 0, 0, 0, setting.UILocation).Unix()) |
|
|
|
} |
|
|
|
} |
|
|
|
if deadline == 0 { |
|
|
|
var ms = models.Milestone{ |
|
|
|
deadline = util.TimeStamp(time.Date(9999, 1, 1, 0, 0, 0, 0, setting.UILocation).Unix()) |
|
|
|
RepoID: g.repo.ID, |
|
|
|
} |
|
|
|
Name: milestone.Title, |
|
|
|
var ms = models.Milestone{ |
|
|
|
Content: milestone.Description, |
|
|
|
RepoID: g.repo.ID, |
|
|
|
IsClosed: milestone.State == "close", |
|
|
|
Name: milestone.Title, |
|
|
|
DeadlineUnix: deadline, |
|
|
|
Content: milestone.Description, |
|
|
|
} |
|
|
|
IsClosed: milestone.State == "close", |
|
|
|
if ms.IsClosed && milestone.Closed != nil { |
|
|
|
DeadlineUnix: deadline, |
|
|
|
ms.ClosedDateUnix = util.TimeStamp(milestone.Closed.Unix()) |
|
|
|
} |
|
|
|
|
|
|
|
if ms.IsClosed && milestone.Closed != nil { |
|
|
|
|
|
|
|
ms.ClosedDateUnix = util.TimeStamp(milestone.Closed.Unix()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mss = append(mss, &ms) |
|
|
|
} |
|
|
|
} |
|
|
|
err := models.NewMilestone(&ms) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
err := models.InsertMilestones(mss...) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
g.milestones.Store(ms.Name, ms.ID) |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CreateLabel creates label
|
|
|
|
for _, ms := range mss { |
|
|
|
func (g *GiteaLocalUploader) CreateLabel(label *base.Label) error { |
|
|
|
g.milestones.Store(ms.Name, ms.ID) |
|
|
|
var lb = models.Label{ |
|
|
|
|
|
|
|
RepoID: g.repo.ID, |
|
|
|
|
|
|
|
Name: label.Name, |
|
|
|
|
|
|
|
Description: label.Description, |
|
|
|
|
|
|
|
Color: fmt.Sprintf("#%s", label.Color), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
err := models.NewLabel(&lb) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
g.labels.Store(lb.Name, lb.ID) |
|
|
|
|
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// CreateRelease creates release
|
|
|
|
// CreateLabels creates labels
|
|
|
|
func (g *GiteaLocalUploader) CreateRelease(release *base.Release) error { |
|
|
|
func (g *GiteaLocalUploader) CreateLabels(labels ...*base.Label) error { |
|
|
|
var rel = models.Release{ |
|
|
|
var lbs = make([]*models.Label, 0, len(labels)) |
|
|
|
RepoID: g.repo.ID, |
|
|
|
for _, label := range labels { |
|
|
|
PublisherID: g.doer.ID, |
|
|
|
lbs = append(lbs, &models.Label{ |
|
|
|
TagName: release.TagName, |
|
|
|
RepoID: g.repo.ID, |
|
|
|
LowerTagName: strings.ToLower(release.TagName), |
|
|
|
Name: label.Name, |
|
|
|
Target: release.TargetCommitish, |
|
|
|
Description: label.Description, |
|
|
|
Title: release.Name, |
|
|
|
Color: fmt.Sprintf("#%s", label.Color), |
|
|
|
Sha1: release.TargetCommitish, |
|
|
|
}) |
|
|
|
Note: release.Body, |
|
|
|
|
|
|
|
IsDraft: release.Draft, |
|
|
|
|
|
|
|
IsPrerelease: release.Prerelease, |
|
|
|
|
|
|
|
IsTag: false, |
|
|
|
|
|
|
|
CreatedUnix: util.TimeStamp(release.Created.Unix()), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// calc NumCommits
|
|
|
|
err := models.NewLabels(lbs...) |
|
|
|
commit, err := g.gitRepo.GetCommit(rel.TagName) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("GetCommit: %v", err) |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
rel.NumCommits, err = commit.CommitsCount() |
|
|
|
for _, lb := range lbs { |
|
|
|
if err != nil { |
|
|
|
g.labels.Store(lb.Name, lb) |
|
|
|
return fmt.Errorf("CommitsCount: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for _, asset := range release.Assets { |
|
|
|
// CreateReleases creates releases
|
|
|
|
var attach = models.Attachment{ |
|
|
|
func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { |
|
|
|
UUID: gouuid.NewV4().String(), |
|
|
|
var rels = make([]*models.Release, 0, len(releases)) |
|
|
|
Name: asset.Name, |
|
|
|
for _, release := range releases { |
|
|
|
DownloadCount: int64(*asset.DownloadCount), |
|
|
|
var rel = models.Release{ |
|
|
|
Size: int64(*asset.Size), |
|
|
|
RepoID: g.repo.ID, |
|
|
|
CreatedUnix: util.TimeStamp(asset.Created.Unix()), |
|
|
|
PublisherID: g.doer.ID, |
|
|
|
|
|
|
|
TagName: release.TagName, |
|
|
|
|
|
|
|
LowerTagName: strings.ToLower(release.TagName), |
|
|
|
|
|
|
|
Target: release.TargetCommitish, |
|
|
|
|
|
|
|
Title: release.Name, |
|
|
|
|
|
|
|
Sha1: release.TargetCommitish, |
|
|
|
|
|
|
|
Note: release.Body, |
|
|
|
|
|
|
|
IsDraft: release.Draft, |
|
|
|
|
|
|
|
IsPrerelease: release.Prerelease, |
|
|
|
|
|
|
|
IsTag: false, |
|
|
|
|
|
|
|
CreatedUnix: util.TimeStamp(release.Created.Unix()), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// download attachment
|
|
|
|
// calc NumCommits
|
|
|
|
resp, err := http.Get(asset.URL) |
|
|
|
commit, err := g.gitRepo.GetCommit(rel.TagName) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return fmt.Errorf("GetCommit: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
defer resp.Body.Close() |
|
|
|
rel.NumCommits, err = commit.CommitsCount() |
|
|
|
|
|
|
|
|
|
|
|
localPath := attach.LocalPath() |
|
|
|
|
|
|
|
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("MkdirAll: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fw, err := os.Create(localPath) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return fmt.Errorf("Create: %v", err) |
|
|
|
return fmt.Errorf("CommitsCount: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
defer fw.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, err := io.Copy(fw, resp.Body); err != nil { |
|
|
|
for _, asset := range release.Assets { |
|
|
|
return err |
|
|
|
var attach = models.Attachment{ |
|
|
|
|
|
|
|
UUID: gouuid.NewV4().String(), |
|
|
|
|
|
|
|
Name: asset.Name, |
|
|
|
|
|
|
|
DownloadCount: int64(*asset.DownloadCount), |
|
|
|
|
|
|
|
Size: int64(*asset.Size), |
|
|
|
|
|
|
|
CreatedUnix: util.TimeStamp(asset.Created.Unix()), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// download attachment
|
|
|
|
|
|
|
|
resp, err := http.Get(asset.URL) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
defer resp.Body.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
localPath := attach.LocalPath() |
|
|
|
|
|
|
|
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("MkdirAll: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fw, err := os.Create(localPath) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("Create: %v", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
defer fw.Close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, err := io.Copy(fw, resp.Body); err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rel.Attachments = append(rel.Attachments, &attach) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
rel.Attachments = append(rel.Attachments, &attach) |
|
|
|
rels = append(rels, &rel) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return models.InsertReleases(rels...) |
|
|
|
return models.MigrateRelease(&rel) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// CreateIssue creates issue
|
|
|
|
// CreateIssues creates issues
|
|
|
|
func (g *GiteaLocalUploader) CreateIssue(issue *base.Issue) error { |
|
|
|
func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error { |
|
|
|
var labelIDs []int64 |
|
|
|
var iss = make([]*models.Issue, 0, len(issues)) |
|
|
|
for _, label := range issue.Labels { |
|
|
|
for _, issue := range issues { |
|
|
|
id, ok := g.labels.Load(label.Name) |
|
|
|
var labels []*models.Label |
|
|
|
if !ok { |
|
|
|
for _, label := range issue.Labels { |
|
|
|
return fmt.Errorf("Label %s missing when create issue", label.Name) |
|
|
|
lb, ok := g.labels.Load(label.Name) |
|
|
|
|
|
|
|
if ok { |
|
|
|
|
|
|
|
labels = append(labels, lb.(*models.Label)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
labelIDs = append(labelIDs, id.(int64)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var milestoneID int64 |
|
|
|
var milestoneID int64 |
|
|
|
if issue.Milestone != "" { |
|
|
|
if issue.Milestone != "" { |
|
|
|
milestone, ok := g.milestones.Load(issue.Milestone) |
|
|
|
milestone, ok := g.milestones.Load(issue.Milestone) |
|
|
|
if !ok { |
|
|
|
if ok { |
|
|
|
return fmt.Errorf("Milestone %s missing when create issue", issue.Milestone) |
|
|
|
milestoneID = milestone.(int64) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
milestoneID = milestone.(int64) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var is = models.Issue{ |
|
|
|
var is = models.Issue{ |
|
|
|
RepoID: g.repo.ID, |
|
|
|
RepoID: g.repo.ID, |
|
|
|
Repo: g.repo, |
|
|
|
Repo: g.repo, |
|
|
|
Index: issue.Number, |
|
|
|
Index: issue.Number, |
|
|
|
PosterID: g.doer.ID, |
|
|
|
PosterID: g.doer.ID, |
|
|
|
Title: issue.Title, |
|
|
|
Title: issue.Title, |
|
|
|
Content: issue.Content, |
|
|
|
Content: issue.Content, |
|
|
|
IsClosed: issue.State == "closed", |
|
|
|
IsClosed: issue.State == "closed", |
|
|
|
IsLocked: issue.IsLocked, |
|
|
|
IsLocked: issue.IsLocked, |
|
|
|
MilestoneID: milestoneID, |
|
|
|
MilestoneID: milestoneID, |
|
|
|
CreatedUnix: util.TimeStamp(issue.Created.Unix()), |
|
|
|
Labels: labels, |
|
|
|
} |
|
|
|
CreatedUnix: util.TimeStamp(issue.Created.Unix()), |
|
|
|
if issue.Closed != nil { |
|
|
|
} |
|
|
|
is.ClosedUnix = util.TimeStamp(issue.Closed.Unix()) |
|
|
|
if issue.Closed != nil { |
|
|
|
|
|
|
|
is.ClosedUnix = util.TimeStamp(issue.Closed.Unix()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// TODO: add reactions
|
|
|
|
|
|
|
|
iss = append(iss, &is) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
err := models.InsertIssue(&is, labelIDs) |
|
|
|
err := models.InsertIssues(iss...) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
g.issues.Store(issue.Number, is.ID) |
|
|
|
for _, is := range iss { |
|
|
|
// TODO: add reactions
|
|
|
|
g.issues.Store(is.Index, is.ID) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CreateComments creates comments of issues
|
|
|
|
|
|
|
|
func (g *GiteaLocalUploader) CreateComments(comments ...*base.Comment) error { |
|
|
|
|
|
|
|
var cms = make([]*models.Comment, 0, len(comments)) |
|
|
|
|
|
|
|
for _, comment := range comments { |
|
|
|
|
|
|
|
var issueID int64 |
|
|
|
|
|
|
|
if issueIDStr, ok := g.issues.Load(comment.IssueIndex); !ok { |
|
|
|
|
|
|
|
issue, err := models.GetIssueByIndex(g.repo.ID, comment.IssueIndex) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
issueID = issue.ID |
|
|
|
|
|
|
|
g.issues.Store(comment.IssueIndex, issueID) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
issueID = issueIDStr.(int64) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cms = append(cms, &models.Comment{ |
|
|
|
|
|
|
|
IssueID: issueID, |
|
|
|
|
|
|
|
Type: models.CommentTypeComment, |
|
|
|
|
|
|
|
PosterID: g.doer.ID, |
|
|
|
|
|
|
|
Content: comment.Content, |
|
|
|
|
|
|
|
CreatedUnix: util.TimeStamp(comment.Created.Unix()), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Reactions
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return models.InsertIssueComments(cms) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// CreateComment creates comment
|
|
|
|
// CreatePullRequests creates pull requests
|
|
|
|
func (g *GiteaLocalUploader) CreateComment(issueNumber int64, comment *base.Comment) error { |
|
|
|
func (g *GiteaLocalUploader) CreatePullRequests(prs ...*base.PullRequest) error { |
|
|
|
var issueID int64 |
|
|
|
var gprs = make([]*models.PullRequest, 0, len(prs)) |
|
|
|
if issueIDStr, ok := g.issues.Load(issueNumber); !ok { |
|
|
|
for _, pr := range prs { |
|
|
|
issue, err := models.GetIssueByIndex(g.repo.ID, issueNumber) |
|
|
|
gpr, err := g.newPullRequest(pr) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
issueID = issue.ID |
|
|
|
gprs = append(gprs, gpr) |
|
|
|
g.issues.Store(issueNumber, issueID) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
issueID = issueIDStr.(int64) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err := models.InsertPullRequests(gprs...); err != nil { |
|
|
|
var cm = models.Comment{ |
|
|
|
return err |
|
|
|
IssueID: issueID, |
|
|
|
|
|
|
|
Type: models.CommentTypeComment, |
|
|
|
|
|
|
|
PosterID: g.doer.ID, |
|
|
|
|
|
|
|
Content: comment.Content, |
|
|
|
|
|
|
|
CreatedUnix: util.TimeStamp(comment.Created.Unix()), |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
err := models.InsertComment(&cm) |
|
|
|
for _, pr := range gprs { |
|
|
|
// TODO: Reactions
|
|
|
|
g.issues.Store(pr.Issue.Index, pr.Issue.ID) |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// CreatePullRequest creates pull request
|
|
|
|
func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullRequest, error) { |
|
|
|
func (g *GiteaLocalUploader) CreatePullRequest(pr *base.PullRequest) error { |
|
|
|
var labels []*models.Label |
|
|
|
var labelIDs []int64 |
|
|
|
|
|
|
|
for _, label := range pr.Labels { |
|
|
|
for _, label := range pr.Labels { |
|
|
|
id, ok := g.labels.Load(label.Name) |
|
|
|
lb, ok := g.labels.Load(label.Name) |
|
|
|
if !ok { |
|
|
|
if ok { |
|
|
|
return fmt.Errorf("Label %s missing when create issue", label.Name) |
|
|
|
labels = append(labels, lb.(*models.Label)) |
|
|
|
} |
|
|
|
} |
|
|
|
labelIDs = append(labelIDs, id.(int64)) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var milestoneID int64 |
|
|
|
var milestoneID int64 |
|
|
|
if pr.Milestone != "" { |
|
|
|
if pr.Milestone != "" { |
|
|
|
milestone, ok := g.milestones.Load(pr.Milestone) |
|
|
|
milestone, ok := g.milestones.Load(pr.Milestone) |
|
|
|
if !ok { |
|
|
|
if ok { |
|
|
|
return fmt.Errorf("Milestone %s missing when create issue", pr.Milestone) |
|
|
|
milestoneID = milestone.(int64) |
|
|
|
} |
|
|
|
} |
|
|
|
milestoneID = milestone.(int64) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// download patch file
|
|
|
|
// download patch file
|
|
|
|
resp, err := http.Get(pr.PatchURL) |
|
|
|
resp, err := http.Get(pr.PatchURL) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
defer resp.Body.Close() |
|
|
|
defer resp.Body.Close() |
|
|
|
pullDir := filepath.Join(g.repo.RepoPath(), "pulls") |
|
|
|
pullDir := filepath.Join(g.repo.RepoPath(), "pulls") |
|
|
|
if err = os.MkdirAll(pullDir, os.ModePerm); err != nil { |
|
|
|
if err = os.MkdirAll(pullDir, os.ModePerm); err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
f, err := os.Create(filepath.Join(pullDir, fmt.Sprintf("%d.patch", pr.Number))) |
|
|
|
f, err := os.Create(filepath.Join(pullDir, fmt.Sprintf("%d.patch", pr.Number))) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
defer f.Close() |
|
|
|
defer f.Close() |
|
|
|
_, err = io.Copy(f, resp.Body) |
|
|
|
_, err = io.Copy(f, resp.Body) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// set head information
|
|
|
|
// set head information
|
|
|
|
pullHead := filepath.Join(g.repo.RepoPath(), "refs", "pull", fmt.Sprintf("%d", pr.Number)) |
|
|
|
pullHead := filepath.Join(g.repo.RepoPath(), "refs", "pull", fmt.Sprintf("%d", pr.Number)) |
|
|
|
if err := os.MkdirAll(pullHead, os.ModePerm); err != nil { |
|
|
|
if err := os.MkdirAll(pullHead, os.ModePerm); err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
p, err := os.Create(filepath.Join(pullHead, "head")) |
|
|
|
p, err := os.Create(filepath.Join(pullHead, "head")) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
defer p.Close() |
|
|
|
defer p.Close() |
|
|
|
_, err = p.WriteString(pr.Head.SHA) |
|
|
|
_, err = p.WriteString(pr.Head.SHA) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var head = "unknown repository" |
|
|
|
var head = "unknown repository" |
|
|
@ -333,16 +375,16 @@ func (g *GiteaLocalUploader) CreatePullRequest(pr *base.PullRequest) error { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
headBranch := filepath.Join(g.repo.RepoPath(), "refs", "heads", pr.Head.OwnerName, pr.Head.Ref) |
|
|
|
headBranch := filepath.Join(g.repo.RepoPath(), "refs", "heads", pr.Head.OwnerName, pr.Head.Ref) |
|
|
|
if err := os.MkdirAll(filepath.Dir(headBranch), os.ModePerm); err != nil { |
|
|
|
if err := os.MkdirAll(filepath.Dir(headBranch), os.ModePerm); err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
b, err := os.Create(headBranch) |
|
|
|
b, err := os.Create(headBranch) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
defer b.Close() |
|
|
|
defer b.Close() |
|
|
|
_, err = b.WriteString(pr.Head.SHA) |
|
|
|
_, err = b.WriteString(pr.Head.SHA) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
} |
|
|
|
head = pr.Head.OwnerName + "/" + pr.Head.Ref |
|
|
|
head = pr.Head.OwnerName + "/" + pr.Head.Ref |
|
|
|
} |
|
|
|
} |
|
|
@ -373,6 +415,7 @@ func (g *GiteaLocalUploader) CreatePullRequest(pr *base.PullRequest) error { |
|
|
|
IsPull: true, |
|
|
|
IsPull: true, |
|
|
|
IsClosed: pr.State == "closed", |
|
|
|
IsClosed: pr.State == "closed", |
|
|
|
IsLocked: pr.IsLocked, |
|
|
|
IsLocked: pr.IsLocked, |
|
|
|
|
|
|
|
Labels: labels, |
|
|
|
CreatedUnix: util.TimeStamp(pr.Created.Unix()), |
|
|
|
CreatedUnix: util.TimeStamp(pr.Created.Unix()), |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
@ -389,7 +432,7 @@ func (g *GiteaLocalUploader) CreatePullRequest(pr *base.PullRequest) error { |
|
|
|
// TODO: reactions
|
|
|
|
// TODO: reactions
|
|
|
|
// TODO: assignees
|
|
|
|
// TODO: assignees
|
|
|
|
|
|
|
|
|
|
|
|
return models.InsertPullRequest(&pullRequest, labelIDs) |
|
|
|
return &pullRequest, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Rollback when migrating failed, this will rollback all the changes.
|
|
|
|
// Rollback when migrating failed, this will rollback all the changes.
|
|
|
|