You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

migrations.en-us.md 2.6 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. # Migration Features
  16. The new migration features were introduced in Gitea 1.9.0. It defines two interfaces to support migrating
  17. repositories data from other git host platforms to gitea or, in the future migrating gitea data to other
  18. git host platforms. Currently, only the migrations from github via APIv3 to Gitea is implemented.
  19. First of all, Gitea defines some standard objects in packages `modules/migrations/base`. They are
  20. `Repository`, `Milestone`, `Release`, `Label`, `Issue`, `Comment`, `PullRequest`, `Reaction`, `Review`, `ReviewComment`.
  21. ## Downloader Interfaces
  22. To migrate from a new git host platform, there are two steps to be updated.
  23. - You should implement a `Downloader` which will get all kinds of repository informations.
  24. - You should implement a `DownloaderFactory` which is used to detect if the URL matches and
  25. create a Downloader.
  26. - You'll need to register the `DownloaderFactory` via `RegisterDownloaderFactory` on init.
  27. ```Go
  28. type Downloader interface {
  29. SetContext(context.Context)
  30. GetRepoInfo() (*Repository, error)
  31. GetTopics() ([]string, error)
  32. GetMilestones() ([]*Milestone, error)
  33. GetReleases() ([]*Release, error)
  34. GetLabels() ([]*Label, error)
  35. GetIssues(page, perPage int) ([]*Issue, bool, error)
  36. GetComments(issueNumber int64) ([]*Comment, error)
  37. GetPullRequests(page, perPage int) ([]*PullRequest, error)
  38. GetReviews(pullRequestNumber int64) ([]*Review, error)
  39. }
  40. ```
  41. ```Go
  42. type DownloaderFactory interface {
  43. Match(opts MigrateOptions) (bool, error)
  44. New(opts MigrateOptions) (Downloader, error)
  45. }
  46. ```
  47. ## Uploader Interface
  48. Currently, only a `GiteaLocalUploader` is implemented, so we only save downloaded
  49. data via this `Uploader` on the local Gitea instance. Other uploaders are not supported
  50. and will be implemented in future.
  51. ```Go
  52. // Uploader uploads all the informations
  53. type Uploader interface {
  54. MaxBatchInsertSize(tp string) int
  55. CreateRepo(repo *Repository, opts MigrateOptions) error
  56. CreateTopics(topic ...string) error
  57. CreateMilestones(milestones ...*Milestone) error
  58. CreateReleases(releases ...*Release) error
  59. SyncTags() error
  60. CreateLabels(labels ...*Label) error
  61. CreateIssues(issues ...*Issue) error
  62. CreateComments(comments ...*Comment) error
  63. CreatePullRequests(prs ...*PullRequest) error
  64. CreateReviews(reviews ...*Review) error
  65. Rollback() error
  66. Close()
  67. }
  68. ```