Skip to content

Commit

Permalink
set codeowners tag for test suites
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Sep 23, 2024
1 parent f692387 commit 3670369
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 13 deletions.
7 changes: 7 additions & 0 deletions lib/datadog/ci/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ def runtime_version
tracer_span.get_tag(Ext::Test::TAG_RUNTIME_VERSION)
end

# Source file path where the test or test suite defined (relative to git repository root).
# @return [String] the source file path of the test
# @return [nil] if the source file path is not found
def source_file
get_tag(Ext::Test::TAG_SOURCE_FILE)
end

def set_environment_runtime_tags
tracer_span.set_tag(Ext::Test::TAG_OS_ARCHITECTURE, ::RbConfig::CONFIG["host_cpu"])
tracer_span.set_tag(Ext::Test::TAG_OS_PLATFORM, ::RbConfig::CONFIG["host_os"])
Expand Down
7 changes: 0 additions & 7 deletions lib/datadog/ci/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ def test_session_id
get_tag(Ext::Test::TAG_TEST_SESSION_ID)
end

# Source file path of the test relative to git repository root.
# @return [String] the source file path of the test
# @return [nil] if the source file path is not found
def source_file
get_tag(Ext::Test::TAG_SOURCE_FILE)
end

# Returns "true" if the test is skipped by the intelligent test runner.
# @return [Boolean] true if the test is skipped by the intelligent test runner, false otherwise.
def skipped_by_itr?
Expand Down
8 changes: 4 additions & 4 deletions lib/datadog/ci/test_visibility/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def on_test_module_started(test_module)
end

def on_test_suite_started(test_suite)
# set_codeowners(test_suite)
set_codeowners(test_suite)

Telemetry.event_created(test_suite)
end
Expand Down Expand Up @@ -225,10 +225,10 @@ def subscribe_to_after_stop_event(tracer_span)
end
end

def set_codeowners(test)
source = test.source_file
def set_codeowners(span)
source = span.source_file
owners = @codeowners.list_owners(source) if source
test.set_tag(Ext::Test::TAG_CODEOWNERS, owners) unless owners.nil?
span.set_tag(Ext::Test::TAG_CODEOWNERS, owners) unless owners.nil?
end

def fix_test_suite!(test)
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/ci/span.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ module Datadog

def runtime_version: () -> String?

def source_file: () -> String?

private

def test_visibility: () -> Datadog::CI::TestVisibility::Component
Expand Down
1 change: 0 additions & 1 deletion sig/datadog/ci/test.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ module Datadog
def test_session_id: () -> String?
def skipped_by_itr?: () -> bool
def itr_unskippable!: () -> void
def source_file: () -> String?
def parameters: () -> String?
def is_retry?: () -> bool
def any_retry_passed?: () -> bool
Expand Down
2 changes: 1 addition & 1 deletion sig/datadog/ci/test_visibility/component.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module Datadog

def fix_test_suite!: (Datadog::CI::Test test) -> void

def set_codeowners: (Datadog::CI::Test test) -> void
def set_codeowners: (Datadog::CI::Span span) -> void

def null_span: () -> Datadog::CI::Span

Expand Down
4 changes: 4 additions & 0 deletions spec/datadog/ci/contrib/rspec/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,10 @@ def expect_failure
"spec/datadog/ci/contrib/rspec/instrumentation_spec.rb"
)
expect(first_test_suite_span).to have_test_tag(:source_start, "57")
expect(first_test_suite_span).to have_test_tag(
:codeowners,
"[\"@DataDog/ruby-guild\", \"@DataDog/ci-app-libraries\"]"
)

expect(first_test_suite_span).to have_pass_status
end
Expand Down

0 comments on commit 3670369

Please sign in to comment.