summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/migration/comment.go7
-rw-r--r--modules/migration/downloader.go15
-rw-r--r--modules/migration/issue.go58
-rw-r--r--modules/migration/null_downloader.go11
-rw-r--r--modules/migration/pullrequest.go7
-rw-r--r--modules/migration/retry_downloader.go8
-rw-r--r--modules/migration/review.go6
7 files changed, 59 insertions, 53 deletions
diff --git a/modules/migration/comment.go b/modules/migration/comment.go
index f364ffc93a..0447689b74 100644
--- a/modules/migration/comment.go
+++ b/modules/migration/comment.go
@@ -7,6 +7,13 @@ package migration
import "time"
+// Commentable can be commented upon
+type Commentable interface {
+ GetLocalIndex() int64
+ GetForeignIndex() int64
+ GetContext() DownloaderContext
+}
+
// Comment is a standard comment information
type Comment struct {
IssueIndex int64 `yaml:"issue_index"`
diff --git a/modules/migration/downloader.go b/modules/migration/downloader.go
index 90e149fb1a..7759c96056 100644
--- a/modules/migration/downloader.go
+++ b/modules/migration/downloader.go
@@ -11,13 +11,6 @@ import (
"code.gitea.io/gitea/modules/structs"
)
-// GetCommentOptions represents an options for get comment
-type GetCommentOptions struct {
- Context IssueContext
- Page int
- PageSize int
-}
-
// Downloader downloads the site repo information
type Downloader interface {
SetContext(context.Context)
@@ -27,10 +20,11 @@ type Downloader interface {
GetReleases() ([]*Release, error)
GetLabels() ([]*Label, error)
GetIssues(page, perPage int) ([]*Issue, bool, error)
- GetComments(opts GetCommentOptions) ([]*Comment, bool, error)
+ GetComments(commentable Commentable) ([]*Comment, bool, error)
+ GetAllComments(page, perPage int) ([]*Comment, bool, error)
SupportGetRepoComments() bool
GetPullRequests(page, perPage int) ([]*PullRequest, bool, error)
- GetReviews(pullRequestContext IssueContext) ([]*Review, error)
+ GetReviews(reviewable Reviewable) ([]*Review, error)
FormatCloneURL(opts MigrateOptions, remoteAddr string) (string, error)
}
@@ -39,3 +33,6 @@ type DownloaderFactory interface {
New(ctx context.Context, opts MigrateOptions) (Downloader, error)
GitServiceType() structs.GitServiceType
}
+
+// DownloaderContext has opaque information only relevant to a given downloader
+type DownloaderContext interface{}
diff --git a/modules/migration/issue.go b/modules/migration/issue.go
index 984f07d8c9..78f648dd2d 100644
--- a/modules/migration/issue.go
+++ b/modules/migration/issue.go
@@ -7,44 +7,26 @@ 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
@@ -52,3 +34,7 @@ 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 }
diff --git a/modules/migration/null_downloader.go b/modules/migration/null_downloader.go
index 6192870873..32da720f16 100644
--- a/modules/migration/null_downloader.go
+++ b/modules/migration/null_downloader.go
@@ -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"}
}
diff --git a/modules/migration/pullrequest.go b/modules/migration/pullrequest.go
index 7a681940a7..eaa0dd45e2 100644
--- a/modules/migration/pullrequest.go
+++ b/modules/migration/pullrequest.go
@@ -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()
diff --git a/modules/migration/retry_downloader.go b/modules/migration/retry_downloader.go
index 1095a26891..2e40c102be 100644
--- a/modules/migration/retry_downloader.go
+++ b/modules/migration/retry_downloader.go
@@ -148,7 +148,7 @@ 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
@@ -156,7 +156,7 @@ func (d *RetryDownloader) GetComments(opts GetCommentOptions) ([]*Comment, bool,
)
err = d.retry(func() error {
- comments, isEnd, err = d.Downloader.GetComments(opts)
+ comments, isEnd, err = d.Downloader.GetComments(commentable)
return err
})
@@ -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
})
diff --git a/modules/migration/review.go b/modules/migration/review.go
index 85795385e9..e4db33d98f 100644
--- a/modules/migration/review.go
+++ b/modules/migration/review.go
@@ -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"