datadog-ci 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +30 -0
  3. data/LICENSE +6 -0
  4. data/LICENSE-3rdparty.csv +2 -0
  5. data/LICENSE.Apache +200 -0
  6. data/LICENSE.BSD3 +24 -0
  7. data/NOTICE +4 -0
  8. data/README.md +125 -0
  9. data/lib/datadog/ci/configuration/components.rb +32 -0
  10. data/lib/datadog/ci/configuration/settings.rb +51 -0
  11. data/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +36 -0
  12. data/lib/datadog/ci/contrib/cucumber/ext.rb +22 -0
  13. data/lib/datadog/ci/contrib/cucumber/formatter.rb +94 -0
  14. data/lib/datadog/ci/contrib/cucumber/instrumentation.rb +28 -0
  15. data/lib/datadog/ci/contrib/cucumber/integration.rb +47 -0
  16. data/lib/datadog/ci/contrib/cucumber/patcher.rb +27 -0
  17. data/lib/datadog/ci/contrib/minitest/configuration/settings.rb +36 -0
  18. data/lib/datadog/ci/contrib/minitest/ext.rb +21 -0
  19. data/lib/datadog/ci/contrib/minitest/hooks.rb +66 -0
  20. data/lib/datadog/ci/contrib/minitest/integration.rb +46 -0
  21. data/lib/datadog/ci/contrib/minitest/patcher.rb +26 -0
  22. data/lib/datadog/ci/contrib/rspec/configuration/settings.rb +36 -0
  23. data/lib/datadog/ci/contrib/rspec/example.rb +70 -0
  24. data/lib/datadog/ci/contrib/rspec/ext.rb +21 -0
  25. data/lib/datadog/ci/contrib/rspec/integration.rb +50 -0
  26. data/lib/datadog/ci/contrib/rspec/patcher.rb +27 -0
  27. data/lib/datadog/ci/ext/app_types.rb +11 -0
  28. data/lib/datadog/ci/ext/environment/extractor.rb +101 -0
  29. data/lib/datadog/ci/ext/environment/providers/appveyor.rb +98 -0
  30. data/lib/datadog/ci/ext/environment/providers/azure.rb +109 -0
  31. data/lib/datadog/ci/ext/environment/providers/base.rb +115 -0
  32. data/lib/datadog/ci/ext/environment/providers/bitbucket.rb +69 -0
  33. data/lib/datadog/ci/ext/environment/providers/bitrise.rb +77 -0
  34. data/lib/datadog/ci/ext/environment/providers/buddy.rb +69 -0
  35. data/lib/datadog/ci/ext/environment/providers/buildkite.rb +95 -0
  36. data/lib/datadog/ci/ext/environment/providers/circleci.rb +82 -0
  37. data/lib/datadog/ci/ext/environment/providers/codefresh.rb +49 -0
  38. data/lib/datadog/ci/ext/environment/providers/github_actions.rb +76 -0
  39. data/lib/datadog/ci/ext/environment/providers/gitlab.rb +119 -0
  40. data/lib/datadog/ci/ext/environment/providers/jenkins.rb +74 -0
  41. data/lib/datadog/ci/ext/environment/providers/local_git.rb +170 -0
  42. data/lib/datadog/ci/ext/environment/providers/teamcity.rb +29 -0
  43. data/lib/datadog/ci/ext/environment/providers/travis.rb +65 -0
  44. data/lib/datadog/ci/ext/environment/providers/user_defined_tags.rb +62 -0
  45. data/lib/datadog/ci/ext/environment/providers.rb +52 -0
  46. data/lib/datadog/ci/ext/environment.rb +82 -0
  47. data/lib/datadog/ci/ext/git.rb +37 -0
  48. data/lib/datadog/ci/ext/settings.rb +12 -0
  49. data/lib/datadog/ci/ext/test.rb +37 -0
  50. data/lib/datadog/ci/extensions.rb +19 -0
  51. data/lib/datadog/ci/flush.rb +38 -0
  52. data/lib/datadog/ci/test.rb +82 -0
  53. data/lib/datadog/ci/utils/git.rb +22 -0
  54. data/lib/datadog/ci/version.rb +28 -0
  55. data/lib/datadog/ci.rb +24 -0
  56. data/sig/datadog/ci/configuration/components.rbs +11 -0
  57. data/sig/datadog/ci/configuration/settings.rbs +14 -0
  58. data/sig/datadog/ci/contrib/cucumber/configuration/settings.rbs +12 -0
  59. data/sig/datadog/ci/contrib/cucumber/ext.rbs +25 -0
  60. data/sig/datadog/ci/contrib/cucumber/formatter.rbs +35 -0
  61. data/sig/datadog/ci/contrib/cucumber/instrumentation.rbs +16 -0
  62. data/sig/datadog/ci/contrib/cucumber/integration.rbs +25 -0
  63. data/sig/datadog/ci/contrib/cucumber/patcher.rbs +15 -0
  64. data/sig/datadog/ci/contrib/minitest/configuration/settings.rbs +12 -0
  65. data/sig/datadog/ci/contrib/minitest/ext.rbs +23 -0
  66. data/sig/datadog/ci/contrib/minitest/hooks.rbs +19 -0
  67. data/sig/datadog/ci/contrib/minitest/integration.rbs +25 -0
  68. data/sig/datadog/ci/contrib/minitest/patcher.rbs +15 -0
  69. data/sig/datadog/ci/contrib/rspec/configuration/settings.rbs +12 -0
  70. data/sig/datadog/ci/contrib/rspec/example.rbs +20 -0
  71. data/sig/datadog/ci/contrib/rspec/ext.rbs +23 -0
  72. data/sig/datadog/ci/contrib/rspec/integration.rbs +25 -0
  73. data/sig/datadog/ci/contrib/rspec/patcher.rbs +15 -0
  74. data/sig/datadog/ci/ext/app_types.rbs +9 -0
  75. data/sig/datadog/ci/ext/environment/extractor.rbs +27 -0
  76. data/sig/datadog/ci/ext/environment/providers/appveyor.rbs +48 -0
  77. data/sig/datadog/ci/ext/environment/providers/azure.rbs +56 -0
  78. data/sig/datadog/ci/ext/environment/providers/base.rbs +69 -0
  79. data/sig/datadog/ci/ext/environment/providers/bitbucket.rbs +37 -0
  80. data/sig/datadog/ci/ext/environment/providers/bitrise.rbs +41 -0
  81. data/sig/datadog/ci/ext/environment/providers/buddy.rbs +37 -0
  82. data/sig/datadog/ci/ext/environment/providers/buildkite.rbs +45 -0
  83. data/sig/datadog/ci/ext/environment/providers/circleci.rbs +41 -0
  84. data/sig/datadog/ci/ext/environment/providers/codefresh.rbs +25 -0
  85. data/sig/datadog/ci/ext/environment/providers/github_actions.rbs +37 -0
  86. data/sig/datadog/ci/ext/environment/providers/gitlab.rbs +57 -0
  87. data/sig/datadog/ci/ext/environment/providers/jenkins.rbs +35 -0
  88. data/sig/datadog/ci/ext/environment/providers/local_git.rbs +66 -0
  89. data/sig/datadog/ci/ext/environment/providers/teamcity.rbs +17 -0
  90. data/sig/datadog/ci/ext/environment/providers/travis.rbs +35 -0
  91. data/sig/datadog/ci/ext/environment/providers/user_defined_tags.rbs +33 -0
  92. data/sig/datadog/ci/ext/environment/providers.rbs +13 -0
  93. data/sig/datadog/ci/ext/environment.rbs +44 -0
  94. data/sig/datadog/ci/ext/git.rbs +53 -0
  95. data/sig/datadog/ci/ext/settings.rbs +9 -0
  96. data/sig/datadog/ci/ext/test.rbs +43 -0
  97. data/sig/datadog/ci/extensions.rbs +7 -0
  98. data/sig/datadog/ci/flush.rbs +15 -0
  99. data/sig/datadog/ci/test.rbs +18 -0
  100. data/sig/datadog/ci/utils/git.rbs +11 -0
  101. data/sig/datadog/ci/version.rbs +16 -0
  102. data/sig/datadog/ci.rbs +7 -0
  103. metadata +154 -0
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ require_relative "base"
6
+
7
+ module Datadog
8
+ module CI
9
+ module Ext
10
+ module Environment
11
+ module Providers
12
+ # Github Actions: https://github.com/features/actions
13
+ # Environment variables docs: https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables
14
+ class GithubActions < Base
15
+ def provider_name
16
+ "github"
17
+ end
18
+
19
+ def job_name
20
+ env["GITHUB_JOB"]
21
+ end
22
+
23
+ def job_url
24
+ "#{env["GITHUB_SERVER_URL"]}/#{env["GITHUB_REPOSITORY"]}/commit/#{env["GITHUB_SHA"]}/checks"
25
+ end
26
+
27
+ def pipeline_id
28
+ env["GITHUB_RUN_ID"]
29
+ end
30
+
31
+ def pipeline_name
32
+ env["GITHUB_WORKFLOW"]
33
+ end
34
+
35
+ def pipeline_number
36
+ env["GITHUB_RUN_NUMBER"]
37
+ end
38
+
39
+ def pipeline_url
40
+ res = "#{env["GITHUB_SERVER_URL"]}/#{env["GITHUB_REPOSITORY"]}/actions/runs/#{env["GITHUB_RUN_ID"]}"
41
+ res = "#{res}/attempts/#{env["GITHUB_RUN_ATTEMPT"]}" if env["GITHUB_RUN_ATTEMPT"]
42
+ res
43
+ end
44
+
45
+ def workspace_path
46
+ env["GITHUB_WORKSPACE"]
47
+ end
48
+
49
+ def git_repository_url
50
+ "#{env["GITHUB_SERVER_URL"]}/#{env["GITHUB_REPOSITORY"]}.git"
51
+ end
52
+
53
+ def git_commit_sha
54
+ env["GITHUB_SHA"]
55
+ end
56
+
57
+ def git_branch_or_tag
58
+ ref = env["GITHUB_HEAD_REF"]
59
+ ref = env["GITHUB_REF"] if ref.nil? || ref.empty?
60
+ ref
61
+ end
62
+
63
+ def ci_env_vars
64
+ {
65
+ "GITHUB_SERVER_URL" => env["GITHUB_SERVER_URL"],
66
+ "GITHUB_REPOSITORY" => env["GITHUB_REPOSITORY"],
67
+ "GITHUB_RUN_ID" => env["GITHUB_RUN_ID"],
68
+ "GITHUB_RUN_ATTEMPT" => env["GITHUB_RUN_ATTEMPT"]
69
+ }.reject { |_, v| v.nil? }.to_json
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module Datadog
6
+ module CI
7
+ module Ext
8
+ module Environment
9
+ module Providers
10
+ # Gitlab CI: https://docs.gitlab.com/ee/ci/
11
+ # Environment variables docs: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
12
+ class Gitlab < Base
13
+ def provider_name
14
+ "gitlab"
15
+ end
16
+
17
+ def job_name
18
+ env["CI_JOB_NAME"]
19
+ end
20
+
21
+ def job_url
22
+ env["CI_JOB_URL"]
23
+ end
24
+
25
+ def pipeline_id
26
+ env["CI_PIPELINE_ID"]
27
+ end
28
+
29
+ def pipeline_name
30
+ env["CI_PROJECT_PATH"]
31
+ end
32
+
33
+ def pipeline_number
34
+ env["CI_PIPELINE_IID"]
35
+ end
36
+
37
+ def pipeline_url
38
+ env["CI_PIPELINE_URL"]
39
+ end
40
+
41
+ def stage_name
42
+ env["CI_JOB_STAGE"]
43
+ end
44
+
45
+ def workspace_path
46
+ env["CI_PROJECT_DIR"]
47
+ end
48
+
49
+ def node_name
50
+ env["CI_RUNNER_ID"]
51
+ end
52
+
53
+ def node_labels
54
+ env["CI_RUNNER_TAGS"]
55
+ end
56
+
57
+ def git_repository_url
58
+ env["CI_REPOSITORY_URL"]
59
+ end
60
+
61
+ def git_commit_sha
62
+ env["CI_COMMIT_SHA"]
63
+ end
64
+
65
+ def git_branch
66
+ env["CI_COMMIT_REF_NAME"]
67
+ end
68
+
69
+ def git_tag
70
+ env["CI_COMMIT_TAG"]
71
+ end
72
+
73
+ def git_commit_author_name
74
+ name, _ = extract_name_email
75
+ name
76
+ end
77
+
78
+ def git_commit_author_email
79
+ _, email = extract_name_email
80
+ email
81
+ end
82
+
83
+ def git_commit_author_date
84
+ env["CI_COMMIT_TIMESTAMP"]
85
+ end
86
+
87
+ def git_commit_message
88
+ env["CI_COMMIT_MESSAGE"]
89
+ end
90
+
91
+ def ci_env_vars
92
+ {
93
+ "CI_PROJECT_URL" => env["CI_PROJECT_URL"],
94
+ "CI_PIPELINE_ID" => env["CI_PIPELINE_ID"],
95
+ "CI_JOB_ID" => env["CI_JOB_ID"]
96
+ }.to_json
97
+ end
98
+
99
+ private
100
+
101
+ def extract_name_email
102
+ return @name_email_tuple if defined?(@name_email_tuple)
103
+
104
+ name_and_email_string = env["CI_COMMIT_AUTHOR"]
105
+ if name_and_email_string.include?("<") && (match = /^([^<]*)<([^>]*)>$/.match(name_and_email_string))
106
+ name = match[1]
107
+ name = name.strip if name
108
+ email = match[2]
109
+ return @name_email_tuple = [name, email] if name && email
110
+ end
111
+
112
+ @name_email_tuple = [nil, name_and_email_string]
113
+ end
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ require_relative "base"
6
+ require_relative "../../../utils/git"
7
+
8
+ module Datadog
9
+ module CI
10
+ module Ext
11
+ module Environment
12
+ module Providers
13
+ # Jenkins: https://www.jenkins.io/
14
+ # Environment variables docs: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables
15
+ class Jenkins < Base
16
+ def provider_name
17
+ "jenkins"
18
+ end
19
+
20
+ def pipeline_id
21
+ env["BUILD_TAG"]
22
+ end
23
+
24
+ def pipeline_name
25
+ if (name = env["JOB_NAME"])
26
+ name = name.gsub("/#{Datadog::CI::Utils::Git.normalize_ref(git_branch)}", "") if git_branch
27
+ name = name.split("/").reject { |v| v.nil? || v.include?("=") }.join("/")
28
+ end
29
+ name
30
+ end
31
+
32
+ def pipeline_number
33
+ env["BUILD_NUMBER"]
34
+ end
35
+
36
+ def pipeline_url
37
+ env["BUILD_URL"]
38
+ end
39
+
40
+ def workspace_path
41
+ env["WORKSPACE"]
42
+ end
43
+
44
+ def node_name
45
+ env["NODE_NAME"]
46
+ end
47
+
48
+ def node_labels
49
+ env["NODE_LABELS"] && env["NODE_LABELS"].split.to_json
50
+ end
51
+
52
+ def git_repository_url
53
+ env["GIT_URL"] || env["GIT_URL_1"]
54
+ end
55
+
56
+ def git_commit_sha
57
+ env["GIT_COMMIT"]
58
+ end
59
+
60
+ def git_branch_or_tag
61
+ env["GIT_BRANCH"]
62
+ end
63
+
64
+ def ci_env_vars
65
+ {
66
+ "DD_CUSTOM_TRACE_ID" => env["DD_CUSTOM_TRACE_ID"]
67
+ }.to_json
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,170 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+
5
+ require_relative "base"
6
+ require_relative "../../git"
7
+
8
+ module Datadog
9
+ module CI
10
+ module Ext
11
+ module Environment
12
+ module Providers
13
+ # As a fallback we try to fetch git information from the local git repository
14
+ class LocalGit < Base
15
+ def git_repository_url
16
+ exec_git_command("git ls-remote --get-url")
17
+ rescue => e
18
+ Datadog.logger.debug(
19
+ "Unable to read git repository url: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
20
+ )
21
+ nil
22
+ end
23
+
24
+ def git_commit_sha
25
+ exec_git_command("git rev-parse HEAD")
26
+ rescue => e
27
+ Datadog.logger.debug(
28
+ "Unable to read git commit SHA: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
29
+ )
30
+ nil
31
+ end
32
+
33
+ def git_branch
34
+ exec_git_command("git rev-parse --abbrev-ref HEAD")
35
+ rescue => e
36
+ Datadog.logger.debug(
37
+ "Unable to read git branch: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
38
+ )
39
+ nil
40
+ end
41
+
42
+ def git_tag
43
+ exec_git_command("git tag --points-at HEAD")
44
+ rescue => e
45
+ Datadog.logger.debug(
46
+ "Unable to read git tag: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
47
+ )
48
+ nil
49
+ end
50
+
51
+ def git_commit_message
52
+ exec_git_command("git show -s --format=%s")
53
+ rescue => e
54
+ Datadog.logger.debug(
55
+ "Unable to read git commit message: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
56
+ )
57
+ nil
58
+ end
59
+
60
+ def git_commit_author_name
61
+ author.name
62
+ end
63
+
64
+ def git_commit_author_email
65
+ author.email
66
+ end
67
+
68
+ def git_commit_author_date
69
+ author.date
70
+ end
71
+
72
+ def git_commit_committer_name
73
+ committer.name
74
+ end
75
+
76
+ def git_commit_committer_email
77
+ committer.email
78
+ end
79
+
80
+ def git_commit_committer_date
81
+ committer.date
82
+ end
83
+
84
+ def workspace_path
85
+ exec_git_command("git rev-parse --show-toplevel")
86
+ rescue => e
87
+ Datadog.logger.debug(
88
+ "Unable to read git base directory: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
89
+ )
90
+ nil
91
+ end
92
+
93
+ private
94
+
95
+ def exec_git_command(cmd)
96
+ out, status = Open3.capture2e(cmd)
97
+
98
+ raise "Failed to run git command #{cmd}: #{out}" unless status.success?
99
+
100
+ out.strip! # There's always a "\n" at the end of the command output
101
+
102
+ return nil if out.empty?
103
+
104
+ out
105
+ end
106
+
107
+ def author
108
+ return @author if defined?(@author)
109
+
110
+ set_git_commit_users
111
+ @author
112
+ end
113
+
114
+ def committer
115
+ return @committer if defined?(@committer)
116
+
117
+ set_git_commit_users
118
+ @committer
119
+ end
120
+
121
+ def set_git_commit_users
122
+ # Get committer and author information in one command.
123
+ output = exec_git_command("git show -s --format='%an\t%ae\t%at\t%cn\t%ce\t%ct'")
124
+ unless output
125
+ Datadog.logger.debug(
126
+ "Unable to read git commit users: git command output is nil"
127
+ )
128
+ @author = @committer = NilUser.new
129
+ return
130
+ end
131
+
132
+ author_name, author_email, author_timestamp,
133
+ committer_name, committer_email, committer_timestamp = output.split("\t").each(&:strip!)
134
+
135
+ @author = GitUser.new(author_name, author_email, author_timestamp)
136
+ @committer = GitUser.new(committer_name, committer_email, committer_timestamp)
137
+ rescue => e
138
+ Datadog.logger.debug(
139
+ "Unable to read git commit users: #{e.class.name} #{e.message} at #{Array(e.backtrace).first}"
140
+ )
141
+ @author = @committer = NilUser.new
142
+ end
143
+
144
+ class GitUser
145
+ attr_reader :name, :email, :timestamp
146
+
147
+ def initialize(name, email, timestamp)
148
+ @name = name
149
+ @email = email
150
+ @timestamp = timestamp
151
+ end
152
+
153
+ def date
154
+ return nil if timestamp.nil?
155
+
156
+ Time.at(timestamp.to_i).utc.to_datetime.iso8601
157
+ end
158
+ end
159
+
160
+ class NilUser < GitUser
161
+ def initialize
162
+ super(nil, nil, nil)
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
168
+ end
169
+ end
170
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module Datadog
6
+ module CI
7
+ module Ext
8
+ module Environment
9
+ module Providers
10
+ # Teamcity: https://www.jetbrains.com/teamcity/
11
+ # Environment variables docs: https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html
12
+ class Teamcity < Base
13
+ def provider_name
14
+ "teamcity"
15
+ end
16
+
17
+ def job_name
18
+ env["TEAMCITY_BUILDCONF_NAME"]
19
+ end
20
+
21
+ def job_url
22
+ env["BUILD_URL"]
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+
5
+ module Datadog
6
+ module CI
7
+ module Ext
8
+ module Environment
9
+ module Providers
10
+ # Travis CI: https://www.travis-ci.com/
11
+ # Environment variables docs: https://docs.travis-ci.com/user/environment-variables#default-environment-variables
12
+ class Travis < Base
13
+ def provider_name
14
+ "travisci"
15
+ end
16
+
17
+ def job_url
18
+ env["TRAVIS_JOB_WEB_URL"]
19
+ end
20
+
21
+ def pipeline_id
22
+ env["TRAVIS_BUILD_ID"]
23
+ end
24
+
25
+ def pipeline_name
26
+ env["TRAVIS_REPO_SLUG"]
27
+ end
28
+
29
+ def pipeline_number
30
+ env["TRAVIS_BUILD_NUMBER"]
31
+ end
32
+
33
+ def pipeline_url
34
+ env["TRAVIS_BUILD_WEB_URL"]
35
+ end
36
+
37
+ def workspace_path
38
+ env["TRAVIS_BUILD_DIR"]
39
+ end
40
+
41
+ def git_repository_url
42
+ "https://github.com/#{env["TRAVIS_REPO_SLUG"]}.git"
43
+ end
44
+
45
+ def git_commit_sha
46
+ env["TRAVIS_COMMIT"]
47
+ end
48
+
49
+ def git_branch
50
+ env["TRAVIS_PULL_REQUEST_BRANCH"] || env["TRAVIS_BRANCH"]
51
+ end
52
+
53
+ def git_tag
54
+ env["TRAVIS_TAG"]
55
+ end
56
+
57
+ def git_commit_message
58
+ env["TRAVIS_COMMIT_MESSAGE"]
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base"
4
+ require_relative "../../git"
5
+
6
+ module Datadog
7
+ module CI
8
+ module Ext
9
+ module Environment
10
+ module Providers
11
+ # Parses user defined git data from the environment variables
12
+ # User documentation: https://docs.datadoghq.com/continuous_integration/troubleshooting/#data-appears-in-test-runs-but-not-tests
13
+ class UserDefinedTags < Base
14
+ def git_repository_url
15
+ env[Git::ENV_REPOSITORY_URL]
16
+ end
17
+
18
+ def git_commit_sha
19
+ env[Git::ENV_COMMIT_SHA]
20
+ end
21
+
22
+ def git_branch
23
+ env[Git::ENV_BRANCH]
24
+ end
25
+
26
+ def git_tag
27
+ env[Git::ENV_TAG]
28
+ end
29
+
30
+ def git_commit_message
31
+ env[Git::ENV_COMMIT_MESSAGE]
32
+ end
33
+
34
+ def git_commit_author_name
35
+ env[Git::ENV_COMMIT_AUTHOR_NAME]
36
+ end
37
+
38
+ def git_commit_author_email
39
+ env[Git::ENV_COMMIT_AUTHOR_EMAIL]
40
+ end
41
+
42
+ def git_commit_author_date
43
+ env[Git::ENV_COMMIT_AUTHOR_DATE]
44
+ end
45
+
46
+ def git_commit_committer_name
47
+ env[Git::ENV_COMMIT_COMMITTER_NAME]
48
+ end
49
+
50
+ def git_commit_committer_email
51
+ env[Git::ENV_COMMIT_COMMITTER_EMAIL]
52
+ end
53
+
54
+ def git_commit_committer_date
55
+ env[Git::ENV_COMMIT_COMMITTER_DATE]
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "providers/base"
4
+ require_relative "providers/appveyor"
5
+ require_relative "providers/azure"
6
+ require_relative "providers/bitbucket"
7
+ require_relative "providers/bitrise"
8
+ require_relative "providers/buddy"
9
+ require_relative "providers/buildkite"
10
+ require_relative "providers/circleci"
11
+ require_relative "providers/codefresh"
12
+ require_relative "providers/github_actions"
13
+ require_relative "providers/gitlab"
14
+ require_relative "providers/jenkins"
15
+ require_relative "providers/teamcity"
16
+ require_relative "providers/travis"
17
+
18
+ require_relative "providers/local_git"
19
+ require_relative "providers/user_defined_tags"
20
+
21
+ module Datadog
22
+ module CI
23
+ module Ext
24
+ module Environment
25
+ module Providers
26
+ PROVIDERS = [
27
+ ["APPVEYOR", Providers::Appveyor],
28
+ ["TF_BUILD", Providers::Azure],
29
+ ["BITBUCKET_COMMIT", Providers::Bitbucket],
30
+ ["BITRISE_BUILD_SLUG", Providers::Bitrise],
31
+ ["BUDDY", Providers::Buddy],
32
+ ["BUILDKITE", Providers::Buildkite],
33
+ ["CIRCLECI", Providers::Circleci],
34
+ ["CF_BUILD_ID", Providers::Codefresh],
35
+ ["GITHUB_SHA", Providers::GithubActions],
36
+ ["GITLAB_CI", Providers::Gitlab],
37
+ ["JENKINS_URL", Providers::Jenkins],
38
+ ["TEAMCITY_VERSION", Providers::Teamcity],
39
+ ["TRAVIS", Providers::Travis]
40
+ ]
41
+
42
+ def self.for_environment(env)
43
+ _, provider_klass = PROVIDERS.find { |provider_env_var, _| env.key?(provider_env_var) }
44
+ provider_klass = Providers::Base if provider_klass.nil?
45
+
46
+ provider_klass.new(env)
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end