class Scrutinizer::Ocular::RepositoryIntrospector
Public Class Methods
new(dir)
click to toggle source
# File lib/scrutinizer/ocular/repository_introspector.rb, line 6 def initialize(dir) @dir = dir end
Public Instance Methods
get_current_parents()
click to toggle source
# File lib/scrutinizer/ocular/repository_introspector.rb, line 30 def get_current_parents stdout, status = Open3.capture2('git log --pretty=%P -n1 HEAD', :chdir => @dir) raise 'Parents could not be determined' unless status.exitstatus == 0 output = stdout.to_s.strip if output.empty? return [] end output.split(' ') end
get_current_revision()
click to toggle source
# File lib/scrutinizer/ocular/repository_introspector.rb, line 43 def get_current_revision stdout, status = Open3.capture2('git rev-parse HEAD', :chdir => @dir) raise 'Revision could not be determined' unless status.exitstatus == 0 stdout.to_s.strip end
get_repository_name()
click to toggle source
# File lib/scrutinizer/ocular/repository_introspector.rb, line 10 def get_repository_name() stdout, status = Open3.capture2('git remote -v', :chdir => @dir) raise 'Repository name could not be determined' unless status.exitstatus == 0 output = stdout.to_s patterns = [ /^origin\s+(?:git@|(?:git|https?):\/\/)([^:\/]+)(?:\/|:)([^\/]+)\/([^\/\s]+?)(?:\.git)?(?:\s|\n)/, /^[^\s]+\s+(?:git@|(?:git|https?):\/\/)([^:\/]+)(?:\/|:)([^\/]+)\/([^\/\s]+?)(?:\.git)?(?:\s|\n)/, ] patterns.each { |pattern| if output =~ pattern return get_repository_type($1) + '/' + $2 + '/' + $3 end } raise "Could not determine repository. Please set the 'SCRUTINIZER_REPOSITORY' environment variable" end
Private Instance Methods
get_repository_type(host)
click to toggle source
# File lib/scrutinizer/ocular/repository_introspector.rb, line 52 def get_repository_type(host) if host == "github.com" return "g" elsif host == "bitbucket.org" return "b" end raise "Unknown host " + host end