58 changes: 22 additions & 36 deletions modules/migration/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,34 @@ package migration

import "time"

// IssueContext is used to map between local and foreign issue/PR ids.
type IssueContext interface {
LocalID() int64
ForeignID() int64
}

// BasicIssueContext is a 1:1 mapping between local and foreign ids.
type BasicIssueContext int64

// LocalID gets the local id.
func (c BasicIssueContext) LocalID() int64 {
return int64(c)
}

// ForeignID gets the foreign id.
func (c BasicIssueContext) ForeignID() int64 {
return int64(c)
}

// Issue is a standard issue information
type Issue struct {
Number int64 `json:"number"`
PosterID int64 `yaml:"poster_id" json:"poster_id"`
PosterName string `yaml:"poster_name" json:"poster_name"`
PosterEmail string `yaml:"poster_email" json:"poster_email"`
Title string `json:"title"`
Content string `json:"content"`
Ref string `json:"ref"`
Milestone string `json:"milestone"`
State string `json:"state"` // closed, open
IsLocked bool `yaml:"is_locked" json:"is_locked"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Closed *time.Time `json:"closed"`
Labels []*Label `json:"labels"`
Reactions []*Reaction `json:"reactions"`
Assignees []string `json:"assignees"`
Context IssueContext `yaml:"-"`
Number int64 `json:"number"`
PosterID int64 `yaml:"poster_id" json:"poster_id"`
PosterName string `yaml:"poster_name" json:"poster_name"`
PosterEmail string `yaml:"poster_email" json:"poster_email"`
Title string `json:"title"`
Content string `json:"content"`
Ref string `json:"ref"`
Milestone string `json:"milestone"`
State string `json:"state"` // closed, open
IsLocked bool `yaml:"is_locked" json:"is_locked"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
Closed *time.Time `json:"closed"`
Labels []*Label `json:"labels"`
Reactions []*Reaction `json:"reactions"`
Assignees []string `json:"assignees"`
ForeignIndex int64 `json:"foreign_id"`
Context DownloaderContext `yaml:"-"`
}

// GetExternalName ExternalUserMigrated interface
func (i *Issue) GetExternalName() string { return i.PosterName }

// GetExternalID ExternalUserMigrated interface
func (i *Issue) GetExternalID() int64 { return i.PosterID }

func (i *Issue) GetLocalIndex() int64 { return i.Number }
func (i *Issue) GetForeignIndex() int64 { return i.ForeignIndex }
func (i *Issue) GetContext() DownloaderContext { return i.Context }
11 changes: 8 additions & 3 deletions modules/migration/null_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,23 @@ func (n NullDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
return nil, false, &ErrNotSupported{Entity: "Issues"}
}

// GetComments returns comments according the options
func (n NullDownloader) GetComments(GetCommentOptions) ([]*Comment, bool, error) {
// GetComments returns comments of an issue or PR
func (n NullDownloader) GetComments(commentable Commentable) ([]*Comment, bool, error) {
return nil, false, &ErrNotSupported{Entity: "Comments"}
}

// GetAllComments returns paginated comments
func (n NullDownloader) GetAllComments(page, perPage int) ([]*Comment, bool, error) {
return nil, false, &ErrNotSupported{Entity: "AllComments"}
}

// GetPullRequests returns pull requests according page and perPage
func (n NullDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) {
return nil, false, &ErrNotSupported{Entity: "PullRequests"}
}

// GetReviews returns pull requests review
func (n NullDownloader) GetReviews(pullRequestContext IssueContext) ([]*Review, error) {
func (n NullDownloader) GetReviews(reviewable Reviewable) ([]*Review, error) {
return nil, &ErrNotSupported{Entity: "Reviews"}
}

Expand Down
7 changes: 6 additions & 1 deletion modules/migration/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ type PullRequest struct {
Assignees []string
IsLocked bool `yaml:"is_locked"`
Reactions []*Reaction
Context IssueContext `yaml:"-"`
ForeignIndex int64
Context DownloaderContext `yaml:"-"`
}

func (p *PullRequest) GetLocalIndex() int64 { return p.Number }
func (p *PullRequest) GetForeignIndex() int64 { return p.ForeignIndex }
func (p *PullRequest) GetContext() DownloaderContext { return p.Context }

// IsForkPullRequest returns true if the pull request from a forked repository but not the same repository
func (p *PullRequest) IsForkPullRequest() bool {
return p.Head.RepoPath() != p.Base.RepoPath()
Expand Down
8 changes: 4 additions & 4 deletions modules/migration/retry_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ func (d *RetryDownloader) GetIssues(page, perPage int) ([]*Issue, bool, error) {
}

// GetComments returns a repository's comments with retry
func (d *RetryDownloader) GetComments(opts GetCommentOptions) ([]*Comment, bool, error) {
func (d *RetryDownloader) GetComments(commentable Commentable) ([]*Comment, bool, error) {
var (
comments []*Comment
isEnd bool
err error
)

err = d.retry(func() error {
comments, isEnd, err = d.Downloader.GetComments(opts)
comments, isEnd, err = d.Downloader.GetComments(commentable)
return err
})

Expand All @@ -180,14 +180,14 @@ func (d *RetryDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bo
}

// GetReviews returns pull requests reviews
func (d *RetryDownloader) GetReviews(pullRequestContext IssueContext) ([]*Review, error) {
func (d *RetryDownloader) GetReviews(reviewable Reviewable) ([]*Review, error) {
var (
reviews []*Review
err error
)

err = d.retry(func() error {
reviews, err = d.Downloader.GetReviews(pullRequestContext)
reviews, err = d.Downloader.GetReviews(reviewable)
return err
})

Expand Down
6 changes: 6 additions & 0 deletions modules/migration/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ package migration

import "time"

// Reviewable can be reviewed
type Reviewable interface {
GetLocalIndex() int64
GetForeignIndex() int64
}

// enumerate all review states
const (
ReviewStatePending = "PENDING"
Expand Down
38 changes: 8 additions & 30 deletions services/migrations/codebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,17 +266,7 @@ func (d *CodebaseDownloader) GetLabels() ([]*base.Label, error) {
}

type codebaseIssueContext struct {
foreignID int64
localID int64
Comments []*base.Comment
}

func (c codebaseIssueContext) LocalID() int64 {
return c.localID
}

func (c codebaseIssueContext) ForeignID() int64 {
return c.foreignID
Comments []*base.Comment
}

// GetIssues returns issues, limits are not supported
Expand Down Expand Up @@ -402,10 +392,9 @@ func (d *CodebaseDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool,
Labels: []*base.Label{
{Name: issue.Type.Name},
},
ForeignIndex: issue.TicketID.Value,
Context: codebaseIssueContext{
foreignID: issue.TicketID.Value,
localID: issue.TicketID.Value,
Comments: comments[1:],
Comments: comments[1:],
},
})

Expand All @@ -418,10 +407,10 @@ func (d *CodebaseDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool,
}

// GetComments returns comments
func (d *CodebaseDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
context, ok := opts.Context.(codebaseIssueContext)
func (d *CodebaseDownloader) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
context, ok := commentable.GetContext().(codebaseIssueContext)
if !ok {
return nil, false, fmt.Errorf("unexpected comment context: %+v", opts.Context)
return nil, false, fmt.Errorf("unexpected context: %+v", commentable.GetContext())
}

return context.Comments, true, nil
Expand Down Expand Up @@ -570,27 +559,16 @@ func (d *CodebaseDownloader) GetPullRequests(page, perPage int) ([]*base.PullReq
SHA: d.getHeadCommit(rawMergeRequest.TargetRef),
RepoName: d.repoName,
},
ForeignIndex: rawMergeRequest.ID.Value,
Context: codebaseIssueContext{
foreignID: rawMergeRequest.ID.Value,
localID: number,
Comments: comments[1:],
Comments: comments[1:],
},
})
}

return pullRequests, true, nil
}

// GetReviews returns pull requests reviews
func (d *CodebaseDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) {
return []*base.Review{}, nil
}

// GetTopics return repository topics
func (d *CodebaseDownloader) GetTopics() ([]string, error) {
return []string{}, nil
}

func (d *CodebaseDownloader) tryGetUser(userID int64) *codebaseUser {
if len(d.userMap) == 0 {
var rawUsers struct {
Expand Down
6 changes: 2 additions & 4 deletions services/migrations/codebase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ func TestCodebaseDownloadRepo(t *testing.T) {
},
}, issues)

comments, _, err := downloader.GetComments(base.GetCommentOptions{
Context: issues[0].Context,
})
comments, _, err := downloader.GetComments(issues[0])
assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{
{
Expand Down Expand Up @@ -148,7 +146,7 @@ func TestCodebaseDownloadRepo(t *testing.T) {
},
}, prs)

rvs, err := downloader.GetReviews(prs[0].Context)
rvs, err := downloader.GetReviews(prs[0])
assert.NoError(t, err)
assert.Empty(t, rvs)
}
5 changes: 0 additions & 5 deletions services/migrations/gitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,3 @@ func NewGitBucketDownloader(ctx context.Context, baseURL, userName, password, to
func (g *GitBucketDownloader) SupportGetRepoComments() bool {
return false
}

// GetReviews is not supported
func (g *GitBucketDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) {
return nil, &base.ErrNotSupported{Entity: "Reviews"}
}
54 changes: 27 additions & 27 deletions services/migrations/gitea_downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,22 +415,22 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
}

allIssues = append(allIssues, &base.Issue{
Title: issue.Title,
Number: issue.Index,
PosterID: issue.Poster.ID,
PosterName: issue.Poster.UserName,
PosterEmail: issue.Poster.Email,
Content: issue.Body,
Milestone: milestone,
State: string(issue.State),
Created: issue.Created,
Updated: issue.Updated,
Closed: issue.Closed,
Reactions: reactions,
Labels: labels,
Assignees: assignees,
IsLocked: issue.IsLocked,
Context: base.BasicIssueContext(issue.Index),
Title: issue.Title,
Number: issue.Index,
PosterID: issue.Poster.ID,
PosterName: issue.Poster.UserName,
PosterEmail: issue.Poster.Email,
Content: issue.Body,
Milestone: milestone,
State: string(issue.State),
Created: issue.Created,
Updated: issue.Updated,
Closed: issue.Closed,
Reactions: reactions,
Labels: labels,
Assignees: assignees,
IsLocked: issue.IsLocked,
ForeignIndex: issue.Index,
})
}

Expand All @@ -442,7 +442,7 @@ func (g *GiteaDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, err
}

// GetComments returns comments according issueNumber
func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
func (g *GiteaDownloader) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
allComments := make([]*base.Comment, 0, g.maxPerPage)

for i := 1; ; i++ {
Expand All @@ -453,26 +453,26 @@ func (g *GiteaDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comm
default:
}

comments, _, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID(), gitea_sdk.ListIssueCommentOptions{ListOptions: gitea_sdk.ListOptions{
comments, _, err := g.client.ListIssueComments(g.repoOwner, g.repoName, commentable.GetForeignIndex(), 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.Context.ForeignID(), err)
return nil, false, fmt.Errorf("error while listing comments for issue #%d. Error: %v", commentable.GetForeignIndex(), 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.Context.ForeignID(), 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", commentable.GetForeignIndex(), comment.ID, g.repoOwner, g.repoName, err)
if err2 := admin_model.CreateRepositoryNotice(
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 {
fmt.Sprintf("Unable to load reactions during migrating issue #%d for comment %d to %s/%s. Error: %v", commentable.GetForeignIndex(), comment.ID, g.repoOwner, g.repoName, err)); err2 != nil {
log.Error("create repository notice failed: ", err2)
}
}

allComments = append(allComments, &base.Comment{
IssueIndex: opts.Context.LocalID(),
IssueIndex: commentable.GetLocalIndex(),
Index: comment.ID,
PosterID: comment.Poster.ID,
PosterName: comment.Poster.UserName,
Expand Down Expand Up @@ -602,7 +602,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques
RepoName: g.repoName,
OwnerName: g.repoOwner,
},
Context: base.BasicIssueContext(pr.Index),
ForeignIndex: pr.Index,
})
}

Expand All @@ -614,7 +614,7 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques
}

// GetReviews returns pull requests review
func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) {
func (g *GiteaDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
if err := g.client.CheckServerVersionConstraint(">=1.12"); err != nil {
log.Info("GiteaDownloader: instance to old, skip GetReviews")
return nil, nil
Expand All @@ -630,7 +630,7 @@ func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review,
default:
}

prl, _, err := g.client.ListPullReviews(g.repoOwner, g.repoName, context.ForeignID(), gitea_sdk.ListPullReviewsOptions{ListOptions: gitea_sdk.ListOptions{
prl, _, err := g.client.ListPullReviews(g.repoOwner, g.repoName, reviewable.GetForeignIndex(), gitea_sdk.ListPullReviewsOptions{ListOptions: gitea_sdk.ListOptions{
Page: i,
PageSize: g.maxPerPage,
}})
Expand All @@ -640,7 +640,7 @@ func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review,

for _, pr := range prl {

rcl, _, err := g.client.ListPullReviewComments(g.repoOwner, g.repoName, context.ForeignID(), pr.ID)
rcl, _, err := g.client.ListPullReviewComments(g.repoOwner, g.repoName, reviewable.GetForeignIndex(), pr.ID)
if err != nil {
return nil, err
}
Expand All @@ -666,7 +666,7 @@ func (g *GiteaDownloader) GetReviews(context base.IssueContext) ([]*base.Review,

allReviews = append(allReviews, &base.Review{
ID: pr.ID,
IssueIndex: context.LocalID(),
IssueIndex: reviewable.GetLocalIndex(),
ReviewerID: pr.Reviewer.ID,
ReviewerName: pr.Reviewer.UserName,
Official: pr.Official,
Expand Down
6 changes: 2 additions & 4 deletions services/migrations/gitea_downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ func TestGiteaDownloadRepo(t *testing.T) {
},
}, issues)

comments, _, err := downloader.GetComments(base.GetCommentOptions{
Context: base.BasicIssueContext(4),
})
comments, _, err := downloader.GetComments(&base.Issue{Number: 4, ForeignIndex: 4})
assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{
{
Expand Down Expand Up @@ -265,7 +263,7 @@ func TestGiteaDownloadRepo(t *testing.T) {
PatchURL: "https://gitea.com/gitea/test_repo/pulls/12.patch",
}, prs[1])

reviews, err := downloader.GetReviews(base.BasicIssueContext(7))
reviews, err := downloader.GetReviews(&base.Issue{Number: 7, ForeignIndex: 7})
assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{
{
Expand Down
8 changes: 8 additions & 0 deletions services/migrations/gitea_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"io"
"os"
"path/filepath"
"strconv"
"strings"
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/foreignreference"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
Expand Down Expand Up @@ -373,6 +375,12 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
Labels: labels,
CreatedUnix: timeutil.TimeStamp(issue.Created.Unix()),
UpdatedUnix: timeutil.TimeStamp(issue.Updated.Unix()),
ForeignReference: &foreignreference.ForeignReference{
LocalIndex: issue.GetLocalIndex(),
ForeignIndex: strconv.FormatInt(issue.GetForeignIndex(), 10),
RepoID: g.repo.ID,
Type: foreignreference.TypeIssue,
},
}

if err := g.remapUser(issue, &is); err != nil {
Expand Down
62 changes: 29 additions & 33 deletions services/migrations/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,22 +446,22 @@ func (g *GithubDownloaderV3) GetIssues(page, perPage int) ([]*base.Issue, bool,
}

allIssues = append(allIssues, &base.Issue{
Title: *issue.Title,
Number: int64(*issue.Number),
PosterID: issue.GetUser().GetID(),
PosterName: issue.GetUser().GetLogin(),
PosterEmail: issue.GetUser().GetEmail(),
Content: issue.GetBody(),
Milestone: issue.GetMilestone().GetTitle(),
State: issue.GetState(),
Created: issue.GetCreatedAt(),
Updated: issue.GetUpdatedAt(),
Labels: labels,
Reactions: reactions,
Closed: issue.ClosedAt,
IsLocked: issue.GetLocked(),
Assignees: assignees,
Context: base.BasicIssueContext(*issue.Number),
Title: *issue.Title,
Number: int64(*issue.Number),
PosterID: issue.GetUser().GetID(),
PosterName: issue.GetUser().GetLogin(),
PosterEmail: issue.GetUser().GetEmail(),
Content: issue.GetBody(),
Milestone: issue.GetMilestone().GetTitle(),
State: issue.GetState(),
Created: issue.GetCreatedAt(),
Updated: issue.GetUpdatedAt(),
Labels: labels,
Reactions: reactions,
Closed: issue.ClosedAt,
IsLocked: issue.GetLocked(),
Assignees: assignees,
ForeignIndex: int64(*issue.Number),
})
}

Expand All @@ -474,16 +474,12 @@ func (g *GithubDownloaderV3) SupportGetRepoComments() bool {
}

// GetComments returns comments according issueNumber
func (g *GithubDownloaderV3) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
if opts.Context != nil {
comments, err := g.getComments(opts.Context)
return comments, false, err
}

return g.GetAllComments(opts.Page, opts.PageSize)
func (g *GithubDownloaderV3) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
comments, err := g.getComments(commentable)
return comments, false, err
}

func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*base.Comment, error) {
func (g *GithubDownloaderV3) getComments(commentable base.Commentable) ([]*base.Comment, error) {
var (
allComments = make([]*base.Comment, 0, g.maxPerPage)
created = "created"
Expand All @@ -498,7 +494,7 @@ func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*bas
}
for {
g.waitAndPickClient()
comments, resp, err := g.getClient().Issues.ListComments(g.ctx, g.repoOwner, g.repoName, int(issueContext.ForeignID()), opt)
comments, resp, err := g.getClient().Issues.ListComments(g.ctx, g.repoOwner, g.repoName, int(commentable.GetForeignIndex()), opt)
if err != nil {
return nil, fmt.Errorf("error while listing repos: %v", err)
}
Expand Down Expand Up @@ -531,7 +527,7 @@ func (g *GithubDownloaderV3) getComments(issueContext base.IssueContext) ([]*bas
}

allComments = append(allComments, &base.Comment{
IssueIndex: issueContext.LocalID(),
IssueIndex: commentable.GetLocalIndex(),
Index: comment.GetID(),
PosterID: comment.GetUser().GetID(),
PosterName: comment.GetUser().GetLogin(),
Expand Down Expand Up @@ -709,9 +705,9 @@ func (g *GithubDownloaderV3) GetPullRequests(page, perPage int) ([]*base.PullReq
RepoName: pr.GetBase().GetRepo().GetName(),
OwnerName: pr.GetBase().GetUser().GetLogin(),
},
PatchURL: pr.GetPatchURL(),
Reactions: reactions,
Context: base.BasicIssueContext(*pr.Number),
PatchURL: pr.GetPatchURL(),
Reactions: reactions,
ForeignIndex: int64(*pr.Number),
})
}

Expand Down Expand Up @@ -777,28 +773,28 @@ func (g *GithubDownloaderV3) convertGithubReviewComments(cs []*github.PullReques
}

// GetReviews returns pull requests review
func (g *GithubDownloaderV3) GetReviews(context base.IssueContext) ([]*base.Review, error) {
func (g *GithubDownloaderV3) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
allReviews := make([]*base.Review, 0, g.maxPerPage)
opt := &github.ListOptions{
PerPage: g.maxPerPage,
}
for {
g.waitAndPickClient()
reviews, resp, err := g.getClient().PullRequests.ListReviews(g.ctx, g.repoOwner, g.repoName, int(context.ForeignID()), opt)
reviews, resp, err := g.getClient().PullRequests.ListReviews(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), opt)
if err != nil {
return nil, fmt.Errorf("error while listing repos: %v", err)
}
g.setRate(&resp.Rate)
for _, review := range reviews {
r := convertGithubReview(review)
r.IssueIndex = context.LocalID()
r.IssueIndex = reviewable.GetLocalIndex()
// retrieve all review comments
opt2 := &github.ListOptions{
PerPage: g.maxPerPage,
}
for {
g.waitAndPickClient()
reviewComments, resp, err := g.getClient().PullRequests.ListReviewComments(g.ctx, g.repoOwner, g.repoName, int(context.ForeignID()), review.GetID(), opt2)
reviewComments, resp, err := g.getClient().PullRequests.ListReviewComments(g.ctx, g.repoOwner, g.repoName, int(reviewable.GetForeignIndex()), review.GetID(), opt2)
if err != nil {
return nil, fmt.Errorf("error while listing repos: %v", err)
}
Expand Down
12 changes: 5 additions & 7 deletions services/migrations/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
}, issues)

// downloader.GetComments()
comments, _, err := downloader.GetComments(base.GetCommentOptions{
Context: base.BasicIssueContext(2),
})
comments, _, err := downloader.GetComments(&base.Issue{Number: 2, ForeignIndex: 2})
assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{
{
Expand Down Expand Up @@ -286,7 +284,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
Merged: true,
MergedTime: timePtr(time.Date(2019, 11, 12, 21, 39, 27, 0, time.UTC)),
MergeCommitSHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
Context: base.BasicIssueContext(3),
ForeignIndex: 3,
},
{
Number: 4,
Expand Down Expand Up @@ -333,11 +331,11 @@ func TestGitHubDownloadRepo(t *testing.T) {
Content: "+1",
},
},
Context: base.BasicIssueContext(4),
ForeignIndex: 4,
},
}, prs)

reviews, err := downloader.GetReviews(base.BasicIssueContext(3))
reviews, err := downloader.GetReviews(&base.PullRequest{Number: 3, ForeignIndex: 3})
assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{
{
Expand Down Expand Up @@ -369,7 +367,7 @@ func TestGitHubDownloadRepo(t *testing.T) {
},
}, reviews)

reviews, err = downloader.GetReviews(base.BasicIssueContext(4))
reviews, err = downloader.GetReviews(&base.PullRequest{Number: 4, ForeignIndex: 4})
assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{
{
Expand Down
72 changes: 28 additions & 44 deletions services/migrations/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,9 @@ func (g *GitlabDownloader) GetReleases() ([]*base.Release, error) {
}

type gitlabIssueContext struct {
foreignID int64
localID int64
IsMergeRequest bool
}

func (c gitlabIssueContext) LocalID() int64 {
return c.localID
}

func (c gitlabIssueContext) ForeignID() int64 {
return c.foreignID
}

// GetIssues returns issues according start and limit
// Note: issue label description and colors are not supported by the go-gitlab library at this time
func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, error) {
Expand Down Expand Up @@ -421,24 +411,21 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
}

allIssues = append(allIssues, &base.Issue{
Title: issue.Title,
Number: int64(issue.IID),
PosterID: int64(issue.Author.ID),
PosterName: issue.Author.Username,
Content: issue.Description,
Milestone: milestone,
State: issue.State,
Created: *issue.CreatedAt,
Labels: labels,
Reactions: reactions,
Closed: issue.ClosedAt,
IsLocked: issue.DiscussionLocked,
Updated: *issue.UpdatedAt,
Context: gitlabIssueContext{
foreignID: int64(issue.IID),
localID: int64(issue.IID),
IsMergeRequest: false,
},
Title: issue.Title,
Number: int64(issue.IID),
PosterID: int64(issue.Author.ID),
PosterName: issue.Author.Username,
Content: issue.Description,
Milestone: milestone,
State: issue.State,
Created: *issue.CreatedAt,
Labels: labels,
Reactions: reactions,
Closed: issue.ClosedAt,
IsLocked: issue.DiscussionLocked,
Updated: *issue.UpdatedAt,
ForeignIndex: int64(issue.IID),
Context: gitlabIssueContext{IsMergeRequest: false},
})

// increment issueCount, to be used in GetPullRequests()
Expand All @@ -450,10 +437,10 @@ func (g *GitlabDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er

// GetComments returns comments according issueNumber
// TODO: figure out how to transfer comment reactions
func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
context, ok := opts.Context.(gitlabIssueContext)
func (g *GitlabDownloader) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
context, ok := commentable.GetContext().(gitlabIssueContext)
if !ok {
return nil, false, fmt.Errorf("unexpected context: %+v", opts.Context)
return nil, false, fmt.Errorf("unexpected context: %+v", commentable.GetContext())
}

allComments := make([]*base.Comment, 0, g.maxPerPage)
Expand All @@ -465,12 +452,12 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
var resp *gitlab.Response
var err error
if !context.IsMergeRequest {
comments, resp, err = g.client.Discussions.ListIssueDiscussions(g.repoID, int(context.ForeignID()), &gitlab.ListIssueDiscussionsOptions{
comments, resp, err = g.client.Discussions.ListIssueDiscussions(g.repoID, int(commentable.GetForeignIndex()), &gitlab.ListIssueDiscussionsOptions{
Page: page,
PerPage: g.maxPerPage,
}, nil, gitlab.WithContext(g.ctx))
} else {
comments, resp, err = g.client.Discussions.ListMergeRequestDiscussions(g.repoID, int(context.ForeignID()), &gitlab.ListMergeRequestDiscussionsOptions{
comments, resp, err = g.client.Discussions.ListMergeRequestDiscussions(g.repoID, int(commentable.GetForeignIndex()), &gitlab.ListMergeRequestDiscussionsOptions{
Page: page,
PerPage: g.maxPerPage,
}, nil, gitlab.WithContext(g.ctx))
Expand All @@ -484,7 +471,7 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
if !comment.IndividualNote {
for _, note := range comment.Notes {
allComments = append(allComments, &base.Comment{
IssueIndex: context.LocalID(),
IssueIndex: commentable.GetLocalIndex(),
Index: int64(note.ID),
PosterID: int64(note.Author.ID),
PosterName: note.Author.Username,
Expand All @@ -496,7 +483,7 @@ func (g *GitlabDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
} else {
c := comment.Notes[0]
allComments = append(allComments, &base.Comment{
IssueIndex: context.LocalID(),
IssueIndex: commentable.GetLocalIndex(),
Index: int64(c.ID),
PosterID: int64(c.Author.ID),
PosterName: c.Author.Username,
Expand Down Expand Up @@ -619,21 +606,18 @@ func (g *GitlabDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
RepoName: g.repoName,
OwnerName: pr.Author.Username,
},
PatchURL: pr.WebURL + ".patch",
Context: gitlabIssueContext{
foreignID: int64(pr.IID),
localID: newPRNumber,
IsMergeRequest: true,
},
PatchURL: pr.WebURL + ".patch",
ForeignIndex: int64(pr.IID),
Context: gitlabIssueContext{IsMergeRequest: true},
})
}

return allPRs, len(prs) < perPage, nil
}

// GetReviews returns pull requests review
func (g *GitlabDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) {
approvals, resp, err := g.client.MergeRequestApprovals.GetConfiguration(g.repoID, int(context.ForeignID()), gitlab.WithContext(g.ctx))
func (g *GitlabDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
approvals, resp, err := g.client.MergeRequestApprovals.GetConfiguration(g.repoID, int(reviewable.GetForeignIndex()), gitlab.WithContext(g.ctx))
if err != nil {
if resp != nil && resp.StatusCode == 404 {
log.Error(fmt.Sprintf("GitlabDownloader: while migrating a error occurred: '%s'", err.Error()))
Expand All @@ -654,7 +638,7 @@ func (g *GitlabDownloader) GetReviews(context base.IssueContext) ([]*base.Review
reviews := make([]*base.Review, 0, len(approvals.ApprovedBy))
for _, user := range approvals.ApprovedBy {
reviews = append(reviews, &base.Review{
IssueIndex: context.LocalID(),
IssueIndex: reviewable.GetLocalIndex(),
ReviewerID: int64(user.User.ID),
ReviewerName: user.User.Username,
CreatedAt: createdAt,
Expand Down
24 changes: 10 additions & 14 deletions services/migrations/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,10 @@ func TestGitlabDownloadRepo(t *testing.T) {
},
}, issues)

comments, _, err := downloader.GetComments(base.GetCommentOptions{
Context: gitlabIssueContext{
foreignID: 2,
localID: 2,
IsMergeRequest: false,
},
comments, _, err := downloader.GetComments(&base.Issue{
Number: 2,
ForeignIndex: 2,
Context: gitlabIssueContext{IsMergeRequest: false},
})
assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{
Expand Down Expand Up @@ -301,15 +299,12 @@ func TestGitlabDownloadRepo(t *testing.T) {
Merged: false,
MergedTime: nil,
MergeCommitSHA: "",
Context: gitlabIssueContext{
foreignID: 2,
localID: 4,
IsMergeRequest: true,
},
ForeignIndex: 2,
Context: gitlabIssueContext{IsMergeRequest: true},
},
}, prs)

rvs, err := downloader.GetReviews(base.BasicIssueContext(1))
rvs, err := downloader.GetReviews(&base.PullRequest{Number: 1, ForeignIndex: 1})
assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{
{
Expand All @@ -328,7 +323,7 @@ func TestGitlabDownloadRepo(t *testing.T) {
},
}, rvs)

rvs, err = downloader.GetReviews(base.BasicIssueContext(2))
rvs, err = downloader.GetReviews(&base.PullRequest{Number: 2, ForeignIndex: 2})
assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{
{
Expand Down Expand Up @@ -469,7 +464,8 @@ func TestGitlabGetReviews(t *testing.T) {
mock, review := convertTestCase(testCase)
mux.HandleFunc(fmt.Sprintf("/api/v4/projects/%d/merge_requests/%d/approvals", testCase.repoID, testCase.prID), mock)

rvs, err := downloader.GetReviews(base.BasicIssueContext(testCase.prID))
id := int64(testCase.prID)
rvs, err := downloader.GetReviews(&base.Issue{Number: id, ForeignIndex: id})
assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{&review}, rvs)
}
Expand Down
32 changes: 16 additions & 16 deletions services/migrations/gogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ func (g *GogsDownloader) getIssues(page int, state string) ([]*base.Issue, bool,
}

// GetComments returns comments according issueNumber
func (g *GogsDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
func (g *GogsDownloader) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
allComments := make([]*base.Comment, 0, 100)

comments, err := g.client.ListIssueComments(g.repoOwner, g.repoName, opts.Context.ForeignID())
comments, err := g.client.ListIssueComments(g.repoOwner, g.repoName, commentable.GetForeignIndex())
if err != nil {
return nil, false, fmt.Errorf("error while listing repos: %v", err)
}
Expand All @@ -235,7 +235,7 @@ func (g *GogsDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comme
continue
}
allComments = append(allComments, &base.Comment{
IssueIndex: opts.Context.LocalID(),
IssueIndex: commentable.GetLocalIndex(),
Index: comment.ID,
PosterID: comment.Poster.ID,
PosterName: comment.Poster.Login,
Expand Down Expand Up @@ -288,19 +288,19 @@ func convertGogsIssue(issue *gogs.Issue) *base.Issue {
}

return &base.Issue{
Title: issue.Title,
Number: issue.Index,
PosterID: issue.Poster.ID,
PosterName: issue.Poster.Login,
PosterEmail: issue.Poster.Email,
Content: issue.Body,
Milestone: milestone,
State: string(issue.State),
Created: issue.Created,
Updated: issue.Updated,
Labels: labels,
Closed: closed,
Context: base.BasicIssueContext(issue.Index),
Title: issue.Title,
Number: issue.Index,
PosterID: issue.Poster.ID,
PosterName: issue.Poster.Login,
PosterEmail: issue.Poster.Email,
Content: issue.Body,
Milestone: milestone,
State: string(issue.State),
Created: issue.Created,
Updated: issue.Updated,
Labels: labels,
Closed: closed,
ForeignIndex: issue.Index,
}
}

Expand Down
4 changes: 1 addition & 3 deletions services/migrations/gogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ func TestGogsDownloadRepo(t *testing.T) {
}, issues)

// downloader.GetComments()
comments, _, err := downloader.GetComments(base.GetCommentOptions{
Context: base.BasicIssueContext(1),
})
comments, _, err := downloader.GetComments(&base.Issue{Number: 1, ForeignIndex: 1})
assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{
{
Expand Down
15 changes: 4 additions & 11 deletions services/migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
allComments := make([]*base.Comment, 0, commentBatchSize)
for _, issue := range issues {
log.Trace("migrating issue %d's comments", issue.Number)
comments, _, err := downloader.GetComments(base.GetCommentOptions{
Context: issue.Context,
})
comments, _, err := downloader.GetComments(issue)
if err != nil {
if !base.IsErrNotSupported(err) {
return err
Expand Down Expand Up @@ -383,9 +381,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
allComments := make([]*base.Comment, 0, commentBatchSize)
for _, pr := range prs {
log.Trace("migrating pull request %d's comments", pr.Number)
comments, _, err := downloader.GetComments(base.GetCommentOptions{
Context: pr.Context,
})
comments, _, err := downloader.GetComments(pr)
if err != nil {
if !base.IsErrNotSupported(err) {
return err
Expand All @@ -412,7 +408,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
// migrate reviews
allReviews := make([]*base.Review, 0, reviewBatchSize)
for _, pr := range prs {
reviews, err := downloader.GetReviews(pr.Context)
reviews, err := downloader.GetReviews(pr)
if err != nil {
if !base.IsErrNotSupported(err) {
return err
Expand Down Expand Up @@ -446,10 +442,7 @@ func migrateRepository(downloader base.Downloader, uploader base.Uploader, opts
if opts.Comments && supportAllComments {
log.Trace("migrating comments")
for i := 1; ; i++ {
comments, isEnd, err := downloader.GetComments(base.GetCommentOptions{
Page: i,
PageSize: commentBatchSize,
})
comments, isEnd, err := downloader.GetAllComments(i, commentBatchSize)
if err != nil {
return err
}
Expand Down
68 changes: 26 additions & 42 deletions services/migrations/onedev.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,9 @@ func (d *OneDevDownloader) GetLabels() ([]*base.Label, error) {
}

type onedevIssueContext struct {
foreignID int64
localID int64
IsPullRequest bool
}

func (c onedevIssueContext) LocalID() int64 {
return c.localID
}

func (c onedevIssueContext) ForeignID() int64 {
return c.foreignID
}

// GetIssues returns issues
func (d *OneDevDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, error) {
rawIssues := make([]struct {
Expand Down Expand Up @@ -346,21 +336,18 @@ func (d *OneDevDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
}
poster := d.tryGetUser(issue.SubmitterID)
issues = append(issues, &base.Issue{
Title: issue.Title,
Number: issue.Number,
PosterName: poster.Name,
PosterEmail: poster.Email,
Content: issue.Description,
Milestone: d.milestoneMap[milestoneID],
State: state,
Created: issue.SubmitDate,
Updated: issue.SubmitDate,
Labels: []*base.Label{label},
Context: onedevIssueContext{
foreignID: issue.ID,
localID: issue.Number,
IsPullRequest: false,
},
Title: issue.Title,
Number: issue.Number,
PosterName: poster.Name,
PosterEmail: poster.Email,
Content: issue.Description,
Milestone: d.milestoneMap[milestoneID],
State: state,
Created: issue.SubmitDate,
Updated: issue.SubmitDate,
Labels: []*base.Label{label},
ForeignIndex: issue.ID,
Context: onedevIssueContext{IsPullRequest: false},
})

if d.maxIssueIndex < issue.Number {
Expand All @@ -372,10 +359,10 @@ func (d *OneDevDownloader) GetIssues(page, perPage int) ([]*base.Issue, bool, er
}

// GetComments returns comments
func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
context, ok := opts.Context.(onedevIssueContext)
func (d *OneDevDownloader) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
context, ok := commentable.GetContext().(onedevIssueContext)
if !ok {
return nil, false, fmt.Errorf("unexpected comment context: %+v", opts.Context)
return nil, false, fmt.Errorf("unexpected context: %+v", commentable.GetContext())
}

rawComments := make([]struct {
Expand All @@ -387,9 +374,9 @@ func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com

var endpoint string
if context.IsPullRequest {
endpoint = fmt.Sprintf("/api/pull-requests/%d/comments", context.ForeignID())
endpoint = fmt.Sprintf("/api/pull-requests/%d/comments", commentable.GetForeignIndex())
} else {
endpoint = fmt.Sprintf("/api/issues/%d/comments", context.ForeignID())
endpoint = fmt.Sprintf("/api/issues/%d/comments", commentable.GetForeignIndex())
}

err := d.callAPI(
Expand All @@ -408,9 +395,9 @@ func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
}, 0, 100)

if context.IsPullRequest {
endpoint = fmt.Sprintf("/api/pull-requests/%d/changes", context.ForeignID())
endpoint = fmt.Sprintf("/api/pull-requests/%d/changes", commentable.GetForeignIndex())
} else {
endpoint = fmt.Sprintf("/api/issues/%d/changes", context.ForeignID())
endpoint = fmt.Sprintf("/api/issues/%d/changes", commentable.GetForeignIndex())
}

err = d.callAPI(
Expand All @@ -429,7 +416,7 @@ func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com
}
poster := d.tryGetUser(comment.UserID)
comments = append(comments, &base.Comment{
IssueIndex: context.LocalID(),
IssueIndex: commentable.GetLocalIndex(),
Index: comment.ID,
PosterID: poster.ID,
PosterName: poster.Name,
Expand All @@ -454,7 +441,7 @@ func (d *OneDevDownloader) GetComments(opts base.GetCommentOptions) ([]*base.Com

poster := d.tryGetUser(change.UserID)
comments = append(comments, &base.Comment{
IssueIndex: context.LocalID(),
IssueIndex: commentable.GetLocalIndex(),
PosterID: poster.ID,
PosterName: poster.Name,
PosterEmail: poster.Email,
Expand Down Expand Up @@ -552,19 +539,16 @@ func (d *OneDevDownloader) GetPullRequests(page, perPage int) ([]*base.PullReque
SHA: mergePreview.TargetHeadCommitHash,
RepoName: d.repoName,
},
Context: onedevIssueContext{
foreignID: pr.ID,
localID: number,
IsPullRequest: true,
},
ForeignIndex: pr.ID,
Context: onedevIssueContext{IsPullRequest: true},
})
}

return pullRequests, len(pullRequests) == 0, nil
}

// GetReviews returns pull requests reviews
func (d *OneDevDownloader) GetReviews(context base.IssueContext) ([]*base.Review, error) {
func (d *OneDevDownloader) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
rawReviews := make([]struct {
ID int64 `json:"id"`
UserID int64 `json:"userId"`
Expand All @@ -576,7 +560,7 @@ func (d *OneDevDownloader) GetReviews(context base.IssueContext) ([]*base.Review
}, 0, 100)

err := d.callAPI(
fmt.Sprintf("/api/pull-requests/%d/reviews", context.ForeignID()),
fmt.Sprintf("/api/pull-requests/%d/reviews", reviewable.GetForeignIndex()),
nil,
&rawReviews,
)
Expand All @@ -600,7 +584,7 @@ func (d *OneDevDownloader) GetReviews(context base.IssueContext) ([]*base.Review

poster := d.tryGetUser(review.UserID)
reviews = append(reviews, &base.Review{
IssueIndex: context.LocalID(),
IssueIndex: reviewable.GetLocalIndex(),
ReviewerID: poster.ID,
ReviewerName: poster.Name,
Content: content,
Expand Down
36 changes: 11 additions & 25 deletions services/migrations/onedev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ func TestOneDevDownloadRepo(t *testing.T) {
Name: "Improvement",
},
},
Context: onedevIssueContext{
foreignID: 398,
localID: 4,
IsPullRequest: false,
},
ForeignIndex: 398,
Context: onedevIssueContext{IsPullRequest: false},
},
{
Number: 3,
Expand All @@ -94,20 +91,15 @@ func TestOneDevDownloadRepo(t *testing.T) {
Name: "New Feature",
},
},
Context: onedevIssueContext{
foreignID: 397,
localID: 3,
IsPullRequest: false,
},
ForeignIndex: 397,
Context: onedevIssueContext{IsPullRequest: false},
},
}, issues)

comments, _, err := downloader.GetComments(base.GetCommentOptions{
Context: onedevIssueContext{
foreignID: 398,
localID: 4,
IsPullRequest: false,
},
comments, _, err := downloader.GetComments(&base.Issue{
Number: 4,
ForeignIndex: 398,
Context: onedevIssueContext{IsPullRequest: false},
})
assert.NoError(t, err)
assertCommentsEqual(t, []*base.Comment{
Expand Down Expand Up @@ -141,18 +133,12 @@ func TestOneDevDownloadRepo(t *testing.T) {
SHA: "f32b0a9dfd09a60f616f29158f772cedd89942d2",
RepoName: "go-gitea-test_repo",
},
Context: onedevIssueContext{
foreignID: 186,
localID: 5,
IsPullRequest: true,
},
ForeignIndex: 186,
Context: onedevIssueContext{IsPullRequest: true},
},
}, prs)

rvs, err := downloader.GetReviews(onedevIssueContext{
foreignID: 186,
localID: 5,
})
rvs, err := downloader.GetReviews(&base.PullRequest{Number: 5, ForeignIndex: 186})
assert.NoError(t, err)
assertReviewsEqual(t, []*base.Review{
{
Expand Down
13 changes: 4 additions & 9 deletions services/migrations/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,17 +193,13 @@ func (r *RepositoryRestorer) GetIssues(page, perPage int) ([]*base.Issue, bool,
}
return nil, false, err
}

for _, issue := range issues {
issue.Context = base.BasicIssueContext(issue.Number)
}
return issues, true, nil
}

// GetComments returns comments according issueNumber
func (r *RepositoryRestorer) GetComments(opts base.GetCommentOptions) ([]*base.Comment, bool, error) {
func (r *RepositoryRestorer) GetComments(commentable base.Commentable) ([]*base.Comment, bool, error) {
comments := make([]*base.Comment, 0, 10)
p := filepath.Join(r.commentDir(), fmt.Sprintf("%d.yml", opts.Context.ForeignID()))
p := filepath.Join(r.commentDir(), fmt.Sprintf("%d.yml", commentable.GetForeignIndex()))
_, err := os.Stat(p)
if err != nil {
if os.IsNotExist(err) {
Expand Down Expand Up @@ -247,15 +243,14 @@ func (r *RepositoryRestorer) GetPullRequests(page, perPage int) ([]*base.PullReq
}
for _, pr := range pulls {
pr.PatchURL = "file://" + filepath.Join(r.baseDir, pr.PatchURL)
pr.Context = base.BasicIssueContext(pr.Number)
}
return pulls, true, nil
}

// GetReviews returns pull requests review
func (r *RepositoryRestorer) GetReviews(context base.IssueContext) ([]*base.Review, error) {
func (r *RepositoryRestorer) GetReviews(reviewable base.Reviewable) ([]*base.Review, error) {
reviews := make([]*base.Review, 0, 10)
p := filepath.Join(r.reviewDir(), fmt.Sprintf("%d.yml", context.ForeignID()))
p := filepath.Join(r.reviewDir(), fmt.Sprintf("%d.yml", reviewable.GetForeignIndex()))
_, err := os.Stat(p)
if err != nil {
if os.IsNotExist(err) {
Expand Down