Class: ManageIQ::CrossRepo::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/manageiq/cross_repo/repository.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier, server: "https://github.com") ⇒ Repository

ManageIQ::CrossRepo::Repository

Examples:

Repostory.new("ManageIQ/manageiq@master", server: "https://github.com")

Parameters:

  • identifier (String)

    the short representation of a repository relative to a server, format [org/]repo

  • server (String) (defaults to: "https://github.com")

    The git repo server hosting this repository, default: github.com



14
15
16
17
18
# File 'lib/manageiq/cross_repo/repository.rb', line 14

def initialize(identifier, server: "https://github.com")
  @identifier = identifier
  @server     = server
  @org, @repo, @ref, @sha, @url, @path = parse_identifier
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



5
6
7
# File 'lib/manageiq/cross_repo/repository.rb', line 5

def identifier
  @identifier
end

#orgObject (readonly)

Returns the value of attribute org.



6
7
8
# File 'lib/manageiq/cross_repo/repository.rb', line 6

def org
  @org
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/manageiq/cross_repo/repository.rb', line 6

def path
  @path
end

#refObject (readonly)

Returns the value of attribute ref.



6
7
8
# File 'lib/manageiq/cross_repo/repository.rb', line 6

def ref
  @ref
end

#repoObject (readonly)

Returns the value of attribute repo.



6
7
8
# File 'lib/manageiq/cross_repo/repository.rb', line 6

def repo
  @repo
end

#serverObject (readonly)

Returns the value of attribute server.



5
6
7
# File 'lib/manageiq/cross_repo/repository.rb', line 5

def server
  @server
end

#shaObject (readonly)

Returns the value of attribute sha.



6
7
8
# File 'lib/manageiq/cross_repo/repository.rb', line 6

def sha
  @sha
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/manageiq/cross_repo/repository.rb', line 6

def url
  @url
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
# File 'lib/manageiq/cross_repo/repository.rb', line 24

def ==(other)
  repo == other.repo && sha == other.sha
end

#core?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/manageiq/cross_repo/repository.rb', line 20

def core?
  repo.casecmp("manageiq") == 0
end

#ensure_cloneObject



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
# File 'lib/manageiq/cross_repo/repository.rb', line 28

def ensure_clone
  return if path.exist?

  require "mixlib/archive"
  require "open-uri"
  require "tmpdir"
  require "zlib"

  retries ||= 0

  puts "Fetching #{tarball_url}#{retry_count(retries)}"

  Dir.mktmpdir do |dir|
    Mixlib::Archive.new(open_tarball_url(tarball_url)).extract(dir)

    content_dir = Pathname.new(dir).children.detect(&:directory?)
    FileUtils.mkdir_p(path.dirname)
    FileUtils.mv(content_dir, path)
  end
rescue => e
  retries += 1
  raise if retries > 3

  sleep 1
  retry
end