From d01f763f4780f9f87b9d74b0e8a7034d26d9699b Mon Sep 17 00:00:00 2001 From: Andrey Marchenko Date: Fri, 1 Sep 2023 16:48:04 +0200 Subject: [PATCH] reshuffle code locations, extract Buddy extractor to a separate class --- lib/datadog/ci/ext/environment.rb | 23 +--- .../{providers => environment}/extractor.rb | 22 +-- .../ci/ext/environment/providers/appveyor.rb | 101 ++++++++++++++ .../ci/ext/environment/providers/azure.rb | 126 ++++++++++++++++++ .../ci/ext/environment/providers/bitbucket.rb | 71 ++++++++++ .../ci/ext/environment/providers/buddy.rb | 72 ++++++++++ .../ci/ext/environment/providers/default.rb | 20 +++ lib/datadog/ci/ext/providers/appveyor.rb | 99 -------------- lib/datadog/ci/ext/providers/azure.rb | 124 ----------------- lib/datadog/ci/ext/providers/bitbucket.rb | 70 ---------- lib/datadog/ci/ext/providers/default.rb | 18 --- .../{providers => environment}/extractor.rbs | 2 +- .../ci/ext/environment/providers/appveyor.rbs | 48 +++++++ .../ci/ext/environment/providers/azure.rbs | 60 +++++++++ .../ext/environment/providers/bitbucket.rbs | 36 +++++ .../ci/ext/environment/providers/buddy.rbs | 38 ++++++ .../ci/ext/environment/providers/default.rbs | 13 ++ sig/datadog/ci/ext/providers/appveyor.rbs | 46 ------- sig/datadog/ci/ext/providers/azure.rbs | 58 -------- sig/datadog/ci/ext/providers/bitbucket.rbs | 34 ----- sig/datadog/ci/ext/providers/default.rbs | 11 -- 21 files changed, 600 insertions(+), 492 deletions(-) rename lib/datadog/ci/ext/{providers => environment}/extractor.rb (85%) create mode 100644 lib/datadog/ci/ext/environment/providers/appveyor.rb create mode 100644 lib/datadog/ci/ext/environment/providers/azure.rb create mode 100644 lib/datadog/ci/ext/environment/providers/bitbucket.rb create mode 100644 lib/datadog/ci/ext/environment/providers/buddy.rb create mode 100644 lib/datadog/ci/ext/environment/providers/default.rb delete mode 100644 lib/datadog/ci/ext/providers/appveyor.rb delete mode 100644 lib/datadog/ci/ext/providers/azure.rb delete mode 100644 lib/datadog/ci/ext/providers/bitbucket.rb delete mode 100644 lib/datadog/ci/ext/providers/default.rb rename sig/datadog/ci/ext/{providers => environment}/extractor.rbs (98%) create mode 100644 sig/datadog/ci/ext/environment/providers/appveyor.rbs create mode 100644 sig/datadog/ci/ext/environment/providers/azure.rbs create mode 100644 sig/datadog/ci/ext/environment/providers/bitbucket.rbs create mode 100644 sig/datadog/ci/ext/environment/providers/buddy.rbs create mode 100644 sig/datadog/ci/ext/environment/providers/default.rbs delete mode 100644 sig/datadog/ci/ext/providers/appveyor.rbs delete mode 100644 sig/datadog/ci/ext/providers/azure.rbs delete mode 100644 sig/datadog/ci/ext/providers/bitbucket.rbs delete mode 100644 sig/datadog/ci/ext/providers/default.rbs diff --git a/lib/datadog/ci/ext/environment.rb b/lib/datadog/ci/ext/environment.rb index 8b650f05..a51e9ab6 100644 --- a/lib/datadog/ci/ext/environment.rb +++ b/lib/datadog/ci/ext/environment.rb @@ -4,7 +4,7 @@ require "json" require_relative "git" -require_relative "providers/extractor" +require_relative "environment/extractor" module Datadog module CI @@ -25,7 +25,6 @@ module Environment TAG_CI_ENV_VARS = "_dd.ci.env_vars" PROVIDERS = [ - ["BUDDY", :extract_buddy], ["BUILDKITE", :extract_buildkite], ["CIRCLECI", :extract_circle_ci], ["GITHUB_SHA", :extract_github_actions], @@ -42,7 +41,7 @@ module Environment def tags(env) # Extract metadata from CI provider environment variables _, extractor = PROVIDERS.find { |provider_env_var, _| env.key?(provider_env_var) } - tags = extractor ? public_send(extractor, env).reject { |_, v| v.nil? || v.strip.empty? } : Providers::Extractor.for_environment(env).tags + tags = extractor ? public_send(extractor, env).reject { |_, v| v.nil? || v.strip.empty? } : Environment::Extractor.for_environment(env).tags # If user defined metadata is defined, overwrite tags.merge!(extract_user_defined_git(env)) @@ -84,24 +83,6 @@ def filter_sensitive_info(url) end # CI providers - def extract_buddy(env) - { - TAG_PROVIDER_NAME => "buddy", - TAG_PIPELINE_ID => "#{env["BUDDY_PIPELINE_ID"]}/#{env["BUDDY_EXECUTION_ID"]}", - TAG_PIPELINE_NAME => env["BUDDY_PIPELINE_NAME"], - TAG_PIPELINE_NUMBER => env["BUDDY_EXECUTION_ID"], - TAG_PIPELINE_URL => env["BUDDY_EXECUTION_URL"], - TAG_WORKSPACE_PATH => env["CI_WORKSPACE_PATH"], - Git::TAG_REPOSITORY_URL => env["BUDDY_SCM_URL"], - Git::TAG_COMMIT_SHA => env["BUDDY_EXECUTION_REVISION"], - Git::TAG_BRANCH => env["BUDDY_EXECUTION_BRANCH"], - Git::TAG_TAG => env["BUDDY_EXECUTION_TAG"], - Git::TAG_COMMIT_MESSAGE => env["BUDDY_EXECUTION_REVISION_MESSAGE"], - Git::TAG_COMMIT_COMMITTER_NAME => env["BUDDY_EXECUTION_REVISION_COMMITTER_NAME"], - Git::TAG_COMMIT_COMMITTER_EMAIL => env["BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL"] - } - end - def extract_buildkite(env) tags = { Git::TAG_BRANCH => env["BUILDKITE_BRANCH"], diff --git a/lib/datadog/ci/ext/providers/extractor.rb b/lib/datadog/ci/ext/environment/extractor.rb similarity index 85% rename from lib/datadog/ci/ext/providers/extractor.rb rename to lib/datadog/ci/ext/environment/extractor.rb index 1ce2a7aa..5130b077 100644 --- a/lib/datadog/ci/ext/providers/extractor.rb +++ b/lib/datadog/ci/ext/environment/extractor.rb @@ -6,25 +6,27 @@ module Datadog module CI module Ext - module Providers + module Environment # Provider is a specific CI provider like Azure Pipelines, Github Actions, Gitlab CI, etc - # Providers::Extractor is responsible for detecting where pipeline is being executed based on environment vars + # 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 "default" - require_relative "appveyor" - require_relative "azure" - require_relative "bitbucket" + require_relative "providers/default" + require_relative "providers/appveyor" + require_relative "providers/azure" + require_relative "providers/bitbucket" + require_relative "providers/buddy" EXTRACTORS = [ - ["APPVEYOR", Appveyor], - ["TF_BUILD", Azure], - ["BITBUCKET_COMMIT", Bitbucket] + ["APPVEYOR", Providers::Appveyor], + ["TF_BUILD", Providers::Azure], + ["BITBUCKET_COMMIT", Providers::Bitbucket], + ["BUDDY", Providers::Buddy] ] def self.for_environment(env) _, extractor_klass = EXTRACTORS.find { |provider_env_var, _| env.key?(provider_env_var) } - extractor_klass = Default if extractor_klass.nil? + extractor_klass = Providers::Default if extractor_klass.nil? extractor_klass.new(env) end diff --git a/lib/datadog/ci/ext/environment/providers/appveyor.rb b/lib/datadog/ci/ext/environment/providers/appveyor.rb new file mode 100644 index 00000000..26ea0aca --- /dev/null +++ b/lib/datadog/ci/ext/environment/providers/appveyor.rb @@ -0,0 +1,101 @@ +# frozen_string_literal: true + +require_relative "../extractor" + +module Datadog + module CI + module Ext + module Environment + module Providers + # Appveyor: https://www.appveyor.com/ + # Environment variables docs: https://www.appveyor.com/docs/environment-variables/ + class Appveyor < Extractor + private + + # overridden methods + def provider_name + "appveyor" + end + + def pipeline_url + url + end + + def job_url + url + end + + def workspace_path + env["APPVEYOR_BUILD_FOLDER"] + end + + def pipeline_id + env["APPVEYOR_BUILD_ID"] + end + + def pipeline_name + env["APPVEYOR_REPO_NAME"] + end + + def pipeline_number + env["APPVEYOR_BUILD_NUMBER"] + end + + def git_repository_url + return nil unless github_repo_provider? + + "https://github.com/#{env["APPVEYOR_REPO_NAME"]}.git" + end + + def git_commit_sha + return nil unless github_repo_provider? + + env["APPVEYOR_REPO_COMMIT"] + end + + def git_branch + return nil unless github_repo_provider? + + env["APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH"] || env["APPVEYOR_REPO_BRANCH"] + end + + def git_tag + return nil unless github_repo_provider? + + env["APPVEYOR_REPO_TAG_NAME"] + end + + def git_commit_author_name + env["APPVEYOR_REPO_COMMIT_AUTHOR"] + end + + def git_commit_author_email + env["APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL"] + end + + def git_commit_message + commit_message = env["APPVEYOR_REPO_COMMIT_MESSAGE"] + if commit_message + extended = env["APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED"] + commit_message = "#{commit_message}\n#{extended}" if extended + end + commit_message + end + + # appveyor-specific methods + + def github_repo_provider? + return @github_repo_provider if defined?(@github_repo_provider) + + @github_repo_provider = env["APPVEYOR_REPO_PROVIDER"] == "github" + end + + def url + @url ||= "https://ci.appveyor.com/project/#{env["APPVEYOR_REPO_NAME"]}/builds/#{env["APPVEYOR_BUILD_ID"]}" + end + end + end + end + end + end +end diff --git a/lib/datadog/ci/ext/environment/providers/azure.rb b/lib/datadog/ci/ext/environment/providers/azure.rb new file mode 100644 index 00000000..38c83d9c --- /dev/null +++ b/lib/datadog/ci/ext/environment/providers/azure.rb @@ -0,0 +1,126 @@ +# frozen_string_literal: true + +require_relative "../extractor" + +module Datadog + module CI + module Ext + 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 + private + + # overridden methods + def provider_name + "azurepipelines" + end + + def pipeline_url + return unless url_defined? + + @pipeline_url ||= "#{team_foundation_server_uri}#{team_project_id}/_build/results?buildId=#{build_id}" + end + + def job_url + return unless url_defined? + + @job_url ||= "#{pipeline_url}&view=logs&j=#{env["SYSTEM_JOBID"]}&t=#{env["SYSTEM_TASKINSTANCEID"]}" + end + + def workspace_path + env["BUILD_SOURCESDIRECTORY"] + end + + def pipeline_id + build_id + end + + def pipeline_number + build_id + end + + def pipeline_name + env["BUILD_DEFINITIONNAME"] + end + + def stage_name + env["SYSTEM_STAGEDISPLAYNAME"] + end + + def job_name + env["SYSTEM_JOBDISPLAYNAME"] + end + + def git_repository_url + env["SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI"] || env["BUILD_REPOSITORY_URI"] + end + + def git_commit_sha + env["SYSTEM_PULLREQUEST_SOURCECOMMITID"] || env["BUILD_SOURCEVERSION"] + end + + def git_branch + return @branch if defined?(@branch) + + set_branch_and_tag + @branch + end + + def git_tag + return @tag if defined?(@tag) + + set_branch_and_tag + @tag + end + + def git_commit_author_name + env["BUILD_REQUESTEDFORID"] + end + + def git_commit_author_email + env["BUILD_REQUESTEDFOREMAIL"] + end + + def git_commit_message + env["BUILD_SOURCEVERSIONMESSAGE"] + end + + def ci_env_vars + { + "SYSTEM_TEAMPROJECTID" => env["SYSTEM_TEAMPROJECTID"], + "BUILD_BUILDID" => env["BUILD_BUILDID"], + "SYSTEM_JOBID" => env["SYSTEM_JOBID"] + }.to_json + end + + # azure-specific methods + + def build_id + env["BUILD_BUILDID"] + end + + def team_foundation_server_uri + env["SYSTEM_TEAMFOUNDATIONSERVERURI"] + end + + def team_project_id + env["SYSTEM_TEAMPROJECTID"] + end + + def url_defined? + !(build_id && team_foundation_server_uri && team_project_id).nil? + end + + def set_branch_and_tag + @branch, @tag = branch_or_tag( + env["SYSTEM_PULLREQUEST_SOURCEBRANCH"] || env["BUILD_SOURCEBRANCH"] || env["BUILD_SOURCEBRANCHNAME"] + ) + 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 new file mode 100644 index 00000000..e6bc4fb7 --- /dev/null +++ b/lib/datadog/ci/ext/environment/providers/bitbucket.rb @@ -0,0 +1,71 @@ +# frozen_string_literal: true + +require_relative "../extractor" + +module Datadog + module CI + module Ext + 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 + private + + # overridden methods + def provider_name + "bitbucket" + end + + def pipeline_id + env["BITBUCKET_PIPELINE_UUID"] ? env["BITBUCKET_PIPELINE_UUID"].tr("{}", "") : nil + end + + def pipeline_name + env["BITBUCKET_REPO_FULL_NAME"] + end + + def pipeline_number + env["BITBUCKET_BUILD_NUMBER"] + end + + def pipeline_url + url + end + + def job_url + url + end + + def workspace_path + env["BITBUCKET_CLONE_DIR"] + end + + def git_repository_url + env["BITBUCKET_GIT_SSH_ORIGIN"] || env["BITBUCKET_GIT_HTTP_ORIGIN"] + end + + def git_commit_sha + env["BITBUCKET_COMMIT"] + end + + def git_branch + env["BITBUCKET_BRANCH"] + end + + def git_tag + env["BITBUCKET_TAG"] + end + + # bitbucket-specific methods + + def url + "https://bitbucket.org/#{env["BITBUCKET_REPO_FULL_NAME"]}/addon/pipelines/home#" \ + "!/results/#{env["BITBUCKET_BUILD_NUMBER"]}" + end + end + end + end + end + end +end diff --git a/lib/datadog/ci/ext/environment/providers/buddy.rb b/lib/datadog/ci/ext/environment/providers/buddy.rb new file mode 100644 index 00000000..f2518a57 --- /dev/null +++ b/lib/datadog/ci/ext/environment/providers/buddy.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require_relative "../extractor" + +module Datadog + module CI + module Ext + module Environment + module Providers + # Buddy: https://buddy.works/ + # Environment variables docs: https://buddy.works/docs/pipelines/environment-variables + class Buddy < Extractor + private + + # overridden methods + def provider_name + "buddy" + end + + def pipeline_id + "#{env["BUDDY_PIPELINE_ID"]}/#{env["BUDDY_EXECUTION_ID"]}" + end + + def pipeline_name + env["BUDDY_PIPELINE_NAME"] + end + + def pipeline_number + env["BUDDY_EXECUTION_ID"] + end + + def pipeline_url + env["BUDDY_EXECUTION_URL"] + end + + def workspace_path + env["CI_WORKSPACE_PATH"] + end + + def git_repository_url + env["BUDDY_SCM_URL"] + end + + def git_commit_sha + env["BUDDY_EXECUTION_REVISION"] + end + + def git_branch + env["BUDDY_EXECUTION_BRANCH"] + end + + def git_tag + env["BUDDY_EXECUTION_TAG"] + end + + def git_commit_message + env["BUDDY_EXECUTION_REVISION_MESSAGE"] + end + + def git_commit_committer_name + env["BUDDY_EXECUTION_REVISION_COMMITTER_NAME"] + end + + def git_commit_committer_email + env["BUDDY_EXECUTION_REVISION_COMMITTER_EMAIL"] + end + end + end + end + end + end +end diff --git a/lib/datadog/ci/ext/environment/providers/default.rb b/lib/datadog/ci/ext/environment/providers/default.rb new file mode 100644 index 00000000..53864611 --- /dev/null +++ b/lib/datadog/ci/ext/environment/providers/default.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require_relative "../extractor" + +module Datadog + module CI + module Ext + module Environment + module Providers + # TODO + class Default < Extractor + def tags + {} + end + end + end + end + end + end +end diff --git a/lib/datadog/ci/ext/providers/appveyor.rb b/lib/datadog/ci/ext/providers/appveyor.rb deleted file mode 100644 index 1d3af293..00000000 --- a/lib/datadog/ci/ext/providers/appveyor.rb +++ /dev/null @@ -1,99 +0,0 @@ -# frozen_string_literal: true - -require_relative "extractor" - -module Datadog - module CI - module Ext - module Providers - # Appveyor: https://www.appveyor.com/ - # Environment variables docs: https://www.appveyor.com/docs/environment-variables/ - class Appveyor < Extractor - private - - # overridden methods - def provider_name - "appveyor" - end - - def pipeline_url - url - end - - def job_url - url - end - - def workspace_path - env["APPVEYOR_BUILD_FOLDER"] - end - - def pipeline_id - env["APPVEYOR_BUILD_ID"] - end - - def pipeline_name - env["APPVEYOR_REPO_NAME"] - end - - def pipeline_number - env["APPVEYOR_BUILD_NUMBER"] - end - - def git_repository_url - return nil unless github_repo_provider? - - "https://github.com/#{env["APPVEYOR_REPO_NAME"]}.git" - end - - def git_commit_sha - return nil unless github_repo_provider? - - env["APPVEYOR_REPO_COMMIT"] - end - - def git_branch - return nil unless github_repo_provider? - - env["APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH"] || env["APPVEYOR_REPO_BRANCH"] - end - - def git_tag - return nil unless github_repo_provider? - - env["APPVEYOR_REPO_TAG_NAME"] - end - - def git_commit_author_name - env["APPVEYOR_REPO_COMMIT_AUTHOR"] - end - - def git_commit_author_email - env["APPVEYOR_REPO_COMMIT_AUTHOR_EMAIL"] - end - - def git_commit_message - commit_message = env["APPVEYOR_REPO_COMMIT_MESSAGE"] - if commit_message - extended = env["APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED"] - commit_message = "#{commit_message}\n#{extended}" if extended - end - commit_message - end - - # appveyor-specific methods - - def github_repo_provider? - return @github_repo_provider if defined?(@github_repo_provider) - - @github_repo_provider = env["APPVEYOR_REPO_PROVIDER"] == "github" - end - - def url - @url ||= "https://ci.appveyor.com/project/#{env["APPVEYOR_REPO_NAME"]}/builds/#{env["APPVEYOR_BUILD_ID"]}" - end - end - end - end - end -end diff --git a/lib/datadog/ci/ext/providers/azure.rb b/lib/datadog/ci/ext/providers/azure.rb deleted file mode 100644 index 796278eb..00000000 --- a/lib/datadog/ci/ext/providers/azure.rb +++ /dev/null @@ -1,124 +0,0 @@ -# frozen_string_literal: true - -require_relative "extractor" - -module Datadog - module CI - module Ext - 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 - private - - # overridden methods - def provider_name - "azurepipelines" - end - - def pipeline_url - return unless url_defined? - - @pipeline_url ||= "#{team_foundation_server_uri}#{team_project_id}/_build/results?buildId=#{build_id}" - end - - def job_url - return unless url_defined? - - @job_url ||= "#{pipeline_url}&view=logs&j=#{env["SYSTEM_JOBID"]}&t=#{env["SYSTEM_TASKINSTANCEID"]}" - end - - def workspace_path - env["BUILD_SOURCESDIRECTORY"] - end - - def pipeline_id - build_id - end - - def pipeline_number - build_id - end - - def pipeline_name - env["BUILD_DEFINITIONNAME"] - end - - def stage_name - env["SYSTEM_STAGEDISPLAYNAME"] - end - - def job_name - env["SYSTEM_JOBDISPLAYNAME"] - end - - def git_repository_url - env["SYSTEM_PULLREQUEST_SOURCEREPOSITORYURI"] || env["BUILD_REPOSITORY_URI"] - end - - def git_commit_sha - env["SYSTEM_PULLREQUEST_SOURCECOMMITID"] || env["BUILD_SOURCEVERSION"] - end - - def git_branch - return @branch if defined?(@branch) - - set_branch_and_tag - @branch - end - - def git_tag - return @tag if defined?(@tag) - - set_branch_and_tag - @tag - end - - def git_commit_author_name - env["BUILD_REQUESTEDFORID"] - end - - def git_commit_author_email - env["BUILD_REQUESTEDFOREMAIL"] - end - - def git_commit_message - env["BUILD_SOURCEVERSIONMESSAGE"] - end - - def ci_env_vars - { - "SYSTEM_TEAMPROJECTID" => env["SYSTEM_TEAMPROJECTID"], - "BUILD_BUILDID" => env["BUILD_BUILDID"], - "SYSTEM_JOBID" => env["SYSTEM_JOBID"] - }.to_json - end - - # azure-specific methods - - def build_id - env["BUILD_BUILDID"] - end - - def team_foundation_server_uri - env["SYSTEM_TEAMFOUNDATIONSERVERURI"] - end - - def team_project_id - env["SYSTEM_TEAMPROJECTID"] - end - - def url_defined? - !(build_id && team_foundation_server_uri && team_project_id).nil? - end - - def set_branch_and_tag - @branch, @tag = branch_or_tag( - env["SYSTEM_PULLREQUEST_SOURCEBRANCH"] || env["BUILD_SOURCEBRANCH"] || env["BUILD_SOURCEBRANCHNAME"] - ) - end - end - end - end - end -end diff --git a/lib/datadog/ci/ext/providers/bitbucket.rb b/lib/datadog/ci/ext/providers/bitbucket.rb deleted file mode 100644 index 57b04897..00000000 --- a/lib/datadog/ci/ext/providers/bitbucket.rb +++ /dev/null @@ -1,70 +0,0 @@ -# frozen_string_literal: true - -require_relative "extractor" - -module Datadog - module CI - module Ext - 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 - private - - # overridden methods - def provider_name - "bitbucket" - end - - def pipeline_id - env["BITBUCKET_PIPELINE_UUID"] ? env["BITBUCKET_PIPELINE_UUID"].tr("{}", "") : nil - end - - def pipeline_name - env["BITBUCKET_REPO_FULL_NAME"] - end - - def pipeline_number - env["BITBUCKET_BUILD_NUMBER"] - end - - def pipeline_url - url - end - - def job_url - url - end - - def workspace_path - env["BITBUCKET_CLONE_DIR"] - end - - def git_repository_url - env["BITBUCKET_GIT_SSH_ORIGIN"] || env["BITBUCKET_GIT_HTTP_ORIGIN"] - end - - def git_commit_sha - env["BITBUCKET_COMMIT"] - end - - def git_branch - env["BITBUCKET_BRANCH"] - end - - def git_tag - env["BITBUCKET_TAG"] - end - - # bitbucket-specific methods - - def url - "https://bitbucket.org/#{env["BITBUCKET_REPO_FULL_NAME"]}/addon/pipelines/home#" \ - "!/results/#{env["BITBUCKET_BUILD_NUMBER"]}" - end - - end - end - end - end -end diff --git a/lib/datadog/ci/ext/providers/default.rb b/lib/datadog/ci/ext/providers/default.rb deleted file mode 100644 index da9b81aa..00000000 --- a/lib/datadog/ci/ext/providers/default.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require_relative "extractor" - -module Datadog - module CI - module Ext - module Providers - # TODO - class Default < Extractor - def tags - {} - end - end - end - end - end -end diff --git a/sig/datadog/ci/ext/providers/extractor.rbs b/sig/datadog/ci/ext/environment/extractor.rbs similarity index 98% rename from sig/datadog/ci/ext/providers/extractor.rbs rename to sig/datadog/ci/ext/environment/extractor.rbs index d8cac7e3..64d3f277 100644 --- a/sig/datadog/ci/ext/providers/extractor.rbs +++ b/sig/datadog/ci/ext/environment/extractor.rbs @@ -1,7 +1,7 @@ module Datadog module CI module Ext - module Providers + module Environment class Extractor EXTRACTORS: ::Array[::Array[String | untyped]] diff --git a/sig/datadog/ci/ext/environment/providers/appveyor.rbs b/sig/datadog/ci/ext/environment/providers/appveyor.rbs new file mode 100644 index 00000000..1508c74d --- /dev/null +++ b/sig/datadog/ci/ext/environment/providers/appveyor.rbs @@ -0,0 +1,48 @@ +module Datadog + module CI + module Ext + module Environment + module Providers + class Appveyor < Extractor + private + + @github_repo_provider: bool + @url: String + + def provider_name: () -> "appveyor" + + def pipeline_url: () -> String? + + def job_url: () -> String? + + def workspace_path: () -> String? + + def pipeline_id: () -> String? + + def pipeline_name: () -> String? + + def pipeline_number: () -> String? + + def git_repository_url: () -> String? + + def git_commit_sha: () -> String? + + def git_branch: () -> String? + + def git_tag: () -> String? + + def git_commit_author_name: () -> String? + + def git_commit_author_email: () -> String? + + def git_commit_message: () -> String? + + def github_repo_provider?: () -> bool + + def url: () -> String? + end + end + end + end + end +end diff --git a/sig/datadog/ci/ext/environment/providers/azure.rbs b/sig/datadog/ci/ext/environment/providers/azure.rbs new file mode 100644 index 00000000..3b89b88a --- /dev/null +++ b/sig/datadog/ci/ext/environment/providers/azure.rbs @@ -0,0 +1,60 @@ +module Datadog + module CI + module Ext + module Environment + module Providers + class Azure < Extractor + private + + @pipeline_url: String + @job_url: String + + def provider_name: () -> "azurepipelines" + + def pipeline_url: () -> String? + + def job_url: () -> String? + + def workspace_path: () -> String? + + def pipeline_id: () -> String? + + def pipeline_number: () -> String? + + def pipeline_name: () -> String? + + def stage_name: () -> String? + + def job_name: () -> String? + + def git_repository_url: () -> String? + + def git_commit_sha: () -> String? + + def git_branch: () -> String? + + def git_tag: () -> String? + + def git_commit_author_name: () -> String? + + def git_commit_author_email: () -> String? + + def git_commit_message: () -> String? + + def ci_env_vars: () -> String? + + def build_id: () -> String? + + def team_foundation_server_uri: () -> String? + + def team_project_id: () -> String? + + def url_defined?: () -> bool + + def set_branch_and_tag: () -> [String?, String?] + end + end + end + end + end +end diff --git a/sig/datadog/ci/ext/environment/providers/bitbucket.rbs b/sig/datadog/ci/ext/environment/providers/bitbucket.rbs new file mode 100644 index 00000000..3dbe8af9 --- /dev/null +++ b/sig/datadog/ci/ext/environment/providers/bitbucket.rbs @@ -0,0 +1,36 @@ +module Datadog + module CI + module Ext + module Environment + module Providers + class Bitbucket < Extractor + private + def provider_name: () -> "bitbucket" + + def pipeline_id: () -> String? + + def pipeline_name: () -> String? + + def pipeline_number: () -> String? + + def pipeline_url: () -> String? + + def job_url: () -> String? + + def workspace_path: () -> String? + + def git_repository_url: () -> String? + + def git_commit_sha: () -> String? + + def git_branch: () -> String? + + def git_tag: () -> String? + + def url: () -> ::String? + end + end + end + end + end +end diff --git a/sig/datadog/ci/ext/environment/providers/buddy.rbs b/sig/datadog/ci/ext/environment/providers/buddy.rbs new file mode 100644 index 00000000..07f01a1c --- /dev/null +++ b/sig/datadog/ci/ext/environment/providers/buddy.rbs @@ -0,0 +1,38 @@ +module Datadog + module CI + module Ext + module Environment + module Providers + class Buddy < Extractor + private + def provider_name: () -> "buddy" + + def pipeline_id: () -> ::String + + def pipeline_name: () -> String? + + def pipeline_number: () -> String? + + def pipeline_url: () -> String? + + def workspace_path: () -> String? + + def git_repository_url: () -> String? + + def git_commit_sha: () -> String? + + def git_branch: () -> String? + + def git_tag: () -> String? + + def git_commit_message: () -> String? + + def git_commit_committer_name: () -> String? + + def git_commit_committer_email: () -> String? + end + end + end + end + end +end diff --git a/sig/datadog/ci/ext/environment/providers/default.rbs b/sig/datadog/ci/ext/environment/providers/default.rbs new file mode 100644 index 00000000..2b00c8fa --- /dev/null +++ b/sig/datadog/ci/ext/environment/providers/default.rbs @@ -0,0 +1,13 @@ +module Datadog + module CI + module Ext + module Environment + module Providers + class Default < Extractor + def tags: () -> ::Hash[String, untyped] + end + end + end + end + end +end diff --git a/sig/datadog/ci/ext/providers/appveyor.rbs b/sig/datadog/ci/ext/providers/appveyor.rbs deleted file mode 100644 index e9f063bb..00000000 --- a/sig/datadog/ci/ext/providers/appveyor.rbs +++ /dev/null @@ -1,46 +0,0 @@ -module Datadog - module CI - module Ext - module Providers - class Appveyor < Extractor - private - - @github_repo_provider: bool - @url: String - - def provider_name: () -> "appveyor" - - def pipeline_url: () -> String? - - def job_url: () -> String? - - def workspace_path: () -> String? - - def pipeline_id: () -> String? - - def pipeline_name: () -> String? - - def pipeline_number: () -> String? - - def git_repository_url: () -> String? - - def git_commit_sha: () -> String? - - def git_branch: () -> String? - - def git_tag: () -> String? - - def git_commit_author_name: () -> String? - - def git_commit_author_email: () -> String? - - def git_commit_message: () -> String? - - def github_repo_provider?: () -> bool - - def url: () -> String? - end - end - end - end -end diff --git a/sig/datadog/ci/ext/providers/azure.rbs b/sig/datadog/ci/ext/providers/azure.rbs deleted file mode 100644 index d4ffbc6d..00000000 --- a/sig/datadog/ci/ext/providers/azure.rbs +++ /dev/null @@ -1,58 +0,0 @@ -module Datadog - module CI - module Ext - module Providers - class Azure < Extractor - private - - @pipeline_url: String - @job_url: String - - def provider_name: () -> "azurepipelines" - - def pipeline_url: () -> String? - - def job_url: () -> String? - - def workspace_path: () -> String? - - def pipeline_id: () -> String? - - def pipeline_number: () -> String? - - def pipeline_name: () -> String? - - def stage_name: () -> String? - - def job_name: () -> String? - - def git_repository_url: () -> String? - - def git_commit_sha: () -> String? - - def git_branch: () -> String? - - def git_tag: () -> String? - - def git_commit_author_name: () -> String? - - def git_commit_author_email: () -> String? - - def git_commit_message: () -> String? - - def ci_env_vars: () -> String? - - def build_id: () -> String? - - def team_foundation_server_uri: () -> String? - - def team_project_id: () -> String? - - def url_defined?: () -> bool - - def set_branch_and_tag: () -> [String?, String?] - end - end - end - end -end diff --git a/sig/datadog/ci/ext/providers/bitbucket.rbs b/sig/datadog/ci/ext/providers/bitbucket.rbs deleted file mode 100644 index f2a5ee4b..00000000 --- a/sig/datadog/ci/ext/providers/bitbucket.rbs +++ /dev/null @@ -1,34 +0,0 @@ -module Datadog - module CI - module Ext - module Providers - class Bitbucket < Extractor - private - def provider_name: () -> "bitbucket" - - def pipeline_id: () -> String? - - def pipeline_name: () -> String? - - def pipeline_number: () -> String? - - def pipeline_url: () -> String? - - def job_url: () -> String? - - def workspace_path: () -> String? - - def git_repository_url: () -> String? - - def git_commit_sha: () -> String? - - def git_branch: () -> String? - - def git_tag: () -> String? - - def url: () -> ::String? - end - end - end - end -end diff --git a/sig/datadog/ci/ext/providers/default.rbs b/sig/datadog/ci/ext/providers/default.rbs deleted file mode 100644 index ce93a465..00000000 --- a/sig/datadog/ci/ext/providers/default.rbs +++ /dev/null @@ -1,11 +0,0 @@ -module Datadog - module CI - module Ext - module Providers - class Default < Extractor - def tags: () -> ::Hash[String, untyped] - end - end - end - end -end