forked from forgejo/forgejo
FIX gogs migration if gogs is hosted at a subpath (#3572)
Also add a test for GogsDownloaderFactory.New() to make sure that the URL of the source repository is parsed correctly. When the source gogs instance is hosted at a subpath like `https://git.example.com/gogs/<username>/<reponame>` the migration fails. This PR fixes that. Co-authored-by: hecker <tomas.hecker@gmail.com> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3572 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: varp0n <tom@gkstn.de> Co-committed-by: varp0n <tom@gkstn.de>
This commit is contained in:
parent
c6cc1430a9
commit
4a2959b3ec
3 changed files with 96 additions and 4 deletions
|
@ -38,17 +38,24 @@ func (f *GogsDownloaderFactory) New(ctx context.Context, opts base.MigrateOption
|
|||
return nil, err
|
||||
}
|
||||
|
||||
baseURL := u.Scheme + "://" + u.Host
|
||||
repoNameSpace := strings.TrimSuffix(u.Path, ".git")
|
||||
repoNameSpace = strings.Trim(repoNameSpace, "/")
|
||||
|
||||
fields := strings.Split(repoNameSpace, "/")
|
||||
if len(fields) < 2 {
|
||||
numFields := len(fields)
|
||||
if numFields < 2 {
|
||||
return nil, fmt.Errorf("invalid path: %s", repoNameSpace)
|
||||
}
|
||||
|
||||
log.Trace("Create gogs downloader. BaseURL: %s RepoOwner: %s RepoName: %s", baseURL, fields[0], fields[1])
|
||||
return NewGogsDownloader(ctx, baseURL, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, fields[0], fields[1]), nil
|
||||
repoOwner := fields[numFields-2]
|
||||
repoName := fields[numFields-1]
|
||||
|
||||
u.Path = ""
|
||||
u = u.JoinPath(fields[:numFields-2]...)
|
||||
baseURL := u.String()
|
||||
|
||||
log.Trace("Create gogs downloader. BaseURL: %s RepoOwner: %s RepoName: %s", baseURL, repoOwner, repoName)
|
||||
return NewGogsDownloader(ctx, baseURL, opts.AuthUsername, opts.AuthPassword, opts.AuthToken, repoOwner, repoName), nil
|
||||
}
|
||||
|
||||
// GitServiceType returns the type of git service
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue