Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gitea 2 Gitea migration #12657

Merged
merged 79 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
5571400
first draft
6543 Aug 31, 2020
6e20e94
update gitea sdk to 9e280adb4da
6543 Aug 31, 2020
08e5cb2
adapt feat of updated sdk
6543 Aug 31, 2020
70bcc39
releases now works
6543 Aug 31, 2020
9eb8395
break the Reactions loop
6543 Aug 31, 2020
3d0e606
use convertGiteaLabel
6543 Aug 31, 2020
a80d9d3
fix endless loop because paggination is not supported there !!!
6543 Aug 31, 2020
351c3fd
rename gitea local uploader files
6543 Aug 31, 2020
d457206
pagination can bite you in the ass
6543 Aug 31, 2020
5ca02fd
Version Checks
6543 Aug 31, 2020
2b57e5f
Merge branch 'master' into feature_gitea2gitea-migration
6543 Aug 31, 2020
da84e83
lint
6543 Aug 31, 2020
7da46b7
docs
6543 Aug 31, 2020
f792c3e
rename gitea sdk import to miss future conficts
6543 Aug 31, 2020
a7db7df
go-swagger: dont scan the sdk structs
6543 Aug 31, 2020
53462b9
make sure gitea can shutdown gracefully
6543 Aug 31, 2020
81f7723
make GetPullRequests and GetIssues similar
6543 Aug 31, 2020
47e7d16
rm useles
6543 Sep 1, 2020
97ea19e
Add Test: started ...
6543 Sep 1, 2020
1dbd30c
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 1, 2020
cfcaeef
... add tests ...
6543 Sep 1, 2020
7de2def
Add tests and Fixing things
6543 Sep 2, 2020
b46abd3
Workaround missing SHA
6543 Sep 2, 2020
33e8385
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 2, 2020
5738f74
Adapt: Ensure that all migration requests are cancellable
6543 Sep 2, 2020
b086983
LINT: fix misspells in test set
6543 Sep 2, 2020
5271c68
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 3, 2020
e4c8b70
adapt ListMergeRequestAwardEmoji
6543 Sep 3, 2020
411fb94
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 4, 2020
7ae2dae
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 8, 2020
0c460dc
update sdk
6543 Sep 8, 2020
bdd4722
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 9, 2020
47db16b
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 10, 2020
3ce4180
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 10, 2020
730b8e0
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 11, 2020
c24bd44
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 14, 2020
e868342
Return error when creating giteadownloader failed
6543 Sep 14, 2020
d36d10d
update sdk
6543 Sep 14, 2020
d1ff729
adapt new sdk
6543 Sep 14, 2020
ee34d41
adopt new features
6543 Sep 14, 2020
9001eeb
check version before err
6543 Sep 14, 2020
a26606f
adapt: 'migrate service type switch page'
6543 Sep 14, 2020
878df2c
optimize
6543 Sep 14, 2020
ddee989
Fix DefaultBranch
6543 Sep 14, 2020
17a8cc0
impruve
6543 Sep 14, 2020
dfd9fc2
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 14, 2020
b4b6ce3
handle subPath
6543 Sep 15, 2020
3dea64a
fix test
6543 Sep 15, 2020
599b8fe
Fix ReviewCommentPosition
6543 Sep 15, 2020
beb2c25
test GetReviews
6543 Sep 15, 2020
2b5c300
add DefaultBranch int test set
6543 Sep 15, 2020
5d4d3c8
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 15, 2020
c37e75b
rm unused
6543 Sep 15, 2020
c3511c9
Update SDK to v0.13.0
6543 Sep 15, 2020
180ef4a
addopt sdk changes
6543 Sep 15, 2020
1f808f4
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 18, 2020
8679be8
found better link
6543 Sep 18, 2020
5384ebf
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 19, 2020
8d1eb34
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 19, 2020
85ea709
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 20, 2020
dcd9726
format template
6543 Sep 20, 2020
b377a97
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 21, 2020
3e1aa54
Update Docs
6543 Sep 21, 2020
429fbb2
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 27, 2020
b83d440
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 28, 2020
0a0e10c
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 29, 2020
ada520b
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 29, 2020
228c20a
Update Gitea SDK (v0.13.1)
6543 Sep 29, 2020
4d10ea7
Merge branch 'master' into feature_gitea2gitea-migration
6543 Sep 30, 2020
4247636
Merge branch 'master' into feature_gitea2gitea-migration
6543 Oct 5, 2020
4bb422d
Merge branch 'master' into feature_gitea2gitea-migration
6543 Oct 6, 2020
b40ff14
Merge branch 'master' into feature_gitea2gitea-migration
6543 Oct 7, 2020
b37ea18
Merge branch 'master' into feature_gitea2gitea-migration
6543 Oct 10, 2020
e24dc81
Merge branch 'master' into feature_gitea2gitea-migration
6543 Oct 11, 2020
f5b43b8
Merge branch 'master' into feature_gitea2gitea-migration
6543 Oct 12, 2020
77b2362
Merge branch 'master' into feature_gitea2gitea-migration
6543 Oct 12, 2020
0cceb75
Merge branch 'master' into feature_gitea2gitea-migration
6543 Oct 13, 2020
545db8f
Merge branch 'master' into feature_gitea2gitea-migration
6543 Oct 13, 2020
ca99e59
Merge branch 'master' into feature_gitea2gitea-migration
6543 Oct 14, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ endif

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

#To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.20.1
#To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger
6543 marked this conversation as resolved.
Show resolved Hide resolved
SWAGGER := $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
SWAGGER_SPEC := templates/swagger/v1_json.tmpl
SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
SWAGGER_EXCLUDE := code.gitea.io/sdk
SWAGGER_NEWLINE_COMMAND := -e '$$a\'

TEST_MYSQL_HOST ?= mysql:3306
Expand Down Expand Up @@ -243,7 +244,7 @@ endif

.PHONY: generate-swagger
generate-swagger:
$(SWAGGER) generate spec -o './$(SWAGGER_SPEC)'
$(SWAGGER) generate spec -x "$(SWAGGER_EXCLUDE)" -o './$(SWAGGER_SPEC)'
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
$(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'

Expand Down
13 changes: 7 additions & 6 deletions docs/content/doc/advanced/migrations.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ menu:

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

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

## Downloader Interfaces

Expand All @@ -33,6 +33,7 @@ create a Downloader.

```Go
type Downloader interface {
GetAsset(relTag string, relID, id int64) (io.ReadCloser, error)
SetContext(context.Context)
GetRepoInfo() (*Repository, error)
GetTopics() ([]string, error)
Expand All @@ -41,15 +42,15 @@ type Downloader interface {
GetLabels() ([]*Label, error)
GetIssues(page, perPage int) ([]*Issue, bool, error)
GetComments(issueNumber int64) ([]*Comment, error)
GetPullRequests(page, perPage int) ([]*PullRequest, error)
GetPullRequests(page, perPage int) ([]*PullRequest, bool, error)
GetReviews(pullRequestNumber int64) ([]*Review, error)
}
```

```Go
type DownloaderFactory interface {
Match(opts MigrateOptions) (bool, error)
New(opts MigrateOptions) (Downloader, error)
New(ctx context.Context, opts MigrateOptions) (Downloader, error)
GitServiceType() structs.GitServiceType
}
```

Expand All @@ -66,7 +67,7 @@ type Uploader interface {
CreateRepo(repo *Repository, opts MigrateOptions) error
CreateTopics(topic ...string) error
CreateMilestones(milestones ...*Milestone) error
CreateReleases(releases ...*Release) error
CreateReleases(downloader Downloader, releases ...*Release) error
SyncTags() error
CreateLabels(labels ...*Label) error
CreateIssues(issues ...*Issue) error
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.14

require (
code.gitea.io/gitea-vet v0.2.1
code.gitea.io/sdk/gitea v0.13.1
gitea.com/lunny/levelqueue v0.3.0
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
gitea.com/macaron/cache v0.0.0-20190822004001-a6e7fee4ee76
Expand Down Expand Up @@ -49,7 +50,7 @@ require (
github.com/google/uuid v1.1.1
github.com/gorilla/context v1.1.1
github.com/hashicorp/go-retryablehttp v0.6.7 // indirect
github.com/hashicorp/go-version v0.0.0-00010101000000-000000000000
github.com/hashicorp/go-version v1.2.1
github.com/huandu/xstrings v1.3.0
github.com/issue9/assert v1.3.2 // indirect
github.com/issue9/identicon v1.0.1
Expand Down
42 changes: 2 additions & 40 deletions go.sum

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions modules/migrations/base/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// AssetDownloader downloads an asset (attachment) for a release
type AssetDownloader interface {
GetAsset(tag string, id int64) (io.ReadCloser, error)
GetAsset(relTag string, relID, id int64) (io.ReadCloser, error)
}

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

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

// GetPullRequests returns a repository's pull requests with retry
func (d *RetryDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, error) {
func (d *RetryDownloader) GetPullRequests(page, perPage int) ([]*PullRequest, bool, error) {
var (
times = d.RetryTimes
prs []*PullRequest
err error
isEnd bool
)
for ; times > 0; times-- {
if prs, err = d.Downloader.GetPullRequests(page, perPage); err == nil {
return prs, nil
if prs, isEnd, err = d.Downloader.GetPullRequests(page, perPage); err == nil {
return prs, isEnd, nil
}
select {
case <-d.ctx.Done():
return nil, d.ctx.Err()
return nil, false, d.ctx.Err()
case <-time.After(time.Second * time.Duration(d.RetryDelay)):
}
}
return nil, err
return nil, false, err
}

// GetReviews returns pull requests reviews
Expand Down
1 change: 1 addition & 0 deletions modules/migrations/base/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ type Issue struct {
Closed *time.Time
Labels []*Label
Reactions []*Reaction
Assignees []string
}
1 change: 0 additions & 1 deletion modules/migrations/base/pullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type PullRequest struct {
MergeCommitSHA string
Head PullRequestBranch
Base PullRequestBranch
Assignee string
Assignees []string
6543 marked this conversation as resolved.
Show resolved Hide resolved
IsLocked bool
Reactions []*Reaction
Expand Down
1 change: 1 addition & 0 deletions modules/migrations/base/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type ReleaseAsset struct {
DownloadCount *int
Created time.Time
Updated time.Time
DownloadURL *string
}

// Release represents a release
Expand Down
2 changes: 0 additions & 2 deletions modules/migrations/base/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ type Repository struct {
IsPrivate bool
IsMirror bool
Description string
AuthUsername string
AuthPassword string
CloneURL string
OriginalURL string
DefaultBranch string
Expand Down
1 change: 1 addition & 0 deletions modules/migrations/base/review.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type ReviewComment struct {
TreePath string
DiffHunk string
Position int
Line int
CommitID string
PosterID int64
Reactions []*Reaction
Expand Down
6 changes: 3 additions & 3 deletions modules/migrations/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (g *PlainGitDownloader) GetReleases() ([]*base.Release, error) {
}

// GetAsset returns an asset
func (g *PlainGitDownloader) GetAsset(_ string, _ int64) (io.ReadCloser, error) {
func (g *PlainGitDownloader) GetAsset(_ string, _, _ int64) (io.ReadCloser, error) {
return nil, ErrNotSupported
}

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

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

// GetReviews returns reviews according issue number
Expand Down
Loading