forked from forgejo/forgejo
Add migrate from OneDev (#16356)
* Use context to simplify logic. * Added migration from OneDev. This PR adds [OneDev](https://code.onedev.io/) as migration source. Supported: - [x] Milestones - [x] Issues - [x] Pull Requests - [x] Comments - [x] Reviews - [x] Labels
This commit is contained in:
parent
2d1935acc7
commit
cee5f7c5e2
24 changed files with 1093 additions and 92 deletions
|
@ -444,6 +444,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
|
|||
Labels: labels,
|
||||
Assignees: assignees,
|
||||
IsLocked: issue.IsLocked,
|
||||
Context: base.BasicIssueContext(issue.Index),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -466,26 +467,26 @@ func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comm
|
|||
default:
|
||||
}
|
||||
|
||||
comments, _, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.IssueNumber, gitea_sdk.ListIssueCommentOptions{ListOptions: gitea_sdk.ListOptions{
|
||||
comments, _, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID(), gitea_sdk.ListIssueCommentOptions{ListOptions: gitea_sdk.ListOptions{
|
||||
// PageSize: g.maxPerPage,
|
||||
// Page: i,
|
||||
}})
|
||||
if err != nil {
|
||||
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", opts.IssueNumber, err)
|
||||
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", opts.Context.ForeignID(), err)
|
||||
}
|
||||
|
||||
for _, comment := range comments {
|
||||
reactions, err := g.getCommentReactions(comment.ID)
|
||||
if err != nil {
|
||||
log.Warn("Unable to load comment reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.IssueNumber, comment.ID, g.repoOwner, g.repoName, err)
|
||||
log.Warn("Unable to load comment reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)
|
||||
if err2 := models.CreateRepositoryNotice(
|
||||
fmt.Sprintf("Unable to load reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.IssueNumber, comment.ID, g.repoOwner, g.repoName, err)); err2 != nil {
|
||||
fmt.Sprintf("Unable to load reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", opts.Context.ForeignID(), comment.ID, g.repoOwner, g.repoName, err)); err2 != nil {
|
||||
log.Error("create repository notice failed: ", err2)
|
||||
}
|
||||
}
|
||||
|
||||
allComments = append(allComments, &base.Comment{
|
||||
IssueIndex: opts.IssueNumber,
|
||||
IssueIndex: opts.Context.LocalID(),
|
||||
PosterID: comment.Poster.ID,
|
||||
PosterName: comment.Poster.UserName,
|
||||
PosterEmail: comment.Poster.Email,
|
||||
|
@ -615,6 +616,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques
|
|||
RepoName: g.repoName,
|
||||
OwnerName: g.repoOwner,
|
||||
},
|
||||
Context: base.BasicIssueContext(pr.Index),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -626,7 +628,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques
|
|||
}
|
||||
|
||||
// GetReviews returns pull requests review
|
||||
func (g *GiteaDownloader) GetReviews(index int64) ([]*base.Review, error) {
|
||||
func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) {
|
||||
if err := g.client.CheckServerVersionConstraint(">=1.12"); err != nil {
|
||||
log.Info("GiteaDownloader: instance to old, skip GetReviews")
|
||||
return nil, nil
|
||||
|
@ -642,7 +644,7 @@ func (g *GiteaDownloader) GetReviews(index int64) ([]*base.Review, error) {
|
|||
default:
|
||||
}
|
||||
|
||||
prl, _, err := g.client.ListPullReviews(g.repoOwner, g.repoName, index, gitea_sdk.ListPullReviewsOptions{ListOptions: gitea_sdk.ListOptions{
|
||||
prl, _, err := g.client.ListPullReviews(g.repoOwner, g.repoName, context.ForeignID(), gitea_sdk.ListPullReviewsOptions{ListOptions: gitea_sdk.ListOptions{
|
||||
Page: i,
|
||||
PageSize: g.maxPerPage,
|
||||
}})
|
||||
|
@ -652,7 +654,7 @@ func (g *GiteaDownloader) GetReviews(index int64) ([]*base.Review, error) {
|
|||
|
||||
for _, pr := range prl {
|
||||
|
||||
rcl, _, err := g.client.ListPullReviewComments(g.repoOwner, g.repoName, index, pr.ID)
|
||||
rcl, _, err := g.client.ListPullReviewComments(g.repoOwner, g.repoName, context.ForeignID(), pr.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -678,7 +680,7 @@ func (g *GiteaDownloader) GetReviews(index int64) ([]*base.Review, error) {
|
|||
|
||||
allReviews = append(allReviews, &base.Review{
|
||||
ID: pr.ID,
|
||||
IssueIndex: index,
|
||||
IssueIndex: context.LocalID(),
|
||||
ReviewerID: pr.Reviewer.ID,
|
||||
ReviewerName: pr.Reviewer.UserName,
|
||||
Official: pr.Official,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue