Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github_groups_controller.rb « import « controllers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6c0773bcfb3da2b79879fcd96606325699b5013a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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