From 87800a57950c01b29438c91afe8bd6c9b2edd597 Mon Sep 17 00:00:00 2001 From: Gustavo Caso Date: Wed, 6 Sep 2023 09:41:46 +0200 Subject: [PATCH] show alternative code organization around provider and extractor --- lib/datadog/ci/ext/environment.rb | 8 +- lib/datadog/ci/ext/environment/extractor.rb | 183 +++--------------- lib/datadog/ci/ext/environment/providers.rb | 49 +++++ .../ci/ext/environment/providers/appveyor.rb | 4 +- .../ci/ext/environment/providers/azure.rb | 4 +- .../ci/ext/environment/providers/base.rb | 110 +++++++++++ .../ci/ext/environment/providers/bitbucket.rb | 4 +- .../ci/ext/environment/providers/bitrise.rb | 4 +- .../ci/ext/environment/providers/buddy.rb | 4 +- .../ci/ext/environment/providers/buildkite.rb | 4 +- .../ci/ext/environment/providers/circleci.rb | 4 +- .../ci/ext/environment/providers/codefresh.rb | 4 +- .../ci/ext/environment/providers/default.rb | 4 +- .../environment/providers/github_actions.rb | 4 +- .../ci/ext/environment/providers/gitlab.rb | 4 +- .../ci/ext/environment/providers/jenkins.rb | 4 +- .../environment/{ => providers}/local_git.rb | 6 +- .../ci/ext/environment/providers/teamcity.rb | 4 +- .../ci/ext/environment/providers/travis.rb | 4 +- .../providers/user_defined_tags.rb | 64 ++++++ .../ci/ext/environment/user_defined_tags.rb | 62 ------ 21 files changed, 283 insertions(+), 255 deletions(-) create mode 100644 lib/datadog/ci/ext/environment/providers.rb create mode 100644 lib/datadog/ci/ext/environment/providers/base.rb rename lib/datadog/ci/ext/environment/{ => providers}/local_git.rb (98%) create mode 100644 lib/datadog/ci/ext/environment/providers/user_defined_tags.rb delete mode 100644 lib/datadog/ci/ext/environment/user_defined_tags.rb diff --git a/lib/datadog/ci/ext/environment.rb b/lib/datadog/ci/ext/environment.rb index 3b2c2114..dde5c7fe 100644 --- a/lib/datadog/ci/ext/environment.rb +++ b/lib/datadog/ci/ext/environment.rb @@ -2,8 +2,6 @@ require_relative "git" require_relative "environment/extractor" -require_relative "environment/user_defined_tags" -require_relative "environment/local_git" module Datadog module CI @@ -29,15 +27,15 @@ module Environment def tags(env) # Extract metadata from CI provider environment variables - tags = Environment::Extractor.for_environment(env).tags + tags = Environment::Extractor.new(env).tags # If user defined metadata is defined, overwrite tags.merge!( - UserDefinedTags.new(env).tags + Environment::Extractor.new(env, provider: Providers::UserDefinedTags).tags ) # Fill out tags from local git as fallback - local_git_tags = LocalGit.new(env).tags + local_git_tags = Environment::Extractor.new(env, provider: LocalGit).tags local_git_tags.each do |key, value| tags[key] ||= value end diff --git a/lib/datadog/ci/ext/environment/extractor.rb b/lib/datadog/ci/ext/environment/extractor.rb index 354093fb..0fb7a337 100644 --- a/lib/datadog/ci/ext/environment/extractor.rb +++ b/lib/datadog/ci/ext/environment/extractor.rb @@ -2,6 +2,7 @@ require_relative "../environment" require_relative "../git" +require_relative "providers" module Datadog module CI @@ -11,76 +12,39 @@ module Environment # Extractor is responsible for detecting where pipeline is being executed based on environment vars # and return the specific extractor that is able to return environment- and git-specific tags class Extractor - require_relative "providers/default" - require_relative "providers/appveyor" - require_relative "providers/azure" - require_relative "providers/bitbucket" - require_relative "providers/bitrise" - require_relative "providers/buddy" - require_relative "providers/buildkite" - require_relative "providers/circleci" - require_relative "providers/codefresh" - require_relative "providers/github_actions" - require_relative "providers/gitlab" - require_relative "providers/jenkins" - require_relative "providers/teamcity" - require_relative "providers/travis" - - PROVIDERS = [ - ["APPVEYOR", Providers::Appveyor], - ["TF_BUILD", Providers::Azure], - ["BITBUCKET_COMMIT", Providers::Bitbucket], - ["BITRISE_BUILD_SLUG", Providers::Bitrise], - ["BUDDY", Providers::Buddy], - ["BUILDKITE", Providers::Buildkite], - ["CIRCLECI", Providers::Circleci], - ["CF_BUILD_ID", Providers::Codefresh], - ["GITHUB_SHA", Providers::GithubActions], - ["GITLAB_CI", Providers::Gitlab], - ["JENKINS_URL", Providers::Jenkins], - ["TEAMCITY_VERSION", Providers::Teamcity], - ["TRAVIS", Providers::Travis] - ] - - def self.for_environment(env) - _, extractor_klass = PROVIDERS.find { |provider_env_var, _| env.key?(provider_env_var) } - extractor_klass = Providers::Default if extractor_klass.nil? - - extractor_klass.new(env) - end - def initialize(env) @env = env + @provider = Providers.for_environment(env) end def tags return @tags if defined?(@tags) @tags = { - Environment::TAG_JOB_NAME => job_name, - Environment::TAG_JOB_URL => job_url, - Environment::TAG_PIPELINE_ID => pipeline_id, - Environment::TAG_PIPELINE_NAME => pipeline_name, - Environment::TAG_PIPELINE_NUMBER => pipeline_number, - Environment::TAG_PIPELINE_URL => pipeline_url, - Environment::TAG_PROVIDER_NAME => provider_name, - Environment::TAG_STAGE_NAME => stage_name, - Environment::TAG_WORKSPACE_PATH => workspace_path, - Environment::TAG_NODE_LABELS => node_labels, - Environment::TAG_NODE_NAME => node_name, - Environment::TAG_CI_ENV_VARS => ci_env_vars, - - Git::TAG_BRANCH => git_branch, - Git::TAG_REPOSITORY_URL => git_repository_url, - Git::TAG_TAG => git_tag, - Git::TAG_COMMIT_AUTHOR_DATE => git_commit_author_date, - Git::TAG_COMMIT_AUTHOR_EMAIL => git_commit_author_email, - Git::TAG_COMMIT_AUTHOR_NAME => git_commit_author_name, - Git::TAG_COMMIT_COMMITTER_DATE => git_commit_committer_date, - Git::TAG_COMMIT_COMMITTER_EMAIL => git_commit_committer_email, - Git::TAG_COMMIT_COMMITTER_NAME => git_commit_committer_name, - Git::TAG_COMMIT_MESSAGE => git_commit_message, - Git::TAG_COMMIT_SHA => git_commit_sha + Environment::TAG_JOB_NAME => @provider.job_name, + Environment::TAG_JOB_URL => @provider.job_url, + Environment::TAG_PIPELINE_ID => @provider.pipeline_id, + Environment::TAG_PIPELINE_NAME => @provider.pipeline_name, + Environment::TAG_PIPELINE_NUMBER => @provider.pipeline_number, + Environment::TAG_PIPELINE_URL => @provider.pipeline_url, + Environment::TAG_PROVIDER_NAME => @provider.provider_name, + Environment::TAG_STAGE_NAME => @provider.stage_name, + Environment::TAG_WORKSPACE_PATH => @provider.workspace_path, + Environment::TAG_NODE_LABELS => @provider.node_labels, + Environment::TAG_NODE_NAME => @provider.node_name, + Environment::TAG_CI_ENV_VARS => @provider.ci_env_vars, + + Git::TAG_BRANCH => @provider.git_branch, + Git::TAG_REPOSITORY_URL => @provider.git_repository_url, + Git::TAG_TAG => @provider.git_tag, + Git::TAG_COMMIT_AUTHOR_DATE => @provider.git_commit_author_date, + Git::TAG_COMMIT_AUTHOR_EMAIL => @provider.git_commit_author_email, + Git::TAG_COMMIT_AUTHOR_NAME => @provider.git_commit_author_name, + Git::TAG_COMMIT_COMMITTER_DATE => @provider.git_commit_committer_date, + Git::TAG_COMMIT_COMMITTER_EMAIL => @provider.git_commit_committer_email, + Git::TAG_COMMIT_COMMITTER_NAME => @provider.git_commit_committer_name, + Git::TAG_COMMIT_MESSAGE => @provider.git_commit_message, + Git::TAG_COMMIT_SHA => @provider.git_commit_sha } # Normalize Git references and filter sensitive data @@ -102,88 +66,6 @@ def tags private - attr_reader :env - - def job_name - end - - def job_url - end - - def pipeline_id - end - - def pipeline_name - end - - def pipeline_number - end - - def pipeline_url - end - - def provider_name - end - - def stage_name - end - - def workspace_path - end - - def node_labels - end - - def node_name - end - - def ci_env_vars - end - - def git_branch - return @branch if defined?(@branch) - - set_branch_and_tag - @branch - end - - def git_repository_url - end - - def git_tag - return @tag if defined?(@tag) - - set_branch_and_tag - @tag - end - - def git_branch_or_tag - end - - def git_commit_author_date - end - - def git_commit_author_email - end - - def git_commit_author_name - end - - def git_commit_committer_date - end - - def git_commit_committer_email - end - - def git_commit_committer_name - end - - def git_commit_message - end - - def git_commit_sha - end - def normalize_git! branch_ref = @tags[Git::TAG_BRANCH] if is_git_tag?(branch_ref) @@ -210,19 +92,6 @@ def is_git_tag?(ref) !ref.nil? && ref.include?("tags/") end - def set_branch_and_tag - branch_or_tag_string = git_branch_or_tag - @branch = @tag = nil - - if branch_or_tag_string && branch_or_tag_string.include?("tags/") - @tag = branch_or_tag_string - else - @branch = branch_or_tag_string - end - - [@branch, @tag] - end - def normalize_ref(name) return nil if name.nil? diff --git a/lib/datadog/ci/ext/environment/providers.rb b/lib/datadog/ci/ext/environment/providers.rb new file mode 100644 index 00000000..16ffe0d7 --- /dev/null +++ b/lib/datadog/ci/ext/environment/providers.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require_relative "providers/default" +require_relative "providers/appveyor" +require_relative "providers/azure" +require_relative "providers/bitbucket" +require_relative "providers/bitrise" +require_relative "providers/buddy" +require_relative "providers/buildkite" +require_relative "providers/circleci" +require_relative "providers/codefresh" +require_relative "providers/github_actions" +require_relative "providers/gitlab" +require_relative "providers/jenkins" +require_relative "providers/teamcity" +require_relative "providers/travis" + +module Datadog + module CI + module Ext + module Environment + module Providers + PROVIDERS = [ + ["APPVEYOR", Providers::Appveyor], + ["TF_BUILD", Providers::Azure], + ["BITBUCKET_COMMIT", Providers::Bitbucket], + ["BITRISE_BUILD_SLUG", Providers::Bitrise], + ["BUDDY", Providers::Buddy], + ["BUILDKITE", Providers::Buildkite], + ["CIRCLECI", Providers::Circleci], + ["CF_BUILD_ID", Providers::Codefresh], + ["GITHUB_SHA", Providers::GithubActions], + ["GITLAB_CI", Providers::Gitlab], + ["JENKINS_URL", Providers::Jenkins], + ["TEAMCITY_VERSION", Providers::Teamcity], + ["TRAVIS", Providers::Travis] + ] + + def self.for_environment(env) + _, provider_klass = PROVIDERS.find { |provider_env_var, _| env.key?(provider_env_var) } + provider_klass = Providers::Default if provider_klass.nil? + + provider_klass.new(env) + end + end + end + end + end +end diff --git a/lib/datadog/ci/ext/environment/providers/appveyor.rb b/lib/datadog/ci/ext/environment/providers/appveyor.rb index 26ea0aca..c7cca337 100644 --- a/lib/datadog/ci/ext/environment/providers/appveyor.rb +++ b/lib/datadog/ci/ext/environment/providers/appveyor.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -9,7 +9,7 @@ module Environment module Providers # Appveyor: https://www.appveyor.com/ # Environment variables docs: https://www.appveyor.com/docs/environment-variables/ - class Appveyor < Extractor + class Appveyor < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/azure.rb b/lib/datadog/ci/ext/environment/providers/azure.rb index 903a4625..da570cb6 100644 --- a/lib/datadog/ci/ext/environment/providers/azure.rb +++ b/lib/datadog/ci/ext/environment/providers/azure.rb @@ -2,7 +2,7 @@ require "json" -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -11,7 +11,7 @@ module Environment module Providers # Azure Pipelines: https://azure.microsoft.com/en-us/products/devops/pipelines # Environment variables docs: https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml - class Azure < Extractor + class Azure < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/base.rb b/lib/datadog/ci/ext/environment/providers/base.rb new file mode 100644 index 00000000..2c6e3eab --- /dev/null +++ b/lib/datadog/ci/ext/environment/providers/base.rb @@ -0,0 +1,110 @@ +module Datadog + module CI + module Ext + module Environment + module Providers + class Base + attr_reader :env + + def initialize(env) + @env = env + end + + def job_name + end + + def job_url + end + + def pipeline_id + end + + def pipeline_name + end + + def pipeline_number + end + + def pipeline_url + end + + def provider_name + end + + def stage_name + end + + def workspace_path + end + + def node_labels + end + + def node_name + end + + def ci_env_vars + end + + def git_branch + return @branch if defined?(@branch) + + set_branch_and_tag + @branch + end + + def git_repository_url + end + + def git_tag + return @tag if defined?(@tag) + + set_branch_and_tag + @tag + end + + def git_branch_or_tag + end + + def git_commit_author_date + end + + def git_commit_author_email + end + + def git_commit_author_name + end + + def git_commit_committer_date + end + + def git_commit_committer_email + end + + def git_commit_committer_name + end + + def git_commit_message + end + + def git_commit_sha + end + + def set_branch_and_tag + branch_or_tag_string = git_branch_or_tag + @branch = @tag = nil + + if branch_or_tag_string && branch_or_tag_string.include?("tags/") + @tag = branch_or_tag_string + else + @branch = branch_or_tag_string + end + + [@branch, @tag] + end + end + end + end + end + end +end diff --git a/lib/datadog/ci/ext/environment/providers/bitbucket.rb b/lib/datadog/ci/ext/environment/providers/bitbucket.rb index e6bc4fb7..e8350c73 100644 --- a/lib/datadog/ci/ext/environment/providers/bitbucket.rb +++ b/lib/datadog/ci/ext/environment/providers/bitbucket.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -9,7 +9,7 @@ module Environment module Providers # Bitbucket Pipelines: https://bitbucket.org/product/features/pipelines # Environment variables docs: https://support.atlassian.com/bitbucket-cloud/docs/variables-and-secrets/ - class Bitbucket < Extractor + class Bitbucket < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/bitrise.rb b/lib/datadog/ci/ext/environment/providers/bitrise.rb index 5bdba80f..bffdf499 100644 --- a/lib/datadog/ci/ext/environment/providers/bitrise.rb +++ b/lib/datadog/ci/ext/environment/providers/bitrise.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -9,7 +9,7 @@ module Environment module Providers # Bitrise: https://bitrise.io/ # Environment variables docs: https://devcenter.bitrise.io/en/references/available-environment-variables.html - class Bitrise < Extractor + class Bitrise < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/buddy.rb b/lib/datadog/ci/ext/environment/providers/buddy.rb index f2518a57..59a370de 100644 --- a/lib/datadog/ci/ext/environment/providers/buddy.rb +++ b/lib/datadog/ci/ext/environment/providers/buddy.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -9,7 +9,7 @@ module Environment module Providers # Buddy: https://buddy.works/ # Environment variables docs: https://buddy.works/docs/pipelines/environment-variables - class Buddy < Extractor + class Buddy < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/buildkite.rb b/lib/datadog/ci/ext/environment/providers/buildkite.rb index 6273a32b..6e6b9e93 100644 --- a/lib/datadog/ci/ext/environment/providers/buildkite.rb +++ b/lib/datadog/ci/ext/environment/providers/buildkite.rb @@ -2,7 +2,7 @@ require "json" -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -11,7 +11,7 @@ module Environment module Providers # Buildkite: https://buildkite.com/ # Environment variables docs: https://buildkite.com/docs/pipelines/environment-variables - class Buildkite < Extractor + class Buildkite < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/circleci.rb b/lib/datadog/ci/ext/environment/providers/circleci.rb index e8d06746..21471251 100644 --- a/lib/datadog/ci/ext/environment/providers/circleci.rb +++ b/lib/datadog/ci/ext/environment/providers/circleci.rb @@ -2,7 +2,7 @@ require "json" -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -11,7 +11,7 @@ module Environment module Providers # Circle CI: https://circleci.com/ # Environment variables docs: https://circleci.com/docs/variables/#built-in-environment-variables - class Circleci < Extractor + class Circleci < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/codefresh.rb b/lib/datadog/ci/ext/environment/providers/codefresh.rb index 5e29dc6a..8391756d 100644 --- a/lib/datadog/ci/ext/environment/providers/codefresh.rb +++ b/lib/datadog/ci/ext/environment/providers/codefresh.rb @@ -2,7 +2,7 @@ require "json" -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -11,7 +11,7 @@ module Environment module Providers # Codefresh: https://codefresh.io/ # Environment variables docs: https://codefresh.io/docs/docs/pipelines/variables/#export-variables-to-all-steps-with-cf_export - class Codefresh < Extractor + class Codefresh < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/default.rb b/lib/datadog/ci/ext/environment/providers/default.rb index 53864611..67b98312 100644 --- a/lib/datadog/ci/ext/environment/providers/default.rb +++ b/lib/datadog/ci/ext/environment/providers/default.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -8,7 +8,7 @@ module Ext module Environment module Providers # TODO - class Default < Extractor + class Default < Base def tags {} end diff --git a/lib/datadog/ci/ext/environment/providers/github_actions.rb b/lib/datadog/ci/ext/environment/providers/github_actions.rb index 18be6437..978ac1fe 100644 --- a/lib/datadog/ci/ext/environment/providers/github_actions.rb +++ b/lib/datadog/ci/ext/environment/providers/github_actions.rb @@ -2,7 +2,7 @@ require "json" -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -11,7 +11,7 @@ module Environment module Providers # Github Actions: https://github.com/features/actions # Environment variables docs: https://docs.github.com/en/actions/learn-github-actions/variables#default-environment-variables - class GithubActions < Extractor + class GithubActions < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/gitlab.rb b/lib/datadog/ci/ext/environment/providers/gitlab.rb index bad709cb..677a9f68 100644 --- a/lib/datadog/ci/ext/environment/providers/gitlab.rb +++ b/lib/datadog/ci/ext/environment/providers/gitlab.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -9,7 +9,7 @@ module Environment module Providers # Gitlab CI: https://docs.gitlab.com/ee/ci/ # Environment variables docs: https://docs.gitlab.com/ee/ci/variables/predefined_variables.html - class Gitlab < Extractor + class Gitlab < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/jenkins.rb b/lib/datadog/ci/ext/environment/providers/jenkins.rb index 28ce887e..4e7a7cc6 100644 --- a/lib/datadog/ci/ext/environment/providers/jenkins.rb +++ b/lib/datadog/ci/ext/environment/providers/jenkins.rb @@ -2,7 +2,7 @@ require "json" -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -11,7 +11,7 @@ module Environment module Providers # Jenkins: https://www.jenkins.io/ # Environment variables docs: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables - class Jenkins < Extractor + class Jenkins < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/local_git.rb b/lib/datadog/ci/ext/environment/providers/local_git.rb similarity index 98% rename from lib/datadog/ci/ext/environment/local_git.rb rename to lib/datadog/ci/ext/environment/providers/local_git.rb index 4b2e7bd3..3064783d 100644 --- a/lib/datadog/ci/ext/environment/local_git.rb +++ b/lib/datadog/ci/ext/environment/providers/local_git.rb @@ -2,15 +2,15 @@ require "open3" -require_relative "extractor" -require_relative "../git" +require_relative "base" +require_relative "../../git" module Datadog module CI module Ext module Environment # As a fallback we try to fetch git information from the local git repository - class LocalGit < Extractor + class LocalGit < Base private def git_repository_url diff --git a/lib/datadog/ci/ext/environment/providers/teamcity.rb b/lib/datadog/ci/ext/environment/providers/teamcity.rb index 80143942..9dd28cd0 100644 --- a/lib/datadog/ci/ext/environment/providers/teamcity.rb +++ b/lib/datadog/ci/ext/environment/providers/teamcity.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -9,7 +9,7 @@ module Environment module Providers # Teamcity: https://www.jetbrains.com/teamcity/ # Environment variables docs: https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html - class Teamcity < Extractor + class Teamcity < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/travis.rb b/lib/datadog/ci/ext/environment/providers/travis.rb index 4196e215..521b80b4 100644 --- a/lib/datadog/ci/ext/environment/providers/travis.rb +++ b/lib/datadog/ci/ext/environment/providers/travis.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../extractor" +require_relative "base" module Datadog module CI @@ -9,7 +9,7 @@ module Environment module Providers # Travis CI: https://www.travis-ci.com/ # Environment variables docs: https://docs.travis-ci.com/user/environment-variables#default-environment-variables - class Travis < Extractor + class Travis < Base private # overridden methods diff --git a/lib/datadog/ci/ext/environment/providers/user_defined_tags.rb b/lib/datadog/ci/ext/environment/providers/user_defined_tags.rb new file mode 100644 index 00000000..414a050c --- /dev/null +++ b/lib/datadog/ci/ext/environment/providers/user_defined_tags.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require_relative "base" +require_relative "../../git" + +module Datadog + module CI + module Ext + module Environment + module Providers + # Parses user defined git data from the environment variables + # User documentation: https://docs.datadoghq.com/continuous_integration/troubleshooting/#data-appears-in-test-runs-but-not-tests + class UserDefinedTags < Base + private + + def git_repository_url + env[Git::ENV_REPOSITORY_URL] + end + + def git_commit_sha + env[Git::ENV_COMMIT_SHA] + end + + def git_branch + env[Git::ENV_BRANCH] + end + + def git_tag + env[Git::ENV_TAG] + end + + def git_commit_message + env[Git::ENV_COMMIT_MESSAGE] + end + + def git_commit_author_name + env[Git::ENV_COMMIT_AUTHOR_NAME] + end + + def git_commit_author_email + env[Git::ENV_COMMIT_AUTHOR_EMAIL] + end + + def git_commit_author_date + env[Git::ENV_COMMIT_AUTHOR_DATE] + end + + def git_commit_committer_name + env[Git::ENV_COMMIT_COMMITTER_NAME] + end + + def git_commit_committer_email + env[Git::ENV_COMMIT_COMMITTER_EMAIL] + end + + def git_commit_committer_date + env[Git::ENV_COMMIT_COMMITTER_DATE] + end + end + end + end + end + end +end diff --git a/lib/datadog/ci/ext/environment/user_defined_tags.rb b/lib/datadog/ci/ext/environment/user_defined_tags.rb deleted file mode 100644 index 0f3e14d9..00000000 --- a/lib/datadog/ci/ext/environment/user_defined_tags.rb +++ /dev/null @@ -1,62 +0,0 @@ -# frozen_string_literal: true - -require_relative "extractor" -require_relative "../git" - -module Datadog - module CI - module Ext - module Environment - # Parses user defined git data from the environment variables - # User documentation: https://docs.datadoghq.com/continuous_integration/troubleshooting/#data-appears-in-test-runs-but-not-tests - class UserDefinedTags < Extractor - private - - def git_repository_url - env[Git::ENV_REPOSITORY_URL] - end - - def git_commit_sha - env[Git::ENV_COMMIT_SHA] - end - - def git_branch - env[Git::ENV_BRANCH] - end - - def git_tag - env[Git::ENV_TAG] - end - - def git_commit_message - env[Git::ENV_COMMIT_MESSAGE] - end - - def git_commit_author_name - env[Git::ENV_COMMIT_AUTHOR_NAME] - end - - def git_commit_author_email - env[Git::ENV_COMMIT_AUTHOR_EMAIL] - end - - def git_commit_author_date - env[Git::ENV_COMMIT_AUTHOR_DATE] - end - - def git_commit_committer_name - env[Git::ENV_COMMIT_COMMITTER_NAME] - end - - def git_commit_committer_email - env[Git::ENV_COMMIT_COMMITTER_EMAIL] - end - - def git_commit_committer_date - env[Git::ENV_COMMIT_COMMITTER_DATE] - end - end - end - end - end -end