Module: PuppetfileResolver::SpecSearchers::Git::GitHub

Defined in:
lib/puppetfile-resolver/spec_searchers/git/github.rb

Class Method Summary collapse

Class Method Details

.metadata(puppetfile_module, resolver_ui, config) ⇒ Object



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
# File 'lib/puppetfile-resolver/spec_searchers/git/github.rb', line 11

def self.(puppetfile_module, resolver_ui, config)
  repo_url = nil
  if puppetfile_module.remote.start_with?('[email protected]:')
    repo_url = puppetfile_module.remote.slice(15..-1)
    repo_url = repo_url.slice(0..-5) if repo_url.end_with?('.git')
  elsif puppetfile_module.remote.start_with?('https://github.com/')
    repo_url = puppetfile_module.remote.slice(19..-1)
    repo_url = repo_url.slice(0..-5) if repo_url.end_with?('.git')
  end
  return nil if repo_url.nil?

   = 'https://raw.githubusercontent.com/' + repo_url + '/'
  if puppetfile_module.ref
     += puppetfile_module.ref + '/'
  elsif puppetfile_module.tag
     += puppetfile_module.tag + '/'
  else
    # Default to master. Should it raise?
     += 'master/'
  end
   += 'metadata.json'

  resolver_ui.debug { "Querying GitHub with #{}" }
  err_msg = "Unable to find module at #{puppetfile_module.remote}"
  err_msg += config.proxy ? " with proxy #{config.proxy}: " : ': '
  response = nil

  begin
    response = ::PuppetfileResolver::Util.net_http_get(, config.proxy)
  rescue ::StandardError => e
    raise err_msg + e.message
  end

  if response.code != '200'
    resolver_ui.debug(err_msg + "Expected HTTP Code 200, but received #{response.code}")
    return nil
  end
  response.body
end