Class: Quaker::GitResolver
- Inherits:
-
Object
- Object
- Quaker::GitResolver
- Defined in:
- lib/quaker/git_resolver.rb
Instance Method Summary collapse
- #find_dir_for_repo(repo) ⇒ Object
-
#parse_url(url) ⇒ Object
Parses repository url to { username: …, repository: …}.
- #resolve(services_map) ⇒ Object
Instance Method Details
#find_dir_for_repo(repo) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/quaker/git_resolver.rb', line 19 def find_dir_for_repo repo dir = Dir.glob('*') .select {|f| File.directory? f} .select {|dir| stdin, stdout, stderr = Open3.popen3("cd #{dir} && git remote -v | awk '{print $2}'") stdout.each_line .map(&:strip) .map {|l| parse_url(l) } .include?(parse_url(repo)) } .first return nil unless dir "./#{dir}" end |
#parse_url(url) ⇒ Object
Parses repository url to { username: …, repository: …}
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/quaker/git_resolver.rb', line 7 def parse_url url begin uri = GitCloneUrl.parse(url) if uri.path.match /^\/?(.*?)\/(.*?)(.git)?$/ return { username: $1, repo: $2 } end rescue URI::InvalidComponentError => ex end url end |
#resolve(services_map) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/quaker/git_resolver.rb', line 34 def resolve services_map for name, spec in services_map git_repo = spec.delete("git") next unless git_repo dir = find_dir_for_repo git_repo $stderr.puts "ERROR: Unable to find dir for repo #{git_repo}" and return unless dir spec["build"] = dir end services_map end |