@@ -135,7 +135,12 @@ async def get_repository(
135135 Fetch repository metadata. Returns (repo_data, None) on success;
136136 (None, {"status": int, "message": str}) on failure for meaningful API responses.
137137 """
138- headers = await self ._get_auth_headers (installation_id = installation_id , user_token = user_token ) or {}
138+ headers = await self ._get_auth_headers (installation_id = installation_id , user_token = user_token )
139+ if not headers :
140+ return (
141+ None ,
142+ {"status" : 401 , "message" : "Authentication required. Provide github_token or installation_id in the request." },
143+ )
139144 url = f"{ config .github .api_base_url } /repos/{ repo_full_name } "
140145 session = await self ._get_session ()
141146 async with session .get (url , headers = headers ) as response :
@@ -169,16 +174,17 @@ async def list_directory_any_auth(
169174 self , repo_full_name : str , path : str , installation_id : int | None = None , user_token : str | None = None
170175 ) -> list [dict [str , Any ]]:
171176 """List directory contents using installation or user token (auth required)."""
172- headers = await self ._get_auth_headers (installation_id = installation_id , user_token = user_token ) or {}
177+ headers = await self ._get_auth_headers (installation_id = installation_id , user_token = user_token )
178+ if not headers :
179+ return []
173180 url = f"{ config .github .api_base_url } /repos/{ repo_full_name } /contents/{ path } "
174181 session = await self ._get_session ()
175182 async with session .get (url , headers = headers ) as response :
176183 if response .status == 200 :
177184 data = await response .json ()
178185 return cast ("list[dict[str, Any]]" , data if isinstance (data , list ) else [data ])
179- if response .status == 401 :
180- return []
181- # Raise exception for other error statuses to avoid silent failures
186+
187+ # Raise exception for error statuses to avoid silent failures
182188 response .raise_for_status ()
183189 return []
184190
@@ -192,13 +198,25 @@ async def get_repository_tree(
192198 ) -> list [dict [str , Any ]]:
193199 """Get the tree of a repository. Requires authentication (github_token or installation_id)."""
194200 start = time .monotonic ()
195- headers = (
196- await self ._get_auth_headers (
197- installation_id = installation_id ,
198- user_token = user_token ,
199- )
200- or {}
201+ headers = await self ._get_auth_headers (
202+ installation_id = installation_id ,
203+ user_token = user_token ,
201204 )
205+ if not headers :
206+ latency_ms = int ((time .monotonic () - start ) * 1000 )
207+ logger .info (
208+ "get_repository_tree" ,
209+ operation = "get_repository_tree" ,
210+ subject_ids = {
211+ "repo" : repo_full_name ,
212+ "installation_id" : installation_id ,
213+ "user_token_present" : bool (user_token ),
214+ "ref" : ref or "main" ,
215+ },
216+ decision = "auth_missing" ,
217+ latency_ms = latency_ms ,
218+ )
219+ return []
202220 ref = ref or "main"
203221 tree_sha = await self ._resolve_tree_sha (repo_full_name , ref , headers )
204222 if not tree_sha :
@@ -259,14 +277,13 @@ async def get_file_content(
259277 Fetches the content of a file from a repository. Requires authentication (github_token or installation_id).
260278 When ref is provided (branch name, tag, or commit SHA), returns content at that ref; otherwise uses default branch.
261279 """
262- headers = (
263- await self ._get_auth_headers (
264- installation_id = installation_id ,
265- user_token = user_token ,
266- accept = "application/vnd.github.raw" ,
267- )
268- or {}
280+ headers = await self ._get_auth_headers (
281+ installation_id = installation_id ,
282+ user_token = user_token ,
283+ accept = "application/vnd.github.raw" ,
269284 )
285+ if not headers :
286+ return None
270287 url = f"{ config .github .api_base_url } /repos/{ repo_full_name } /contents/{ file_path } "
271288 params = {"ref" : ref } if ref else None
272289
0 commit comments