Skip to content

Commit 49b1948

Browse files
authored
Gitea 2 Gitea migration (#12657)
* first draft * update gitea sdk to 9e280adb4da * adapt feat of updated sdk * releases now works * break the Reactions loop * use convertGiteaLabel * fix endless loop because paggination is not supported there !!! * rename gitea local uploader files * pagination can bite you in the ass * Version Checks * lint * docs * rename gitea sdk import to miss future conficts * go-swagger: dont scan the sdk structs * make sure gitea can shutdown gracefully * make GetPullRequests and GetIssues similar * rm useles * Add Test: started ... * ... add tests ... * Add tests and Fixing things * Workaround missing SHA * Adapt: Ensure that all migration requests are cancellable (714ab71) * LINT: fix misspells in test set * adapt ListMergeRequestAwardEmoji * update sdk * Return error when creating giteadownloader failed * update sdk * adapt new sdk * adopt new features * check version before err * adapt: 'migrate service type switch page' * optimize * Fix DefaultBranch * impruve * handle subPath * fix test * Fix ReviewCommentPosition * test GetReviews * add DefaultBranch int test set * rm unused * Update SDK to v0.13.0 * addopt sdk changes * found better link * format template * Update Docs * Update Gitea SDK (v0.13.1)
1 parent dfa7291 commit 49b1948

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+6885
-82
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,12 @@ endif
120120

121121
GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES))
122122

123-
#To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.20.1
123+
#To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger
124124
SWAGGER := $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
125125
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
126126
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
127127
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
128+
SWAGGER_EXCLUDE := code.gitea.io/sdk
128129
SWAGGER_NEWLINE_COMMAND := -e '$$a\'
129130

130131
TEST_MYSQL_HOST ?= mysql:3306
@@ -243,7 +244,7 @@ endif
243244

244245
.PHONY: generate-swagger
245246
generate-swagger:
246-
$(SWAGGER) generate spec -o './$(SWAGGER_SPEC)'
247+
$(SWAGGER) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
247248
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
248249
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
249250

docs/content/doc/advanced/migrations.en-us.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ menu:
1717

1818
The new migration features were introduced in Gitea 1.9.0. It defines two interfaces to support migrating
1919
repositories data from other git host platforms to gitea or, in the future migrating gitea data to other
20-
git host platforms. Currently, only the migrations from github via APIv3 to Gitea is implemented.
20+
git host platforms. Currently, migrations from Github, Gitlab and Gitea to Gitea is implemented.
2121

2222
First of all, Gitea defines some standard objects in packages `modules/migrations/base`. They are
23-
`Repository`, `Milestone`, `Release`, `Label`, `Issue`, `Comment`, `PullRequest`, `Reaction`, `Review`, `ReviewComment`.
23+
`Repository`, `Milestone`, `Release`, `ReleaseAsset`, `Label`, `Issue`, `Comment`, `PullRequest`, `Reaction`, `Review`, `ReviewComment`.
2424

2525
## Downloader Interfaces
2626

@@ -33,6 +33,7 @@ create a Downloader.
3333

3434
```Go
3535
type Downloader interface {
36+
GetAsset(relTag string, relID, id int64) (io.ReadCloser, error)
3637
SetContext(context.Context)
3738
GetRepoInfo() (*Repository, error)
3839
GetTopics() ([]string, error)
@@ -41,15 +42,15 @@ type Downloader interface {
4142
GetLabels() ([]*Label, error)
4243
GetIssues(page, perPage int) ([]*Issue, bool, error)
4344
GetComments(issueNumber int64) ([]*Comment, error)
44-
GetPullRequests(page, perPage int) ([]*PullRequest, error)
45+
GetPullRequests(page, perPage int) ([]*PullRequest, bool, error)
4546
GetReviews(pullRequestNumber int64) ([]*Review, error)
4647
}
4748
```
4849

4950
```Go
5051
type DownloaderFactory interface {
51-
Match(opts MigrateOptions) (bool, error)
52-
New(opts MigrateOptions) (Downloader, error)
52+
New(ctx context.Context, opts MigrateOptions) (Downloader, error)
53+
GitServiceType() structs.GitServiceType
5354
}
5455
```
5556

@@ -66,7 +67,7 @@ type Uploader interface {
6667
CreateRepo(repo *Repository, opts MigrateOptions) error
6768
CreateTopics(topic ...string) error
6869
CreateMilestones(milestones ...*Milestone) error
69-
CreateReleases(releases ...*Release) error
70+
CreateReleases(downloader Downloader, releases ...*Release) error
7071
SyncTags() error
7172
CreateLabels(labels ...*Label) error
7273
CreateIssues(issues ...*Issue) error

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.14
44

55
require (
66
code.gitea.io/gitea-vet v0.2.1
7+
code.gitea.io/sdk/gitea v0.13.1
78
gitea.com/lunny/levelqueue v0.3.0
89
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
910
gitea.com/macaron/cache v0.0.0-20190822004001-a6e7fee4ee76
@@ -49,7 +50,7 @@ require (
4950
github.com/google/uuid v1.1.1
5051
github.com/gorilla/context v1.1.1
5152
github.com/hashicorp/go-retryablehttp v0.6.7 // indirect
52-
github.com/hashicorp/go-version v0.0.0-00010101000000-000000000000
53+
github.com/hashicorp/go-version v1.2.1
5354
github.com/huandu/xstrings v1.3.0
5455
github.com/issue9/assert v1.3.2 // indirect
5556
github.com/issue9/identicon v1.0.1

go.sum

Lines changed: 2 additions & 40 deletions
Large diffs are not rendered by default.

modules/migrations/base/downloader.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
// AssetDownloader downloads an asset (attachment) for a release
1717
type AssetDownloader interface {
18-
GetAsset(tag string, id int64) (io.ReadCloser, error)
18+
GetAsset(relTag string, relID, id int64) (io.ReadCloser, error)
1919
}
2020

2121
// Downloader downloads the site repo informations
@@ -29,7 +29,7 @@ type Downloader interface {
2929
GetLabels() ([]*Label, error)
3030
GetIssues(page, perPage int) ([]*Issue, bool, error)
3131
GetComments(issueNumber int64) ([]*Comment, error)
32-
GetPullRequests(page, perPage int) ([]*PullRequest, error)
32+
GetPullRequests(page, perPage int) ([]*PullRequest, bool, error)
3333
GetReviews(pullRequestNumber int64) ([]*Review, error)
3434
}
3535

@@ -209,23 +209,24 @@ func (d *RetryDownloader) GetComments(issueNumber int64) ([]*Comment, error) {
209209
}
210210

211211
// GetPullRequests returns a repository's pull requests with retry
212-
func (d *RetryDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, error) {
212+
func (d *RetryDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) {
213213
var (
214214
times = d.RetryTimes
215215
prs []*PullRequest
216216
err error
217+
isEnd bool
217218
)
218219
for ; times > 0; times-- {
219-
if prs, err = d.Downloader.GetPullRequests(page, perPage); err == nil {
220-
return prs, nil
220+
if prs, isEnd, err = d.Downloader.GetPullRequests(page, perPage); err == nil {
221+
return prs, isEnd, nil
221222
}
222223
select {
223224
case <-d.ctx.Done():
224-
return nil, d.ctx.Err()
225+
return nil, false, d.ctx.Err()
225226
case <-time.After(time.Second * time.Duration(d.RetryDelay)):
226227
}
227228
}
228-
return nil, err
229+
return nil, false, err
229230
}
230231

231232
// GetReviews returns pull requests reviews

modules/migrations/base/issue.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ type Issue struct {
2323
Closed *time.Time
2424
Labels []*Label
2525
Reactions []*Reaction
26+
Assignees []string
2627
}

modules/migrations/base/pullrequest.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type PullRequest struct {
3131
MergeCommitSHA string
3232
Head PullRequestBranch
3333
Base PullRequestBranch
34-
Assignee string
3534
Assignees []string
3635
IsLocked bool
3736
Reactions []*Reaction

modules/migrations/base/release.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type ReleaseAsset struct {
1515
DownloadCount *int
1616
Created time.Time
1717
Updated time.Time
18+
DownloadURL *string
1819
}
1920

2021
// Release represents a release

modules/migrations/base/repo.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ type Repository struct {
1212
IsPrivate bool
1313
IsMirror bool
1414
Description string
15-
AuthUsername string
16-
AuthPassword string
1715
CloneURL string
1816
OriginalURL string
1917
DefaultBranch string

modules/migrations/base/review.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type ReviewComment struct {
3636
TreePath string
3737
DiffHunk string
3838
Position int
39+
Line int
3940
CommitID string
4041
PosterID int64
4142
Reactions []*Reaction

modules/migrations/git.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func (g *PlainGitDownloader) GetReleases() ([]*base.Release, error) {
6666
}
6767

6868
// GetAsset returns an asset
69-
func (g *PlainGitDownloader) GetAsset(_ string, _ int64) (io.ReadCloser, error) {
69+
func (g *PlainGitDownloader) GetAsset(_ string, _, _ int64) (io.ReadCloser, error) {
7070
return nil, ErrNotSupported
7171
}
7272

@@ -81,8 +81,8 @@ func (g *PlainGitDownloader) GetComments(issueNumber int64) ([]*base.Comment, er
8181
}
8282

8383
// GetPullRequests returns pull requests according page and perPage
84-
func (g *PlainGitDownloader) GetPullRequests(start, limit int) ([]*base.PullRequest, error) {
85-
return nil, ErrNotSupported
84+
func (g *PlainGitDownloader) GetPullRequests(start, limit int) ([]*base.PullRequest, bool, error) {
85+
return nil, false, ErrNotSupported
8686
}
8787

8888
// GetReviews returns reviews according issue number

0 commit comments

Comments
 (0)