forked from forgejo/forgejo
migrations: add test for importing pull requests in gitea uploader (#18752)
* logs: add the buffer logger to inspect logs during testing Signed-off-by: Loïc Dachary <loic@dachary.org> * migrations: add test for importing pull requests in gitea uploader Signed-off-by: Loïc Dachary <loic@dachary.org> * for each git.OpenRepositoryCtx, call Close * Content is expected to return the content of the log * test for errors before defer Co-authored-by: Loïc Dachary <loic@dachary.org> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
parent
e4ef61ee0f
commit
49cab2b01f
12 changed files with 512 additions and 20 deletions
|
@ -484,19 +484,9 @@ func (g *GiteaLocalUploader) CreatePullRequests(prs ...*base.PullRequest) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullRequest, error) {
|
||||
var labels []*models.Label
|
||||
for _, label := range pr.Labels {
|
||||
lb, ok := g.labels[label.Name]
|
||||
if ok {
|
||||
labels = append(labels, lb)
|
||||
}
|
||||
}
|
||||
|
||||
milestoneID := g.milestones[pr.Milestone]
|
||||
|
||||
func (g *GiteaLocalUploader) updateGitForPullRequest(pr *base.PullRequest) (head string, err error) {
|
||||
// download patch file
|
||||
err := func() error {
|
||||
err = func() error {
|
||||
if pr.PatchURL == "" {
|
||||
return nil
|
||||
}
|
||||
|
@ -519,25 +509,25 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
|
|||
return err
|
||||
}()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
// set head information
|
||||
pullHead := filepath.Join(g.repo.RepoPath(), "refs", "pull", fmt.Sprintf("%d", pr.Number))
|
||||
if err := os.MkdirAll(pullHead, os.ModePerm); err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
p, err := os.Create(filepath.Join(pullHead, "head"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
_, err = p.WriteString(pr.Head.SHA)
|
||||
p.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
|
||||
head := "unknown repository"
|
||||
head = "unknown repository"
|
||||
if pr.IsForkPullRequest() && pr.State != "closed" {
|
||||
if pr.Head.OwnerName != "" {
|
||||
remote := pr.Head.OwnerName
|
||||
|
@ -560,16 +550,16 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
|
|||
} else {
|
||||
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 {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
b, err := os.Create(headBranch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
_, err = b.WriteString(pr.Head.SHA)
|
||||
b.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return "", err
|
||||
}
|
||||
head = pr.Head.OwnerName + "/" + pr.Head.Ref
|
||||
}
|
||||
|
@ -595,6 +585,25 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
|
|||
}
|
||||
}
|
||||
|
||||
return head, nil
|
||||
}
|
||||
|
||||
func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullRequest, error) {
|
||||
var labels []*models.Label
|
||||
for _, label := range pr.Labels {
|
||||
lb, ok := g.labels[label.Name]
|
||||
if ok {
|
||||
labels = append(labels, lb)
|
||||
}
|
||||
}
|
||||
|
||||
milestoneID := g.milestones[pr.Milestone]
|
||||
|
||||
head, err := g.updateGitForPullRequest(pr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("updateGitForPullRequest: %w", err)
|
||||
}
|
||||
|
||||
if pr.Created.IsZero() {
|
||||
if pr.Closed != nil {
|
||||
pr.Created = *pr.Closed
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue