summaryrefslogtreecommitdiffstats
path: root/modules/migrations/base
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-05-07 09:12:51 +0800
committerGitHub <noreply@github.com>2019-05-07 09:12:51 +0800
commit08069dc4656fa53ee5dd25189e15012cb4f8acb2 (patch)
tree2e08cb239fef3221e55da75f106dfcb0140e08a1 /modules/migrations/base
parent1c7c739eb9ea1d2ffdaed3c776c84d42858c0851 (diff)
downloadgitea-08069dc4656fa53ee5dd25189e15012cb4f8acb2.tar.gz
gitea-08069dc4656fa53ee5dd25189e15012cb4f8acb2.zip
Improve migrations to support migrating milestones/labels/issues/comments/pullrequests (#6290)
* add migrations * fix package dependency * fix lints * implements migrations except pull requests * add releases * migrating releases * fix bug * fix lint * fix migrate releases * fix tests * add rollback * pull request migtations * fix import * fix go module vendor * add tests for upload to gitea * more migrate options * fix swagger-check * fix misspell * add options on migration UI * fix log error * improve UI options on migrating * add support for username password when migrating from github * fix tests * remove comments and fix migrate limitation * improve error handles * migrate API will also support migrate milestones/labels/issues/pulls/releases * fix tests and remove unused codes * add DownloaderFactory and docs about how to create a new Downloader * fix misspell * fix migration docs * Add hints about migrate options on migration page * fix tests
Diffstat (limited to 'modules/migrations/base')
-rw-r--r--modules/migrations/base/comment.go17
-rw-r--r--modules/migrations/base/downloader.go23
-rw-r--r--modules/migrations/base/issue.go24
-rw-r--r--modules/migrations/base/label.go13
-rw-r--r--modules/migrations/base/milestone.go19
-rw-r--r--modules/migrations/base/options.go26
-rw-r--r--modules/migrations/base/pullrequest.go53
-rw-r--r--modules/migrations/base/reaction.go17
-rw-r--r--modules/migrations/base/release.go31
-rw-r--r--modules/migrations/base/repo.go18
-rw-r--r--modules/migrations/base/uploader.go18
11 files changed, 259 insertions, 0 deletions
diff --git a/modules/migrations/base/comment.go b/modules/migrations/base/comment.go
new file mode 100644
index 0000000000..0ff0963f07
--- /dev/null
+++ b/modules/migrations/base/comment.go
@@ -0,0 +1,17 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2018 Jonas Franz. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+import "time"
+
+// Comment is a standard comment information
+type Comment struct {
+ PosterName string
+ PosterEmail string
+ Created time.Time
+ Content string
+ Reactions *Reactions
+}
diff --git a/modules/migrations/base/downloader.go b/modules/migrations/base/downloader.go
new file mode 100644
index 0000000000..9a09fdac0a
--- /dev/null
+++ b/modules/migrations/base/downloader.go
@@ -0,0 +1,23 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2018 Jonas Franz. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+// Downloader downloads the site repo informations
+type Downloader interface {
+ GetRepoInfo() (*Repository, error)
+ GetMilestones() ([]*Milestone, error)
+ GetReleases() ([]*Release, error)
+ GetLabels() ([]*Label, error)
+ GetIssues(start, limit int) ([]*Issue, error)
+ GetComments(issueNumber int64) ([]*Comment, error)
+ GetPullRequests(start, limit int) ([]*PullRequest, error)
+}
+
+// DownloaderFactory defines an interface to match a downloader implementation and create a downloader
+type DownloaderFactory interface {
+ Match(opts MigrateOptions) (bool, error)
+ New(opts MigrateOptions) (Downloader, error)
+}
diff --git a/modules/migrations/base/issue.go b/modules/migrations/base/issue.go
new file mode 100644
index 0000000000..ddadd0c2b3
--- /dev/null
+++ b/modules/migrations/base/issue.go
@@ -0,0 +1,24 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2018 Jonas Franz. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+import "time"
+
+// Issue is a standard issue information
+type Issue struct {
+ Number int64
+ PosterName string
+ PosterEmail string
+ Title string
+ Content string
+ Milestone string
+ State string // closed, open
+ IsLocked bool
+ Created time.Time
+ Closed *time.Time
+ Labels []*Label
+ Reactions *Reactions
+}
diff --git a/modules/migrations/base/label.go b/modules/migrations/base/label.go
new file mode 100644
index 0000000000..0c86b547f1
--- /dev/null
+++ b/modules/migrations/base/label.go
@@ -0,0 +1,13 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2018 Jonas Franz. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+// Label defines a standard label informations
+type Label struct {
+ Name string
+ Color string
+ Description string
+}
diff --git a/modules/migrations/base/milestone.go b/modules/migrations/base/milestone.go
new file mode 100644
index 0000000000..8736aa6cfd
--- /dev/null
+++ b/modules/migrations/base/milestone.go
@@ -0,0 +1,19 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2018 Jonas Franz. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+import "time"
+
+// Milestone defines a standard milestone
+type Milestone struct {
+ Title string
+ Description string
+ Deadline *time.Time
+ Created time.Time
+ Updated *time.Time
+ Closed *time.Time
+ State string
+}
diff --git a/modules/migrations/base/options.go b/modules/migrations/base/options.go
new file mode 100644
index 0000000000..262981b933
--- /dev/null
+++ b/modules/migrations/base/options.go
@@ -0,0 +1,26 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2018 Jonas Franz. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+// MigrateOptions defines the way a repository gets migrated
+type MigrateOptions struct {
+ RemoteURL string
+ AuthUsername string
+ AuthPassword string
+ Name string
+ Description string
+
+ Wiki bool
+ Issues bool
+ Milestones bool
+ Labels bool
+ Releases bool
+ Comments bool
+ PullRequests bool
+ Private bool
+ Mirror bool
+ IgnoreIssueAuthor bool // if true will not add original author information before issues or comments content.
+}
diff --git a/modules/migrations/base/pullrequest.go b/modules/migrations/base/pullrequest.go
new file mode 100644
index 0000000000..515cab3f91
--- /dev/null
+++ b/modules/migrations/base/pullrequest.go
@@ -0,0 +1,53 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2018 Jonas Franz. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+import (
+ "fmt"
+ "time"
+)
+
+// PullRequest defines a standard pull request information
+type PullRequest struct {
+ Number int64
+ Title string
+ PosterName string
+ PosterEmail string
+ Content string
+ Milestone string
+ State string
+ Created time.Time
+ Closed *time.Time
+ Labels []*Label
+ PatchURL string
+ Merged bool
+ MergedTime *time.Time
+ MergeCommitSHA string
+ Head PullRequestBranch
+ Base PullRequestBranch
+ Assignee string
+ Assignees []string
+ IsLocked bool
+}
+
+// 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()
+}
+
+// PullRequestBranch represents a pull request branch
+type PullRequestBranch struct {
+ CloneURL string
+ Ref string
+ SHA string
+ RepoName string
+ OwnerName string
+}
+
+// RepoPath returns pull request repo path
+func (p PullRequestBranch) RepoPath() string {
+ return fmt.Sprintf("%s/%s", p.OwnerName, p.RepoName)
+}
diff --git a/modules/migrations/base/reaction.go b/modules/migrations/base/reaction.go
new file mode 100644
index 0000000000..fd7a9543d3
--- /dev/null
+++ b/modules/migrations/base/reaction.go
@@ -0,0 +1,17 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2018 Jonas Franz. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+// Reactions represents a summary of reactions.
+type Reactions struct {
+ TotalCount int
+ PlusOne int
+ MinusOne int
+ Laugh int
+ Confused int
+ Heart int
+ Hooray int
+}
diff --git a/modules/migrations/base/release.go b/modules/migrations/base/release.go
new file mode 100644
index 0000000000..4ebc37315d
--- /dev/null
+++ b/modules/migrations/base/release.go
@@ -0,0 +1,31 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+import "time"
+
+// ReleaseAsset represents a release asset
+type ReleaseAsset struct {
+ URL string
+ Name string
+ ContentType *string
+ Size *int
+ DownloadCount *int
+ Created time.Time
+ Updated time.Time
+}
+
+// Release represents a release
+type Release struct {
+ TagName string
+ TargetCommitish string
+ Name string
+ Body string
+ Draft bool
+ Prerelease bool
+ Assets []ReleaseAsset
+ Created time.Time
+ Published time.Time
+}
diff --git a/modules/migrations/base/repo.go b/modules/migrations/base/repo.go
new file mode 100644
index 0000000000..907d8fc09e
--- /dev/null
+++ b/modules/migrations/base/repo.go
@@ -0,0 +1,18 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2018 Jonas Franz. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+// Repository defines a standard repository information
+type Repository struct {
+ Name string
+ Owner string
+ IsPrivate bool
+ IsMirror bool
+ Description string
+ AuthUsername string
+ AuthPassword string
+ CloneURL string
+}
diff --git a/modules/migrations/base/uploader.go b/modules/migrations/base/uploader.go
new file mode 100644
index 0000000000..eaeb10314a
--- /dev/null
+++ b/modules/migrations/base/uploader.go
@@ -0,0 +1,18 @@
+// Copyright 2019 The Gitea Authors. All rights reserved.
+// Copyright 2018 Jonas Franz. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package base
+
+// Uploader uploads all the informations
+type Uploader interface {
+ CreateRepo(repo *Repository, includeWiki bool) error
+ CreateMilestone(milestone *Milestone) error
+ CreateRelease(release *Release) error
+ CreateLabel(label *Label) error
+ CreateIssue(issue *Issue) error
+ CreateComment(issueNumber int64, comment *Comment) error
+ CreatePullRequest(pr *PullRequest) error
+ Rollback() error
+}