mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-29 22:25:59 +00:00
Fix migration failing when importing either issues or PRs but not the other (#8892)
Related to https://codeberg.org/Codeberg/Community/issues/1944 * Allowed the githubdownloaderv3 to know whether issues and, or PRs are requested to migrate * Used this information to decide to filter for "/pulls/" or "/issues" * Or not to filter at all if issues == true && prs == true * Added isolated test for the downloader and for the uploader * Created a new test_repo in github.com/forgejo and set it up properly together with @Gusted * Updated github_downloader_test with the new URLs and test data from the repo * Recorded the API calls for local testing * Added a minimal gitbucket test (which uses the github downloader under the hood) Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8892 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: patdyn <patdyn@noreply.codeberg.org> Co-committed-by: patdyn <patdyn@noreply.codeberg.org>
This commit is contained in:
parent
ed3b70cbb9
commit
9a423c0e67
70 changed files with 966 additions and 980 deletions
|
@ -57,7 +57,7 @@ func (f *GithubDownloaderV3Factory) New(ctx context.Context, opts base.MigrateOp
|
|||
|
||||
log.Trace("Create github downloader BaseURL: %s %s/%s", baseURL, oldOwner, oldName)
|
||||
|
||||
return NewGithubDownloaderV3(ctx, baseURL, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, oldOwner, oldName), nil
|
||||
return NewGithubDownloaderV3(ctx, baseURL, opts.PullRequests, opts.Issues, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, oldOwner, oldName), nil
|
||||
}
|
||||
|
||||
// GitServiceType returns the type of git service
|
||||
|
@ -69,30 +69,34 @@ func (f *GithubDownloaderV3Factory) GitServiceType() structs.GitServiceType {
|
|||
// from github via APIv3
|
||||
type GithubDownloaderV3 struct {
|
||||
base.NullDownloader
|
||||
ctx context.Context
|
||||
clients []*github.Client
|
||||
baseURL string
|
||||
repoOwner string
|
||||
repoName string
|
||||
userName string
|
||||
password string
|
||||
rates []*github.Rate
|
||||
curClientIdx int
|
||||
maxPerPage int
|
||||
SkipReactions bool
|
||||
SkipReviews bool
|
||||
ctx context.Context
|
||||
clients []*github.Client
|
||||
baseURL string
|
||||
repoOwner string
|
||||
repoName string
|
||||
userName string
|
||||
password string
|
||||
getPullRequests bool
|
||||
getIssues bool
|
||||
rates []*github.Rate
|
||||
curClientIdx int
|
||||
maxPerPage int
|
||||
SkipReactions bool
|
||||
SkipReviews bool
|
||||
}
|
||||
|
||||
// NewGithubDownloaderV3 creates a github Downloader via github v3 API
|
||||
func NewGithubDownloaderV3(ctx context.Context, baseURL, userName, password, token, repoOwner, repoName string) *GithubDownloaderV3 {
|
||||
func NewGithubDownloaderV3(ctx context.Context, baseURL string, getPullRequests, getIssues bool, userName, password, token, repoOwner, repoName string) *GithubDownloaderV3 {
|
||||
downloader := GithubDownloaderV3{
|
||||
userName: userName,
|
||||
baseURL: baseURL,
|
||||
password: password,
|
||||
ctx: ctx,
|
||||
repoOwner: repoOwner,
|
||||
repoName: repoName,
|
||||
maxPerPage: 100,
|
||||
userName: userName,
|
||||
baseURL: baseURL,
|
||||
password: password,
|
||||
ctx: ctx,
|
||||
repoOwner: repoOwner,
|
||||
repoName: repoName,
|
||||
maxPerPage: 100,
|
||||
getPullRequests: getPullRequests,
|
||||
getIssues: getIssues,
|
||||
}
|
||||
|
||||
if token != "" {
|
||||
|
@ -582,6 +586,24 @@ func (g *GithubDownloaderV3) getComments(commentable base.Commentable) ([]*base.
|
|||
return allComments, nil
|
||||
}
|
||||
|
||||
func (g *GithubDownloaderV3) filterByHTMLURL(comments []*github.IssueComment, filterBy string) []*github.IssueComment {
|
||||
var result []*github.IssueComment
|
||||
for _, val := range comments {
|
||||
if !strings.Contains(*val.HTMLURL, filterBy) {
|
||||
result = append(result, val)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func (g *GithubDownloaderV3) filterPRComments(comments []*github.IssueComment) []*github.IssueComment {
|
||||
return g.filterByHTMLURL(comments, "/pull/")
|
||||
}
|
||||
|
||||
func (g *GithubDownloaderV3) filterIssueComments(comments []*github.IssueComment) []*github.IssueComment {
|
||||
return g.filterByHTMLURL(comments, "/issues/")
|
||||
}
|
||||
|
||||
// GetAllComments returns repository comments according page and perPageSize
|
||||
func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment, bool, error) {
|
||||
var (
|
||||
|
@ -608,6 +630,12 @@ func (g *GithubDownloaderV3) GetAllComments(page, perPage int) ([]*base.Comment,
|
|||
}
|
||||
isEnd := resp.NextPage == 0
|
||||
|
||||
if g.getIssues && !g.getPullRequests {
|
||||
comments = g.filterPRComments(comments)
|
||||
} else if !g.getIssues && g.getPullRequests {
|
||||
comments = g.filterIssueComments(comments)
|
||||
}
|
||||
|
||||
log.Trace("Request get comments %d/%d, but in fact get %d, next page is %d", perPage, page, len(comments), resp.NextPage)
|
||||
g.setRate(&resp.Rate)
|
||||
for _, comment := range comments {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue