2019-05-07 09:12:51 +08:00
|
|
|
---
|
|
|
|
date: "2019-04-15T17:29:00+08:00"
|
|
|
|
title: "Advanced: Migrations Interfaces"
|
|
|
|
slug: "migrations-interfaces"
|
|
|
|
weight: 30
|
|
|
|
toc: true
|
|
|
|
draft: false
|
|
|
|
menu:
|
|
|
|
sidebar:
|
|
|
|
parent: "advanced"
|
|
|
|
name: "Migrations Interfaces"
|
|
|
|
weight: 55
|
|
|
|
identifier: "migrations-interfaces"
|
|
|
|
---
|
|
|
|
|
|
|
|
# Migration Features
|
|
|
|
|
2020-01-31 13:01:32 +08:00
|
|
|
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
|
2020-10-14 12:06:00 +08:00
|
|
|
git host platforms. Currently, migrations from Github, Gitlab and Gitea to Gitea is implemented.
|
2019-05-07 09:12:51 +08:00
|
|
|
|
|
|
|
First of all, Gitea defines some standard objects in packages `modules/migrations/base`. They are
|
2020-10-14 12:06:00 +08:00
|
|
|
`Repository`, `Milestone`, `Release`, `ReleaseAsset`, `Label`, `Issue`, `Comment`, `PullRequest`, `Reaction`, `Review`, `ReviewComment`.
|
2019-05-07 09:12:51 +08:00
|
|
|
|
|
|
|
## Downloader Interfaces
|
|
|
|
|
|
|
|
To migrate from a new git host platform, there are two steps to be updated.
|
|
|
|
|
|
|
|
- You should implement a `Downloader` which will get all kinds of repository informations.
|
2020-01-31 13:01:32 +08:00
|
|
|
- You should implement a `DownloaderFactory` which is used to detect if the URL matches and
|
2019-05-07 09:12:51 +08:00
|
|
|
create a Downloader.
|
|
|
|
- You'll need to register the `DownloaderFactory` via `RegisterDownloaderFactory` on init.
|
|
|
|
|
|
|
|
```Go
|
|
|
|
type Downloader interface {
|
2020-10-14 12:06:00 +08:00
|
|
|
GetAsset(relTag string, relID, id int64) (io.ReadCloser, error)
|
2020-01-31 13:01:32 +08:00
|
|
|
SetContext(context.Context)
|
2019-05-07 09:12:51 +08:00
|
|
|
GetRepoInfo() (*Repository, error)
|
2019-08-14 14:16:12 +08:00
|
|
|
GetTopics() ([]string, error)
|
2019-05-07 09:12:51 +08:00
|
|
|
GetMilestones() ([]*Milestone, error)
|
|
|
|
GetReleases() ([]*Release, error)
|
|
|
|
GetLabels() ([]*Label, error)
|
2020-01-31 13:01:32 +08:00
|
|
|
GetIssues(page, perPage int) ([]*Issue, bool, error)
|
2019-05-07 09:12:51 +08:00
|
|
|
GetComments(issueNumber int64) ([]*Comment, error)
|
2020-10-14 12:06:00 +08:00
|
|
|
GetPullRequests(page, perPage int) ([]*PullRequest, bool, error)
|
2020-01-31 13:01:32 +08:00
|
|
|
GetReviews(pullRequestNumber int64) ([]*Review, error)
|
2019-05-07 09:12:51 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```Go
|
|
|
|
type DownloaderFactory interface {
|
2020-10-14 12:06:00 +08:00
|
|
|
New(ctx context.Context, opts MigrateOptions) (Downloader, error)
|
|
|
|
GitServiceType() structs.GitServiceType
|
2019-05-07 09:12:51 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Uploader Interface
|
|
|
|
|
2020-01-31 13:01:32 +08:00
|
|
|
Currently, only a `GiteaLocalUploader` is implemented, so we only save downloaded
|
2019-05-07 09:12:51 +08:00
|
|
|
data via this `Uploader` on the local Gitea instance. Other uploaders are not supported
|
|
|
|
and will be implemented in future.
|
|
|
|
|
|
|
|
```Go
|
|
|
|
// Uploader uploads all the informations
|
|
|
|
type Uploader interface {
|
2020-01-31 13:01:32 +08:00
|
|
|
MaxBatchInsertSize(tp string) int
|
|
|
|
CreateRepo(repo *Repository, opts MigrateOptions) error
|
|
|
|
CreateTopics(topic ...string) error
|
|
|
|
CreateMilestones(milestones ...*Milestone) error
|
2020-10-14 12:06:00 +08:00
|
|
|
CreateReleases(downloader Downloader, releases ...*Release) error
|
2020-01-31 13:01:32 +08:00
|
|
|
SyncTags() error
|
|
|
|
CreateLabels(labels ...*Label) error
|
|
|
|
CreateIssues(issues ...*Issue) error
|
|
|
|
CreateComments(comments ...*Comment) error
|
|
|
|
CreatePullRequests(prs ...*PullRequest) error
|
|
|
|
CreateReviews(reviews ...*Review) error
|
2019-05-07 09:12:51 +08:00
|
|
|
Rollback() error
|
2019-11-13 15:01:19 +08:00
|
|
|
Close()
|
2019-05-07 09:12:51 +08:00
|
|
|
}
|
|
|
|
|
2019-11-13 15:01:19 +08:00
|
|
|
```
|