summaryrefslogtreecommitdiff
path: root/lib/api/import_github.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/import_github.rb')
-rw-r--r--lib/api/import_github.rb34
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/api/import_github.rb b/lib/api/import_github.rb
index d742e3732a8..6330a4458f3 100644
--- a/lib/api/import_github.rb
+++ b/lib/api/import_github.rb
@@ -8,6 +8,7 @@ module API
urgency :low
rescue_from Octokit::Unauthorized, with: :provider_unauthorized
+ rescue_from Gitlab::GithubImport::RateLimitError, with: :too_many_requests
helpers do
def client
@@ -33,6 +34,10 @@ module API
def provider_unauthorized
error!("Access denied to your #{Gitlab::ImportSources.title(provider.to_s)} account.", 401)
end
+
+ def too_many_requests
+ error!('Too Many Requests', 429)
+ end
end
desc 'Import a GitHub project' do
@@ -51,7 +56,7 @@ module API
requires :personal_access_token, type: String, desc: 'GitHub personal access token'
requires :repo_id, type: Integer, desc: 'GitHub repository ID'
optional :new_name, type: String, desc: 'New repo name'
- requires :target_namespace, type: String, desc: 'Namespace to import repo into'
+ requires :target_namespace, type: String, allow_blank: false, desc: 'Namespace or group to import repository into'
optional :github_hostname, type: String, desc: 'Custom GitHub enterprise hostname'
optional :optional_stages, type: Hash, desc: 'Optional stages of import to be performed'
end
@@ -92,5 +97,32 @@ module API
render_api_error!(result[:message], result[:http_status])
end
end
+
+ desc 'Import User Gists' do
+ detail 'This feature was introduced in GitLab 15.8'
+ success code: 202
+ failure [
+ { code: 401, message: 'Unauthorized' },
+ { code: 422, message: 'Unprocessable Entity' },
+ { code: 429, message: 'Too Many Requests' }
+ ]
+ end
+ params do
+ requires :personal_access_token, type: String, desc: 'GitHub personal access token'
+ end
+ post 'import/github/gists' do
+ not_found! if Feature.disabled?(:github_import_gists)
+
+ authorize! :create_snippet
+
+ result = Import::Github::GistsImportService.new(current_user, client, access_params).execute
+
+ if result[:status] == :success
+ status 202
+ else
+ status result[:http_status]
+ { errors: result[:message] }
+ end
+ end
end
end