diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 09:40:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 09:40:42 +0000 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /app/controllers/import/github_groups_controller.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) | |
download | gitlab-ce-ee664acb356f8123f4f6b00b73c1e1cf0866c7fb.tar.gz |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'app/controllers/import/github_groups_controller.rb')
-rw-r--r-- | app/controllers/import/github_groups_controller.rb | 57 |
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 |