summaryrefslogtreecommitdiff
path: root/app/controllers/import/github_groups_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/import/github_groups_controller.rb')
-rw-r--r--app/controllers/import/github_groups_controller.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/app/controllers/import/github_groups_controller.rb b/app/controllers/import/github_groups_controller.rb
new file mode 100644
index 00000000000..6c0773bcfb3
--- /dev/null
+++ b/app/controllers/import/github_groups_controller.rb
@@ -0,0 +1,57 @@
+# frozen_string_literal: true
+
+module Import
+ class GithubGroupsController < ApplicationController
+ include Import::GithubOauth
+
+ before_action :provider_auth, only: [:status]
+ feature_category :importers
+
+ PAGE_LENGTH = 25
+
+ def status
+ respond_to do |format|
+ format.json do
+ render json: { provider_groups: serialized_provider_groups }
+ end
+ end
+ end
+
+ private
+
+ def serialized_provider_groups
+ Import::GithubOrgSerializer.new.represent(importable_orgs)
+ end
+
+ def importable_orgs
+ client_orgs.to_a
+ end
+
+ def client_orgs
+ @client_orgs ||= client.octokit.organizations(nil, pagination_options)
+ end
+
+ def client
+ @client ||= Gitlab::GithubImport::Client.new(session[access_token_key])
+ end
+
+ def pagination_options
+ {
+ page: [1, params[:page].to_i].max,
+ per_page: PAGE_LENGTH
+ }
+ end
+
+ def auth_state_key
+ :"#{provider_name}_auth_state_key"
+ end
+
+ def access_token_key
+ :"#{provider_name}_access_token"
+ end
+
+ def provider_name
+ :github
+ end
+ end
+end