Class: Scrutinizer::Ocular::RepositoryIntrospector
- Inherits:
-
Object
- Object
- Scrutinizer::Ocular::RepositoryIntrospector
- Defined in:
- lib/scrutinizer/ocular/repository_introspector.rb
Instance Method Summary collapse
- #get_current_parents ⇒ Object
- #get_current_revision ⇒ Object
- #get_repository_name ⇒ Object
-
#initialize(dir) ⇒ RepositoryIntrospector
constructor
A new instance of RepositoryIntrospector.
Constructor Details
#initialize(dir) ⇒ RepositoryIntrospector
6 7 8 |
# File 'lib/scrutinizer/ocular/repository_introspector.rb', line 6 def initialize(dir) @dir = dir end |
Instance Method Details
#get_current_parents ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 ⇒ Object
43 44 45 46 47 48 49 |
# 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 ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 |