Class: Codacy::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/codacy/git.rb

Class Method Summary collapse

Class Method Details

.commit_idObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/codacy/git.rb', line 3

def self.commit_id

  commit = ENV['TRAVIS_COMMIT'] ||
      ENV['DRONE_COMMIT'] ||
      ENV['GIT_COMMIT'] ||
      ENV['CIRCLE_SHA1'] ||
      ENV['CI_COMMIT_ID'] ||
      ENV['WERCKER_GIT_COMMIT'] ||
      ENV['HEROKU_TEST_RUN_COMMIT_VERSION'] ||
      ENV['CI_COMMIT_SHA'] ||
      ENV['COMMIT_SHA'] || # Google Cloud Build
      git_commit

  commit
end

.git(command) ⇒ Object



39
40
41
# File 'lib/codacy/git.rb', line 39

def self.git(command)
  `git --git-dir="#{git_dir}/.git" #{command}`
end

.git_commitObject



26
27
28
# File 'lib/codacy/git.rb', line 26

def self.git_commit
  git("log -1 --pretty=format:'%H'")
end

.git_dirObject



30
31
32
33
34
35
36
37
# File 'lib/codacy/git.rb', line 30

def self.git_dir
  dir = `git rev-parse --show-toplevel`
  if $?.to_i == 0
    return dir.strip!
  else
    return ''
  end
end

.work_dirObject



19
20
21
22
23
24
# File 'lib/codacy/git.rb', line 19

def self.work_dir
  work_dir = ENV['WORK_DIR'] ||
      ENV['TRAVIS_BUILD_DIR'] ||
      git_dir
  work_dir
end