diff --git a/lib/datadog/ci/configuration/components.rb b/lib/datadog/ci/configuration/components.rb index 9abe9443..aafad49f 100644 --- a/lib/datadog/ci/configuration/components.rb +++ b/lib/datadog/ci/configuration/components.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../flush" module Datadog diff --git a/lib/datadog/ci/configuration/settings.rb b/lib/datadog/ci/configuration/settings.rb index d75c5a77..fc3c38f9 100644 --- a/lib/datadog/ci/configuration/settings.rb +++ b/lib/datadog/ci/configuration/settings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../ext/settings" module Datadog diff --git a/lib/datadog/ci/contrib/cucumber/configuration/settings.rb b/lib/datadog/ci/contrib/cucumber/configuration/settings.rb index 9a0e6ccc..713094e6 100644 --- a/lib/datadog/ci/contrib/cucumber/configuration/settings.rb +++ b/lib/datadog/ci/contrib/cucumber/configuration/settings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../ext" require "datadog/tracing/contrib/configuration/settings" diff --git a/lib/datadog/ci/contrib/cucumber/ext.rb b/lib/datadog/ci/contrib/cucumber/ext.rb index 75fc21b4..4878a445 100644 --- a/lib/datadog/ci/contrib/cucumber/ext.rb +++ b/lib/datadog/ci/contrib/cucumber/ext.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Datadog module CI module Contrib @@ -5,14 +7,14 @@ module Cucumber # Cucumber integration constants # TODO: mark as `@public_api` when GA, to protect from resource and tag name changes. module Ext - APP = "cucumber".freeze - ENV_ENABLED = "DD_TRACE_CUCUMBER_ENABLED".freeze - ENV_OPERATION_NAME = "DD_TRACE_CUCUMBER_OPERATION_NAME".freeze - FRAMEWORK = "cucumber".freeze - OPERATION_NAME = "cucumber.test".freeze - SERVICE_NAME = "cucumber".freeze - STEP_SPAN_TYPE = "step".freeze - TEST_TYPE = "test".freeze + APP = "cucumber" + ENV_ENABLED = "DD_TRACE_CUCUMBER_ENABLED" + ENV_OPERATION_NAME = "DD_TRACE_CUCUMBER_OPERATION_NAME" + FRAMEWORK = "cucumber" + OPERATION_NAME = "cucumber.test" + SERVICE_NAME = "cucumber" + STEP_SPAN_TYPE = "step" + TEST_TYPE = "test" end end end diff --git a/lib/datadog/ci/contrib/cucumber/formatter.rb b/lib/datadog/ci/contrib/cucumber/formatter.rb index 239ae902..150218ac 100644 --- a/lib/datadog/ci/contrib/cucumber/formatter.rb +++ b/lib/datadog/ci/contrib/cucumber/formatter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../../test" require_relative "../../ext/app_types" require_relative "../../ext/environment" diff --git a/lib/datadog/ci/contrib/cucumber/instrumentation.rb b/lib/datadog/ci/contrib/cucumber/instrumentation.rb index 87688ddf..9e98cc58 100644 --- a/lib/datadog/ci/contrib/cucumber/instrumentation.rb +++ b/lib/datadog/ci/contrib/cucumber/instrumentation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "formatter" module Datadog diff --git a/lib/datadog/ci/contrib/cucumber/integration.rb b/lib/datadog/ci/contrib/cucumber/integration.rb index 2e9c4b2d..115ba47a 100644 --- a/lib/datadog/ci/contrib/cucumber/integration.rb +++ b/lib/datadog/ci/contrib/cucumber/integration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "configuration/settings" require_relative "patcher" diff --git a/lib/datadog/ci/contrib/cucumber/patcher.rb b/lib/datadog/ci/contrib/cucumber/patcher.rb index 9e1430da..268404bf 100644 --- a/lib/datadog/ci/contrib/cucumber/patcher.rb +++ b/lib/datadog/ci/contrib/cucumber/patcher.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "datadog/tracing/contrib/patcher" require_relative "instrumentation" diff --git a/lib/datadog/ci/contrib/minitest/configuration/settings.rb b/lib/datadog/ci/contrib/minitest/configuration/settings.rb index 1ac6cd54..f412978e 100644 --- a/lib/datadog/ci/contrib/minitest/configuration/settings.rb +++ b/lib/datadog/ci/contrib/minitest/configuration/settings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../ext" require "datadog/tracing/contrib/configuration/settings" diff --git a/lib/datadog/ci/contrib/minitest/ext.rb b/lib/datadog/ci/contrib/minitest/ext.rb index 0ffaf746..b45ab2a3 100644 --- a/lib/datadog/ci/contrib/minitest/ext.rb +++ b/lib/datadog/ci/contrib/minitest/ext.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Datadog module CI module Contrib diff --git a/lib/datadog/ci/contrib/minitest/hooks.rb b/lib/datadog/ci/contrib/minitest/hooks.rb index d8bba439..0bb61195 100644 --- a/lib/datadog/ci/contrib/minitest/hooks.rb +++ b/lib/datadog/ci/contrib/minitest/hooks.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Datadog module CI module Contrib diff --git a/lib/datadog/ci/contrib/minitest/integration.rb b/lib/datadog/ci/contrib/minitest/integration.rb index 4be1ae1c..e918e25e 100644 --- a/lib/datadog/ci/contrib/minitest/integration.rb +++ b/lib/datadog/ci/contrib/minitest/integration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "configuration/settings" require_relative "patcher" diff --git a/lib/datadog/ci/contrib/rspec/configuration/settings.rb b/lib/datadog/ci/contrib/rspec/configuration/settings.rb index 2ece8d0c..c573b9e5 100644 --- a/lib/datadog/ci/contrib/rspec/configuration/settings.rb +++ b/lib/datadog/ci/contrib/rspec/configuration/settings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../ext" require "datadog/tracing/contrib/configuration/settings" diff --git a/lib/datadog/ci/contrib/rspec/example.rb b/lib/datadog/ci/contrib/rspec/example.rb index 7be45b27..e45e26c6 100644 --- a/lib/datadog/ci/contrib/rspec/example.rb +++ b/lib/datadog/ci/contrib/rspec/example.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require_relative "../../test" require_relative "../../ext/app_types" diff --git a/lib/datadog/ci/contrib/rspec/ext.rb b/lib/datadog/ci/contrib/rspec/ext.rb index 65351fac..9ce6ae1a 100644 --- a/lib/datadog/ci/contrib/rspec/ext.rb +++ b/lib/datadog/ci/contrib/rspec/ext.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Datadog module CI module Contrib @@ -5,13 +7,13 @@ module RSpec # RSpec integration constants # TODO: mark as `@public_api` when GA, to protect from resource and tag name changes. module Ext - APP = "rspec".freeze - ENV_ENABLED = "DD_TRACE_RSPEC_ENABLED".freeze - ENV_OPERATION_NAME = "DD_TRACE_RSPEC_OPERATION_NAME".freeze - FRAMEWORK = "rspec".freeze - OPERATION_NAME = "rspec.example".freeze - SERVICE_NAME = "rspec".freeze - TEST_TYPE = "test".freeze + APP = "rspec" + ENV_ENABLED = "DD_TRACE_RSPEC_ENABLED" + ENV_OPERATION_NAME = "DD_TRACE_RSPEC_OPERATION_NAME" + FRAMEWORK = "rspec" + OPERATION_NAME = "rspec.example" + SERVICE_NAME = "rspec" + TEST_TYPE = "test" end end end diff --git a/lib/datadog/ci/contrib/rspec/integration.rb b/lib/datadog/ci/contrib/rspec/integration.rb index 5ce19878..2121c50e 100644 --- a/lib/datadog/ci/contrib/rspec/integration.rb +++ b/lib/datadog/ci/contrib/rspec/integration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "datadog/tracing/contrib/integration" require_relative "configuration/settings" diff --git a/lib/datadog/ci/contrib/rspec/patcher.rb b/lib/datadog/ci/contrib/rspec/patcher.rb index 0dc057b6..80365e67 100644 --- a/lib/datadog/ci/contrib/rspec/patcher.rb +++ b/lib/datadog/ci/contrib/rspec/patcher.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "datadog/tracing/contrib/patcher" require_relative "example" diff --git a/lib/datadog/ci/ext/app_types.rb b/lib/datadog/ci/ext/app_types.rb index 297e78a1..e83ad3c3 100644 --- a/lib/datadog/ci/ext/app_types.rb +++ b/lib/datadog/ci/ext/app_types.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + module Datadog module CI module Ext module AppTypes - TYPE_TEST = "test".freeze + TYPE_TEST = "test" end end end diff --git a/lib/datadog/ci/ext/environment/providers/base.rb b/lib/datadog/ci/ext/environment/providers/base.rb index 77d1682c..82d2b514 100644 --- a/lib/datadog/ci/ext/environment/providers/base.rb +++ b/lib/datadog/ci/ext/environment/providers/base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Datadog module CI module Ext diff --git a/lib/datadog/ci/ext/settings.rb b/lib/datadog/ci/ext/settings.rb index c9424739..d74dbbd6 100644 --- a/lib/datadog/ci/ext/settings.rb +++ b/lib/datadog/ci/ext/settings.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + module Datadog module CI module Ext # Defines constants for test tags module Settings - ENV_MODE_ENABLED = "DD_TRACE_CI_ENABLED".freeze + ENV_MODE_ENABLED = "DD_TRACE_CI_ENABLED" end end end diff --git a/lib/datadog/ci/ext/test.rb b/lib/datadog/ci/ext/test.rb index 8d4a0471..af7199fb 100644 --- a/lib/datadog/ci/ext/test.rb +++ b/lib/datadog/ci/ext/test.rb @@ -1,33 +1,35 @@ +# frozen_string_literal: true + module Datadog module CI module Ext # Defines constants for test tags module Test - CONTEXT_ORIGIN = "ciapp-test".freeze + CONTEXT_ORIGIN = "ciapp-test" - TAG_ARGUMENTS = "test.arguments".freeze - TAG_FRAMEWORK = "test.framework".freeze - TAG_FRAMEWORK_VERSION = "test.framework_version".freeze - TAG_NAME = "test.name".freeze - TAG_SKIP_REASON = "test.skip_reason".freeze # DEV: Not populated yet - TAG_STATUS = "test.status".freeze - TAG_SUITE = "test.suite".freeze - TAG_TRAITS = "test.traits".freeze - TAG_TYPE = "test.type".freeze + TAG_ARGUMENTS = "test.arguments" + TAG_FRAMEWORK = "test.framework" + TAG_FRAMEWORK_VERSION = "test.framework_version" + TAG_NAME = "test.name" + TAG_SKIP_REASON = "test.skip_reason" # DEV: Not populated yet + TAG_STATUS = "test.status" + TAG_SUITE = "test.suite" + TAG_TRAITS = "test.traits" + TAG_TYPE = "test.type" # Environment runtime tags - TAG_OS_ARCHITECTURE = "os.architecture".freeze - TAG_OS_PLATFORM = "os.platform".freeze - TAG_RUNTIME_NAME = "runtime.name".freeze - TAG_RUNTIME_VERSION = "runtime.version".freeze + TAG_OS_ARCHITECTURE = "os.architecture" + TAG_OS_PLATFORM = "os.platform" + TAG_RUNTIME_NAME = "runtime.name" + TAG_RUNTIME_VERSION = "runtime.version" # TODO: is there a better place for SPAN_KIND? - TAG_SPAN_KIND = "span.kind".freeze + TAG_SPAN_KIND = "span.kind" module Status - PASS = "pass".freeze - FAIL = "fail".freeze - SKIP = "skip".freeze + PASS = "pass" + FAIL = "fail" + SKIP = "skip" end end end diff --git a/lib/datadog/ci/extensions.rb b/lib/datadog/ci/extensions.rb index e0ec9f28..7c0c1ec2 100644 --- a/lib/datadog/ci/extensions.rb +++ b/lib/datadog/ci/extensions.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "datadog/core/configuration/settings" require "datadog/core/configuration/components" diff --git a/lib/datadog/ci/flush.rb b/lib/datadog/ci/flush.rb index c3771404..5fabf41e 100644 --- a/lib/datadog/ci/flush.rb +++ b/lib/datadog/ci/flush.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "datadog/tracing/metadata/ext" require "datadog/tracing/flush" diff --git a/lib/datadog/ci/utils/git.rb b/lib/datadog/ci/utils/git.rb index 0afe8c7a..4e674966 100644 --- a/lib/datadog/ci/utils/git.rb +++ b/lib/datadog/ci/utils/git.rb @@ -1,19 +1,19 @@ +# frozen_string_literal: true + module Datadog module CI module Utils module Git - module_function - - def normalize_ref(name) - return nil if name.nil? + def self.normalize_ref(ref) + return nil if ref.nil? refs = %r{^refs/(heads/)?} origin = %r{^origin/} tags = %r{^tags/} - name.gsub(refs, "").gsub(origin, "").gsub(tags, "") + ref.gsub(refs, "").gsub(origin, "").gsub(tags, "") end - def is_git_tag?(ref) + def self.is_git_tag?(ref) !ref.nil? && ref.include?("tags/") end end diff --git a/spec/datadog/ci/utils/git_spec.rb b/spec/datadog/ci/utils/git_spec.rb new file mode 100644 index 00000000..c17700c5 --- /dev/null +++ b/spec/datadog/ci/utils/git_spec.rb @@ -0,0 +1,49 @@ +RSpec.describe ::Datadog::CI::Utils::Git do + describe ".normalize_ref" do + subject { described_class.normalize_ref(ref) } + + context "when input is nil" do + let(:ref) { nil } + + it { is_expected.to be_nil } + end + + context "when input is github ref" do + let(:ref) { "refs/heads/master" } + + it "strips everything out except ref name" do + is_expected.to eq("master") + end + end + + context "when input includes tags" do + let(:ref) { "refs/heads/tags/0.1.0" } + + it "strips everything out except ref name" do + is_expected.to eq("0.1.0") + end + end + end + + describe ".is_git_tag?" do + subject { described_class.is_git_tag?(ref) } + + context "when input is nil" do + let(:ref) { nil } + + it { is_expected.to be_falsey } + end + + context "when input is a branch" do + let(:ref) { "refs/heads/master" } + + it { is_expected.to be_falsey } + end + + context "when input includes tags" do + let(:ref) { "refs/heads/tags/0.1.0" } + + it { is_expected.to be_truthy } + end + end +end