Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

migrations_source_import.go 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. // Copyright 2016 The go-github AUTHORS. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSE file.
  5. package github
  6. import (
  7. "context"
  8. "fmt"
  9. )
  10. // Import represents a repository import request.
  11. type Import struct {
  12. // The URL of the originating repository.
  13. VCSURL *string `json:"vcs_url,omitempty"`
  14. // The originating VCS type. Can be one of 'subversion', 'git',
  15. // 'mercurial', or 'tfvc'. Without this parameter, the import job will
  16. // take additional time to detect the VCS type before beginning the
  17. // import. This detection step will be reflected in the response.
  18. VCS *string `json:"vcs,omitempty"`
  19. // VCSUsername and VCSPassword are only used for StartImport calls that
  20. // are importing a password-protected repository.
  21. VCSUsername *string `json:"vcs_username,omitempty"`
  22. VCSPassword *string `json:"vcs_password,omitempty"`
  23. // For a tfvc import, the name of the project that is being imported.
  24. TFVCProject *string `json:"tfvc_project,omitempty"`
  25. // LFS related fields that may be preset in the Import Progress response
  26. // Describes whether the import has been opted in or out of using Git
  27. // LFS. The value can be 'opt_in', 'opt_out', or 'undecided' if no
  28. // action has been taken.
  29. UseLFS *string `json:"use_lfs,omitempty"`
  30. // Describes whether files larger than 100MB were found during the
  31. // importing step.
  32. HasLargeFiles *bool `json:"has_large_files,omitempty"`
  33. // The total size in gigabytes of files larger than 100MB found in the
  34. // originating repository.
  35. LargeFilesSize *int `json:"large_files_size,omitempty"`
  36. // The total number of files larger than 100MB found in the originating
  37. // repository. To see a list of these files, call LargeFiles.
  38. LargeFilesCount *int `json:"large_files_count,omitempty"`
  39. // Identifies the current status of an import. An import that does not
  40. // have errors will progress through these steps:
  41. //
  42. // detecting - the "detection" step of the import is in progress
  43. // because the request did not include a VCS parameter. The
  44. // import is identifying the type of source control present at
  45. // the URL.
  46. // importing - the "raw" step of the import is in progress. This is
  47. // where commit data is fetched from the original repository.
  48. // The import progress response will include CommitCount (the
  49. // total number of raw commits that will be imported) and
  50. // Percent (0 - 100, the current progress through the import).
  51. // mapping - the "rewrite" step of the import is in progress. This
  52. // is where SVN branches are converted to Git branches, and
  53. // where author updates are applied. The import progress
  54. // response does not include progress information.
  55. // pushing - the "push" step of the import is in progress. This is
  56. // where the importer updates the repository on GitHub. The
  57. // import progress response will include PushPercent, which is
  58. // the percent value reported by git push when it is "Writing
  59. // objects".
  60. // complete - the import is complete, and the repository is ready
  61. // on GitHub.
  62. //
  63. // If there are problems, you will see one of these in the status field:
  64. //
  65. // auth_failed - the import requires authentication in order to
  66. // connect to the original repository. Make an UpdateImport
  67. // request, and include VCSUsername and VCSPassword.
  68. // error - the import encountered an error. The import progress
  69. // response will include the FailedStep and an error message.
  70. // Contact GitHub support for more information.
  71. // detection_needs_auth - the importer requires authentication for
  72. // the originating repository to continue detection. Make an
  73. // UpdatImport request, and include VCSUsername and
  74. // VCSPassword.
  75. // detection_found_nothing - the importer didn't recognize any
  76. // source control at the URL.
  77. // detection_found_multiple - the importer found several projects
  78. // or repositories at the provided URL. When this is the case,
  79. // the Import Progress response will also include a
  80. // ProjectChoices field with the possible project choices as
  81. // values. Make an UpdateImport request, and include VCS and
  82. // (if applicable) TFVCProject.
  83. Status *string `json:"status,omitempty"`
  84. CommitCount *int `json:"commit_count,omitempty"`
  85. StatusText *string `json:"status_text,omitempty"`
  86. AuthorsCount *int `json:"authors_count,omitempty"`
  87. Percent *int `json:"percent,omitempty"`
  88. PushPercent *int `json:"push_percent,omitempty"`
  89. URL *string `json:"url,omitempty"`
  90. HTMLURL *string `json:"html_url,omitempty"`
  91. AuthorsURL *string `json:"authors_url,omitempty"`
  92. RepositoryURL *string `json:"repository_url,omitempty"`
  93. Message *string `json:"message,omitempty"`
  94. FailedStep *string `json:"failed_step,omitempty"`
  95. // Human readable display name, provided when the Import appears as
  96. // part of ProjectChoices.
  97. HumanName *string `json:"human_name,omitempty"`
  98. // When the importer finds several projects or repositories at the
  99. // provided URLs, this will identify the available choices. Call
  100. // UpdateImport with the selected Import value.
  101. ProjectChoices []Import `json:"project_choices,omitempty"`
  102. }
  103. func (i Import) String() string {
  104. return Stringify(i)
  105. }
  106. // SourceImportAuthor identifies an author imported from a source repository.
  107. //
  108. // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-commit-authors
  109. type SourceImportAuthor struct {
  110. ID *int64 `json:"id,omitempty"`
  111. RemoteID *string `json:"remote_id,omitempty"`
  112. RemoteName *string `json:"remote_name,omitempty"`
  113. Email *string `json:"email,omitempty"`
  114. Name *string `json:"name,omitempty"`
  115. URL *string `json:"url,omitempty"`
  116. ImportURL *string `json:"import_url,omitempty"`
  117. }
  118. func (a SourceImportAuthor) String() string {
  119. return Stringify(a)
  120. }
  121. // LargeFile identifies a file larger than 100MB found during a repository import.
  122. //
  123. // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-large-files
  124. type LargeFile struct {
  125. RefName *string `json:"ref_name,omitempty"`
  126. Path *string `json:"path,omitempty"`
  127. OID *string `json:"oid,omitempty"`
  128. Size *int `json:"size,omitempty"`
  129. }
  130. func (f LargeFile) String() string {
  131. return Stringify(f)
  132. }
  133. // StartImport initiates a repository import.
  134. //
  135. // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#start-an-import
  136. func (s *MigrationService) StartImport(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
  137. u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
  138. req, err := s.client.NewRequest("PUT", u, in)
  139. if err != nil {
  140. return nil, nil, err
  141. }
  142. // TODO: remove custom Accept header when this API fully launches
  143. req.Header.Set("Accept", mediaTypeImportPreview)
  144. out := new(Import)
  145. resp, err := s.client.Do(ctx, req, out)
  146. if err != nil {
  147. return nil, resp, err
  148. }
  149. return out, resp, nil
  150. }
  151. // ImportProgress queries for the status and progress of an ongoing repository import.
  152. //
  153. // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-import-progress
  154. func (s *MigrationService) ImportProgress(ctx context.Context, owner, repo string) (*Import, *Response, error) {
  155. u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
  156. req, err := s.client.NewRequest("GET", u, nil)
  157. if err != nil {
  158. return nil, nil, err
  159. }
  160. // TODO: remove custom Accept header when this API fully launches
  161. req.Header.Set("Accept", mediaTypeImportPreview)
  162. out := new(Import)
  163. resp, err := s.client.Do(ctx, req, out)
  164. if err != nil {
  165. return nil, resp, err
  166. }
  167. return out, resp, nil
  168. }
  169. // UpdateImport initiates a repository import.
  170. //
  171. // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#update-existing-import
  172. func (s *MigrationService) UpdateImport(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
  173. u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
  174. req, err := s.client.NewRequest("PATCH", u, in)
  175. if err != nil {
  176. return nil, nil, err
  177. }
  178. // TODO: remove custom Accept header when this API fully launches
  179. req.Header.Set("Accept", mediaTypeImportPreview)
  180. out := new(Import)
  181. resp, err := s.client.Do(ctx, req, out)
  182. if err != nil {
  183. return nil, resp, err
  184. }
  185. return out, resp, nil
  186. }
  187. // CommitAuthors gets the authors mapped from the original repository.
  188. //
  189. // Each type of source control system represents authors in a different way.
  190. // For example, a Git commit author has a display name and an email address,
  191. // but a Subversion commit author just has a username. The GitHub Importer will
  192. // make the author information valid, but the author might not be correct. For
  193. // example, it will change the bare Subversion username "hubot" into something
  194. // like "hubot <hubot@12341234-abab-fefe-8787-fedcba987654>".
  195. //
  196. // This method and MapCommitAuthor allow you to provide correct Git author
  197. // information.
  198. //
  199. // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-commit-authors
  200. func (s *MigrationService) CommitAuthors(ctx context.Context, owner, repo string) ([]*SourceImportAuthor, *Response, error) {
  201. u := fmt.Sprintf("repos/%v/%v/import/authors", owner, repo)
  202. req, err := s.client.NewRequest("GET", u, nil)
  203. if err != nil {
  204. return nil, nil, err
  205. }
  206. // TODO: remove custom Accept header when this API fully launches
  207. req.Header.Set("Accept", mediaTypeImportPreview)
  208. var authors []*SourceImportAuthor
  209. resp, err := s.client.Do(ctx, req, &authors)
  210. if err != nil {
  211. return nil, resp, err
  212. }
  213. return authors, resp, nil
  214. }
  215. // MapCommitAuthor updates an author's identity for the import. Your
  216. // application can continue updating authors any time before you push new
  217. // commits to the repository.
  218. //
  219. // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#map-a-commit-author
  220. func (s *MigrationService) MapCommitAuthor(ctx context.Context, owner, repo string, id int64, author *SourceImportAuthor) (*SourceImportAuthor, *Response, error) {
  221. u := fmt.Sprintf("repos/%v/%v/import/authors/%v", owner, repo, id)
  222. req, err := s.client.NewRequest("PATCH", u, author)
  223. if err != nil {
  224. return nil, nil, err
  225. }
  226. // TODO: remove custom Accept header when this API fully launches
  227. req.Header.Set("Accept", mediaTypeImportPreview)
  228. out := new(SourceImportAuthor)
  229. resp, err := s.client.Do(ctx, req, out)
  230. if err != nil {
  231. return nil, resp, err
  232. }
  233. return out, resp, nil
  234. }
  235. // SetLFSPreference sets whether imported repositories should use Git LFS for
  236. // files larger than 100MB. Only the UseLFS field on the provided Import is
  237. // used.
  238. //
  239. // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#set-git-lfs-preference
  240. func (s *MigrationService) SetLFSPreference(ctx context.Context, owner, repo string, in *Import) (*Import, *Response, error) {
  241. u := fmt.Sprintf("repos/%v/%v/import/lfs", owner, repo)
  242. req, err := s.client.NewRequest("PATCH", u, in)
  243. if err != nil {
  244. return nil, nil, err
  245. }
  246. // TODO: remove custom Accept header when this API fully launches
  247. req.Header.Set("Accept", mediaTypeImportPreview)
  248. out := new(Import)
  249. resp, err := s.client.Do(ctx, req, out)
  250. if err != nil {
  251. return nil, resp, err
  252. }
  253. return out, resp, nil
  254. }
  255. // LargeFiles lists files larger than 100MB found during the import.
  256. //
  257. // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#get-large-files
  258. func (s *MigrationService) LargeFiles(ctx context.Context, owner, repo string) ([]*LargeFile, *Response, error) {
  259. u := fmt.Sprintf("repos/%v/%v/import/large_files", owner, repo)
  260. req, err := s.client.NewRequest("GET", u, nil)
  261. if err != nil {
  262. return nil, nil, err
  263. }
  264. // TODO: remove custom Accept header when this API fully launches
  265. req.Header.Set("Accept", mediaTypeImportPreview)
  266. var files []*LargeFile
  267. resp, err := s.client.Do(ctx, req, &files)
  268. if err != nil {
  269. return nil, resp, err
  270. }
  271. return files, resp, nil
  272. }
  273. // CancelImport stops an import for a repository.
  274. //
  275. // GitHub API docs: https://developer.github.com/v3/migration/source_imports/#cancel-an-import
  276. func (s *MigrationService) CancelImport(ctx context.Context, owner, repo string) (*Response, error) {
  277. u := fmt.Sprintf("repos/%v/%v/import", owner, repo)
  278. req, err := s.client.NewRequest("DELETE", u, nil)
  279. if err != nil {
  280. return nil, err
  281. }
  282. // TODO: remove custom Accept header when this API fully launches
  283. req.Header.Set("Accept", mediaTypeImportPreview)
  284. return s.client.Do(ctx, req, nil)
  285. }