Class: Gitload::Sources::GitLab

Inherits:
Object
  • Object
show all
Includes:
Source
Defined in:
lib/gitload/sources/gitlab.rb

Defined Under Namespace

Classes: Repo

Instance Method Summary collapse

Methods included from Source

included

Constructor Details

#initialize(config, options = {}) ⇒ GitLab

Returns a new instance of GitLab.



9
10
11
12
13
14
15
16
# File 'lib/gitload/sources/gitlab.rb', line 9

def initialize config, options = {}
  @config = config

  ::Gitlab.configure do |c|
    c.endpoint = 'https://gitlab.com/api/v4'
    c.private_token = options.fetch :private_token, ENV['GITLOAD_GITLAB_TOKEN']
  end
end

Instance Method Details

#reposObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gitload/sources/gitlab.rb', line 18

def repos

  puts 'Loading GitLab projects...'
  data = @config.load_or_cache_data 'gitlab' do

    page = 1
    projects = []

    res = Gitlab.projects(membership: true, per_page: 100)
    projects += res.collect(&:to_h)

    while res.has_next_page?
      page += 1
      puts "Loading GitLab projects (page #{page})..."
      projects += res.next_page.collect(&:to_h)
    end

    Utils.stringify_keys(projects)
  end

  data.collect{ |d| Repo.new d }
end