|
| 1 | +--- |
| 2 | +date: "2019-04-15T17:29:00+08:00" |
| 3 | +title: "Advanced: Migrations Interfaces" |
| 4 | +slug: "migrations-interfaces" |
| 5 | +weight: 30 |
| 6 | +toc: true |
| 7 | +draft: false |
| 8 | +menu: |
| 9 | + sidebar: |
| 10 | + parent: "advanced" |
| 11 | + name: "Migrations Interfaces" |
| 12 | + weight: 55 |
| 13 | + identifier: "migrations-interfaces" |
| 14 | +--- |
| 15 | + |
| 16 | +# Migration Features |
| 17 | + |
| 18 | +The new migration features introduced in Gitea 1.9.0. It defined two interfaces to support migrating |
| 19 | +repositories data from other git host platforms to gitea or in future migrating gitea data to other |
| 20 | +git host platform. Currently, it only implements to migrate from github via APIv3 to Gitea. |
| 21 | + |
| 22 | +First of all, Gitea defines some standard objects, `Repository`, `Milestone`, `Release`, `Label`, `Issue`, |
| 23 | +`Comment`, `PullRequest`. |
| 24 | + |
| 25 | +## Downloader Interfaces |
| 26 | + |
| 27 | +To migrate from a new git host platform, there are two steps to be updated. |
| 28 | + |
| 29 | +- You should implement a Downloader which could get repository all kinds of informations. |
| 30 | +- You should implement a DownloaderFactory which could detect if the url should match the |
| 31 | +factory and new a Downloader |
| 32 | +- You should RegisterDownloaderFactory when init |
| 33 | + |
| 34 | +```Go |
| 35 | +type Downloader interface { |
| 36 | + GetRepoInfo() (*Repository, error) |
| 37 | + GetMilestones() ([]*Milestone, error) |
| 38 | + GetReleases() ([]*Release, error) |
| 39 | + GetLabels() ([]*Label, error) |
| 40 | + GetIssues(start, limit int) ([]*Issue, error) |
| 41 | + GetComments(issueNumber int64) ([]*Comment, error) |
| 42 | + GetPullRequests(start, limit int) ([]*PullRequest, error) |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +```Go |
| 47 | +type DownloaderFactory interface { |
| 48 | + Match(opts MigrateOptions) (bool, error) |
| 49 | + New(opts MigrateOptions) (Downloader, error) |
| 50 | +} |
| 51 | +``` |
| 52 | + |
| 53 | +## Uploader Interface |
| 54 | + |
| 55 | +Currently, we only implemented an Uploader `GiteaLocalUploader` so we only save downloaded |
| 56 | +data via this `Uploader` and we haven't supported a new Uploader that will be in future. |
| 57 | + |
| 58 | +```Go |
| 59 | +// Uploader uploads all the informations |
| 60 | +type Uploader interface { |
| 61 | + CreateRepo(repo *Repository, includeWiki bool) error |
| 62 | + CreateMilestone(milestone *Milestone) error |
| 63 | + CreateRelease(release *Release) error |
| 64 | + CreateLabel(label *Label) error |
| 65 | + CreateIssue(issue *Issue) error |
| 66 | + CreateComment(issueNumber int64, comment *Comment) error |
| 67 | + CreatePullRequest(pr *PullRequest) error |
| 68 | + Rollback() error |
| 69 | +} |
| 70 | + |
| 71 | +``` |
0 commit comments