File tree Expand file tree Collapse file tree 3 files changed +32
-8
lines changed
Expand file tree Collapse file tree 3 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -103,9 +103,13 @@ def __post_init__(self) -> None:
103103 self .exporter = InMemorySpanExporter ()
104104 span_processor = export .SimpleSpanProcessor (self .exporter )
105105 elif self .token and self .repo_name :
106+ try :
107+ owner , repo = utils .split_full_repo_name (self .repo_name )
108+ except utils .InvalidRepositoryFullNameError :
109+ return
106110 self .exporter = OTLPSpanExporter (
107111 session = SessionHardRaiser (),
108- endpoint = f"{ self .api_url } /v1/repos/ { self . repo_name } /ci /traces" ,
112+ endpoint = f"{ self .api_url } /v1/ci/ { owner } /repositories/ { repo } /traces" ,
109113 headers = {"Authorization" : f"Bearer { self .token } " },
110114 compression = Compression .Gzip ,
111115 )
Original file line number Diff line number Diff line change @@ -65,6 +65,20 @@ def get_repository_name_from_env_url(env: str) -> typing.Optional[str]:
6565 return None
6666
6767
68+ class InvalidRepositoryFullNameError (Exception ):
69+ pass
70+
71+
72+ def split_full_repo_name (
73+ full_repo_name : str ,
74+ ) -> typing .Tuple [str , str ]:
75+ split_name = full_repo_name .split ("/" )
76+ if len (split_name ) == 2 :
77+ return split_name [0 ], split_name [1 ]
78+
79+ raise InvalidRepositoryFullNameError (f"Invalid repository name: { full_repo_name } " )
80+
81+
6882def get_repository_name () -> typing .Optional [str ]:
6983 provider = get_ci_provider ()
7084
Original file line number Diff line number Diff line change @@ -77,12 +77,18 @@ def _run(
7777 )
7878
7979 full_repository = utils .get_repository_name ()
80- passthrough = responses .Response (
81- responses .POST ,
82- f"{ api_url } /v1/repos/{ full_repository } /ci/traces" ,
83- passthrough = True ,
84- )
85- responses .add (passthrough )
80+ if full_repository is not None :
81+ try :
82+ owner , repo = utils .split_full_repo_name (full_repository )
83+ except utils .InvalidRepositoryFullNameError :
84+ pass
85+ else :
86+ passthrough = responses .Response (
87+ responses .POST ,
88+ f"{ api_url } /v1/ci/{ owner } /repositories/{ repo } /traces" ,
89+ passthrough = True ,
90+ )
91+ responses .add (passthrough )
8692
8793 plugin = pytest_mergify .PytestMergify ()
8894 pytester .makepyfile (code )
@@ -111,7 +117,7 @@ class TestHTTPRequestHandler(http.server.BaseHTTPRequestHandler):
111117 def do_POST (self ) -> None :
112118 path = self .path [1 :].split ("/" )
113119 # loozy match, who cares
114- if path [0 ] == "v1" and path [- 1 ] == "traces" and path [ - 2 ] == "ci" :
120+ if path [0 ] == "v1" and path [- 1 ] == "traces" :
115121 self .send_response (self .__class__ .response_code )
116122 self .send_header ("Content-Type" , "text/plain" )
117123 self .end_headers ()
You can’t perform that action at this time.
0 commit comments