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
# File 'lib/gitload/sources/gitlab.rb', line 18

def repos

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

    projects = []

    Gitlab.projects(membership: true, per_page: 100).auto_paginate do |project|
      projects << project.to_h
    end

    Utils.stringify_keys(projects)
  end

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