Skip to content

Commit 33693f5

Browse files
github-actions[bot]vitor-de-araujobrettlangdon
authored
fix(ci_visibility): look for CODEOWNERS relative to repo root, not cwd [backport 2.21] (#13128)
Backport fe66a15 from #13112 to 2.21. ## Checklist - [x] PR author has checked that all the criteria below are met - The PR description includes an overview of the change - The PR description articulates the motivation for the change - The change includes tests OR the PR description describes a testing strategy - The PR description notes risks associated with the change, if any - Newly-added code is easy to change - The change follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) - The change includes or references documentation updates if necessary - Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Reviewer has checked that all the criteria below are met - Title is accurate - All changes are related to the pull request's stated goal - Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes - Testing strategy adequately addresses listed risks - Newly-added code is easy to change - Release note makes sense to a user of the library - If necessary, author has acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment - Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) --------- Co-authored-by: Vítor De Araújo <[email protected]> Co-authored-by: Brett Langdon <[email protected]>
1 parent d141a48 commit 33693f5

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

ddtrace/internal/ci_visibility/recorder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def __init__(self, tracer=None, config=None, service=None):
306306
log.info("Detected configurations: %s", str(self._configurations))
307307

308308
try:
309-
self._codeowners = Codeowners()
309+
self._codeowners = Codeowners(cwd=self._tags.get(ci.WORKSPACE_PATH))
310310
except ValueError:
311311
log.warning("CODEOWNERS file is not available")
312312
except Exception:
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
CI Visibility: This fix resolves an issue where the ``CODEOWNERS`` file of the project being tested was looked up in
5+
the current working directory rather than the repository root.

tests/contrib/pytest/test_pytest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,25 @@ def test_team_b():
953953
assert json.loads(test_spans[0].get_tag(test.CODEOWNERS)) == ["@default-team"], test_spans[0]
954954
assert json.loads(test_spans[1].get_tag(test.CODEOWNERS)) == ["@team-b", "@backup-b"], test_spans[1]
955955

956+
def test_pytest_will_report_codeowners_when_called_from_subdirectory(self):
957+
self.testdir.mkdir(".github")
958+
self.testdir.makefile("", **{".github/CODEOWNERS": "* @default-team"})
959+
960+
subdir = self.testdir.mkdir("subdir")
961+
test_file_content = """
962+
import pytest
963+
964+
def test_foo():
965+
assert 1 == 1
966+
"""
967+
self.testdir.makepyfile(**{"subdir/test_foo": test_file_content})
968+
969+
subdir.chdir()
970+
self.inline_run("--ddtrace", "test_foo.py")
971+
spans = self.pop_spans()
972+
[test_span] = [span for span in spans if span.get_tag("type") == "test"]
973+
assert json.loads(test_span.get_tag(test.CODEOWNERS)) == ["@default-team"]
974+
956975
def test_pytest_session(self):
957976
"""Test that running pytest will generate a test session span."""
958977
self.inline_run("--ddtrace")

0 commit comments

Comments
 (0)