Module: PuppetfileResolver::SpecSearchers::Git

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

Class Method Summary collapse

Class Method Details

.find_all(puppetfile_module, dependency, cache, resolver_ui) ⇒ Object



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
58
59
60
61
# File 'lib/puppetfile-resolver/spec_searchers/git.rb', line 8

def self.find_all(puppetfile_module, dependency, cache, resolver_ui)
  dep_id = ::PuppetfileResolver::SpecSearchers::Common.dependency_cache_id(self, dependency)
  # Has the information been cached?
  return cache.load(dep_id) if cache.exist?(dep_id)

  # We _could_ git clone this, but it'll take too long. So for now, just
  # try and resolve github based repositories by crafting a URL

  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')
  end
  if 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 [] 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'

  require 'net/http'
  require 'uri'

  resolver_ui.debug { "Querying the Github with #{metadata_url}" }
  response = Net::HTTP.get_response(URI.parse())
  if response.code != '200'
    cache.save(dep_id, [])
    return []
  end

  # TODO: symbolise_object should be in a Util namespace
   = ::PuppetfileResolver::Util.symbolise_object(::JSON.parse(response.body))
  result = [Models::ModuleSpecification.new(
    name: [:name],
    origin: :git,
    version: [:version],
    metadata: 
  )]

  cache.save(dep_id, result)

  result
end