PageRenderTime 26ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/octokit/client/source_import.rb

https://gitlab.com/mayakarya/octokit.rb
Ruby | 161 lines | 45 code | 9 blank | 107 comment | 1 complexity | ff47f27afa2b0d349a3458f5b17e16df MD5 | raw file
  1. module Octokit
  2. class Client
  3. # Methods for the Source Import API
  4. #
  5. # @see https://developer.github.com/v3/migration/source_imports
  6. module SourceImport
  7. # Start a source import to a GitHub repository using GitHub Importer.
  8. #
  9. # @overload start_source_import(repo, vcs, vcs_url, options = {})
  10. # @deprecated
  11. # @param repo [Integer, String, Hash, Repository] A GitHub repository.
  12. # @param vcs [String] The originating VCS type. Can be one of "subversion", "git", "mercurial", or "tfvc".
  13. # @param vcs_url [String] The URL of the originating repository.
  14. # @param options [Hash]
  15. # @option options [String] :vcs_username If authentication is required, the username to provide to vcs_url.
  16. # @option options [String] :vcs_password If authentication is required, the password to provide to vcs_url.
  17. # @option options [String] :tfvc_project For a tfvc import, the name of the project that is being imported.
  18. # @overload start_source_import(repo, vcs_url, options = {})
  19. # @param repo [Integer, String, Hash, Repository] A GitHub repository.
  20. # @param vcs_url [String] The URL of the originating repository.
  21. # @param options [Hash]
  22. # @param options [String] :vcs The originating VCS type. Can be one of "subversion", "git", "mercurial", or "tfvc".
  23. # @option options [String] :vcs_username If authentication is required, the username to provide to vcs_url.
  24. # @option options [String] :vcs_password If authentication is required, the password to provide to vcs_url.
  25. # @option options [String] :tfvc_project For a tfvc import, the name of the project that is being imported.
  26. # @return [Sawyer::Resource] Hash representing the repository import
  27. # @see https://developer.github.com/v3/migration/source_imports/#start-an-import
  28. #
  29. # @example
  30. # @client.start_source_import("octokit/octokit.rb", "http://svn.mycompany.com/svn/myproject", {
  31. # :vcs => "subversion",
  32. # :vcs_username" => "octocat",
  33. # :vcs_password => "secret"
  34. # })
  35. def start_source_import(*args)
  36. arguments = Octokit::RepoArguments.new(args)
  37. vcs_url = arguments.pop
  38. vcs = arguments.pop
  39. if vcs
  40. octokit_warn "Octokit#start_source_import vcs parameter is now an option, please update your call before the next major Octokit version update."
  41. arguments.options.merge!(:vcs => vcs)
  42. end
  43. options = ensure_api_media_type(:source_imports, arguments.options.merge(:vcs_url => vcs_url))
  44. put "#{Repository.path arguments.repo}/import", options
  45. end
  46. # View the progress of an import.
  47. #
  48. # @param repo [Integer, String, Hash, Repository] A GitHub repository.
  49. # @return [Sawyer::Resource] Hash representing the progress of the import
  50. # @see https://developer.github.com/v3/migration/source_imports/#get-import-progress
  51. #
  52. # @example
  53. # @client.source_import_progress("octokit/octokit.rb")
  54. def source_import_progress(repo, options = {})
  55. options = ensure_api_media_type(:source_imports, options)
  56. get "#{Repository.path repo}/import", options
  57. end
  58. # Update source import with authentication or project choice
  59. # Restart source import if no options are passed
  60. #
  61. # @param repo [Integer, String, Hash, Repository] A GitHub repository.
  62. # @return [Sawyer::Resource] Hash representing the repository import
  63. # @see https://developer.github.com/v3/migration/source_imports/#update-existing-import
  64. # @option options [String] :vcs_username If authentication is required, the username to provide to vcs_url.
  65. # @option options [String] :vcs_password If authentication is required, the password to provide to vcs_url.
  66. # @option options [String] To update project choice, please refer to the project_choice array from the progress return hash for the exact attributes.
  67. # https://developer.github.com/v3/migration/source_imports/#update-existing-import
  68. #
  69. # @example
  70. # @client.update_source_import("octokit/octokit.rb", {
  71. # :vcs_username" => "octocat",
  72. # :vcs_password => "secret"
  73. # })
  74. def update_source_import(repo, options = {})
  75. options = ensure_api_media_type(:source_imports, options)
  76. patch "#{Repository.path repo}/import", options
  77. end
  78. # List source import commit authors
  79. #
  80. # @param repo [Integer, String, Hash, Repository] A GitHub repository.
  81. # @param options [Hash]
  82. # @option options [String] :since Only authors found after this id are returned.
  83. # @return [Array<Sawyer::Resource>] Array of hashes representing commit_authors.
  84. # @see https://developer.github.com/v3/migration/source_imports/#get-commit-authors
  85. #
  86. # @example
  87. # @client.source_import_commit_authors("octokit/octokit.rb")
  88. def source_import_commit_authors(repo, options = {})
  89. options = ensure_api_media_type(:source_imports, options)
  90. get "#{Repository.path repo}/import/authors", options
  91. end
  92. # Update an author's identity for the import.
  93. #
  94. # @param author_url [String] The source import API url for the commit author
  95. # @param values [Hash] The updated author attributes
  96. # @option values [String] :email The new Git author email.
  97. # @option values [String] :name The new Git author name.
  98. # @return [Sawyer::Resource] Hash representing the updated commit author
  99. # @see https://developer.github.com/v3/migration/source_imports/#map-a-commit-author
  100. #
  101. # @example
  102. # author_url = "https://api.github.com/repos/octokit/octokit.rb/import/authors/1"
  103. # @client.map_source_import_commit_author(author_url, {
  104. # :email => "hubot@github.com",
  105. # :name => "Hubot the Robot"
  106. # })
  107. def map_source_import_commit_author(author_url, values, options = {})
  108. options = ensure_api_media_type(:source_imports, options.merge(values))
  109. patch author_url, options
  110. end
  111. # Stop an import for a repository.
  112. #
  113. # @param repo [Integer, String, Hash, Repository] A GitHub repository.
  114. # @return [Boolean] True if the import has been cancelled, false otherwise.
  115. # @see https://developer.github.com/v3/migration/source_imports/#cancel-an-import
  116. #
  117. # @example
  118. # @client.cancel_source_import("octokit/octokit.rb")
  119. def cancel_source_import(repo, options = {})
  120. options = ensure_api_media_type(:source_imports, options)
  121. boolean_from_response :delete, "#{Repository.path repo}/import", options
  122. end
  123. # List source import large files
  124. #
  125. # @param repo [Integer, String, Hash, Repository] A GitHub repository.
  126. # @param options [Hash]
  127. # @option options [Fixnum] :page Page of paginated results
  128. # @return [Array<Sawyer::Resource>] Array of hashes representing files over 100MB.
  129. # @see https://developer.github.com/v3/migration/source_imports/#get-large-files
  130. #
  131. # @example
  132. # @client.source_import_large_files("octokit/octokit.rb")
  133. def source_import_large_files(repo, options = {})
  134. options = ensure_api_media_type(:source_imports, options)
  135. get "#{Repository.path repo}/import/large_files", options
  136. end
  137. # Set preference for using Git LFS to import files over 100MB
  138. #
  139. # @param repo [Integer, String, Hash, Repository] A GitHub repository.
  140. # @param use_lfs [String] Preference for using Git LFS to import large files. Can be one of "opt_in" or "opt_out"
  141. # @return [Sawyer::Resource] Hash representing the repository import
  142. # @see https://developer.github.com/v3/migration/source_imports/#set-git-lfs-preference
  143. #
  144. # @example
  145. # @client.opt_in_source_import_lfs("octokit/octokit.rb", "opt_in")
  146. def set_source_import_lfs_preference(repo, use_lfs, options = {})
  147. options = ensure_api_media_type(:source_imports, options.merge(:use_lfs => use_lfs))
  148. patch "#{Repository.path repo}/import/lfs", options
  149. end
  150. end
  151. end
  152. end