Class: Connectors::GitLab::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/connectors/gitlab/extractor.rb

Constant Summary collapse

PAGE_SIZE =

max is 100

100

Instance Method Summary collapse

Constructor Details

#initialize(base_url: nil, api_token: nil, owned_only: true) ⇒ Extractor

Returns a new instance of Extractor.



20
21
22
23
24
25
26
# File 'lib/connectors/gitlab/extractor.rb', line 20

def initialize(base_url: nil, api_token: nil, owned_only: true)
  super()
  @base_url = base_url
  @api_token = api_token
  # only get projects that user owns
  @owned_only = owned_only
end

Instance Method Details

#health_checkObject



54
55
56
57
58
59
60
# File 'lib/connectors/gitlab/extractor.rb', line 54

def health_check
  # let's do a simple call to get the current user
  response = client.get('user')
  unless response.present? && response.status == 200
    raise "Health check failed with response status #{response.status} and body #{response.body}"
  end
end

#yield_projects_page(next_page_link = nil) {|projects_chunk| ... } ⇒ Object

Yields:

  • (projects_chunk)


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
# File 'lib/connectors/gitlab/extractor.rb', line 28

def yield_projects_page(next_page_link = nil)
  query_params = {
    :pagination => :keyset,
    :per_page => PAGE_SIZE,
    :order_by => :id,
    :sort => :desc,
    :owned => @owned_only
  }

  if next_page_link.present?
    if (matcher = /(https?:[^>]*)/.match(next_page_link))
      clean_query = URI.parse(matcher.captures[0]).query
      query_params = Rack::Utils.parse_query(clean_query)
    else
      raise "Next page link has unexpected format: #{next_page_link}"
    end
  end
  response = client.get('projects', query_params)

  projects_chunk = JSON.parse(response.body)
  yield projects_chunk

  # return next link
  response.headers['Link'] || nil
end