Skip to content

Commit

Permalink
Merge branch '2.10' into backport-10460-to-2.10
Browse files Browse the repository at this point in the history
  • Loading branch information
taegyunkim authored Sep 9, 2024
2 parents e15898b + d7e6c20 commit 1025e7a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ddtrace/internal/ci_visibility/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os
from pathlib import Path
import re
import socket
from typing import TYPE_CHECKING # noqa:F401
from typing import NamedTuple # noqa:F401
Expand Down Expand Up @@ -102,12 +103,17 @@ class CIVisibilityAuthenticationException(Exception):
pass


def _extract_repository_name_from_url(repository_url):
# type: (str) -> str
def _extract_repository_name_from_url(repository_url: str) -> str:
_REPO_NAME_REGEX = r".*/(?P<repo_name>.*?)(\.git)?$"

try:
return parse.urlparse(repository_url).path.rstrip(".git").rpartition("/")[-1]
url_path = parse.urlparse(repository_url).path
matches = re.match(_REPO_NAME_REGEX, url_path, flags=re.IGNORECASE)
if matches:
return matches.group("repo_name")
log.warning("Cannot extract repository name from unexpected URL path: %s", url_path)
return repository_url
except ValueError:
# In case of parsing error, default to repository url
log.warning("Repository name cannot be parsed from repository_url: %s", repository_url)
return repository_url

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
fixes:
- |
CI Visibility: Fixes a bug where ``.git`` was incorrectly being stripped from repository URLs when extracting service names,
resulting in ``g``, ``i``, or ``t`` being removed (eg: ``test-environment.git`` incorrectly becoming ``test-environmen``)
10 changes: 10 additions & 0 deletions tests/ci_visibility/test_ci_visibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@ def test_ci_visibility_service_disable():
("git+git://github.com/org/repo-name.git", "repo-name"),
("git+ssh://github.com/org/repo-name.git", "repo-name"),
("git+https://github.com/org/repo-name.git", "repo-name"),
("https://github.com/fastapi/fastapi.git", "fastapi"),
("[email protected]:fastapi/fastapi.git", "fastapi"),
("[email protected]:fastapi/fastapi.gitttttt", "fastapi.gitttttt"),
("[email protected]:fastapi/fastapiiiititititi.git", "fastapiiiititititi"),
("https://github.com/fastapi/fastapitttttt.git", "fastapitttttt"),
("this is definitely not a valid git repo URL", "this is definitely not a valid git repo URL"),
("[email protected]:fastapi/FastAPI.GiT", "FastAPI"),
("git+https://github.com/org/REPO-NAME.GIT", "REPO-NAME"),
("https://github.com/DataDog/DD-TRACE-py", "DD-TRACE-py"),
("https://github.com/DataDog/dd-trace-py.GIT", "dd-trace-py"),
],
)
def test_repository_name_extracted(repository_url, repository_name):
Expand Down

0 comments on commit 1025e7a

Please sign in to comment.