Class: Datadog::CI::Ext::Environment::Providers::LocalGit

Inherits:
Base
  • Object
show all
Defined in:
lib/datadog/ci/ext/environment/providers/local_git.rb

Overview

As a fallback we try to fetch git information from the local git repository

Defined Under Namespace

Classes: GitUser, NilUser

Instance Attribute Summary

Attributes inherited from Base

#env

Instance Method Summary collapse

Methods inherited from Base

#ci_env_vars, #git_branch_or_tag, handles?, #initialize, #job_name, #job_url, #node_labels, #node_name, #pipeline_id, #pipeline_name, #pipeline_number, #pipeline_url, #provider_name, #stage_name

Constructor Details

This class inherits a constructor from Datadog::CI::Ext::Environment::Providers::Base

Instance Method Details

#git_branchObject



31
32
33
34
35
36
37
38
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 31

def git_branch
  Utils::Git.exec_git_command("git rev-parse --abbrev-ref HEAD")
rescue => e
  Datadog.logger.debug(
    "Unable to read git branch: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
  )
  nil
end

#git_commit_author_dateObject



66
67
68
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 66

def git_commit_author_date
  author.date
end

#git_commit_author_emailObject



62
63
64
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 62

def git_commit_author_email
  author.email
end

#git_commit_author_nameObject



58
59
60
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 58

def git_commit_author_name
  author.name
end

#git_commit_committer_dateObject



78
79
80
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 78

def git_commit_committer_date
  committer.date
end

#git_commit_committer_emailObject



74
75
76
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 74

def git_commit_committer_email
  committer.email
end

#git_commit_committer_nameObject



70
71
72
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 70

def git_commit_committer_name
  committer.name
end

#git_commit_messageObject



49
50
51
52
53
54
55
56
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 49

def git_commit_message
  Utils::Git.exec_git_command("git show -s --format=%s")
rescue => e
  Datadog.logger.debug(
    "Unable to read git commit message: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
  )
  nil
end

#git_commit_shaObject



22
23
24
25
26
27
28
29
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 22

def git_commit_sha
  Utils::Git.exec_git_command("git rev-parse HEAD")
rescue => e
  Datadog.logger.debug(
    "Unable to read git commit SHA: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
  )
  nil
end

#git_repository_urlObject



13
14
15
16
17
18
19
20
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 13

def git_repository_url
  Utils::Git.exec_git_command("git ls-remote --get-url")
rescue => e
  Datadog.logger.debug(
    "Unable to read git repository url: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
  )
  nil
end

#git_tagObject



40
41
42
43
44
45
46
47
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 40

def git_tag
  Utils::Git.exec_git_command("git tag --points-at HEAD")
rescue => e
  Datadog.logger.debug(
    "Unable to read git tag: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
  )
  nil
end

#workspace_pathObject



82
83
84
85
86
87
88
89
# File 'lib/datadog/ci/ext/environment/providers/local_git.rb', line 82

def workspace_path
  Utils::Git.exec_git_command("git rev-parse --show-toplevel")
rescue => e
  Datadog.logger.debug(
    "Unable to read git base directory: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
  )
  nil
end