@@ -264,12 +264,21 @@ def get_workflow_artifacts(self, repo: str, run_id: int) -> Dict[str, Dict]:
264264 "size_in_bytes" : 1048576 ,
265265 "digest" : "sha256:mock-digest"
266266 },
267- "mock-artifact " : {
267+ "release_info " : {
268268 "id" : 67890 ,
269269 "archive_download_url" : f"https://api.github.com/repos/{ repo } /actions/artifacts/67890/zip" ,
270270 "created_at" : "2023-01-01T00:00:00Z" ,
271271 "expires_at" : "2023-01-31T00:00:00Z" ,
272272 "updated_at" : "2023-01-01T00:00:00Z" ,
273+ "size_in_bytes" : 2097152 ,
274+ "digest" : "sha256:mock-digest-info"
275+ },
276+ "mock-artifact" : {
277+ "id" : 11111 ,
278+ "archive_download_url" : f"https://api.github.com/repos/{ repo } /actions/artifacts/11111/zip" ,
279+ "created_at" : "2023-01-01T00:00:00Z" ,
280+ "expires_at" : "2023-01-31T00:00:00Z" ,
281+ "updated_at" : "2023-01-01T00:00:00Z" ,
273282 "size_in_bytes" : 2048576 ,
274283 "digest" : "sha256:mock-digest-2"
275284 }
@@ -322,31 +331,33 @@ def get_workflow_artifacts(self, repo: str, run_id: int) -> Dict[str, Dict]:
322331 console .print (f"[red]Failed to get artifacts: { e } [/red]" )
323332 return {}
324333
325- def extract_release_handle (self , repo : str , artifacts : Dict [str , Dict ]) -> Optional [Dict [str , Any ]]:
326- """Extract release_handle JSON from artifacts.
334+ def extract_result (self , repo : str , artifacts : Dict [str , Dict ], artifact_name : str , json_file_name : str ) -> Optional [Dict [str , Any ]]:
335+ """Extract JSON result from artifacts.
327336
328337 Args:
329338 repo: Repository name
330339 artifacts: Dictionary of artifacts from get_workflow_artifacts
340+ artifact_name: Name of the artifact to extract from
341+ json_file_name: Name of the JSON file within the artifact
331342
332343 Returns:
333- Parsed JSON content from release_handle.json file, or None if not found
344+ Parsed JSON content from the specified file, or None if not found
334345 """
335- if "release_handle" not in artifacts :
336- console .print ("[yellow]No release_handle artifact found[/yellow]" )
346+ if artifact_name not in artifacts :
347+ console .print (f "[yellow]No { artifact_name } artifact found[/yellow]" )
337348 return None
338349
339- release_handle_artifact = artifacts ["release_handle" ]
340- artifact_id = release_handle_artifact .get ("id" )
350+ target_artifact = artifacts [artifact_name ]
351+ artifact_id = target_artifact .get ("id" )
341352
342353 if not artifact_id :
343- console .print ("[red]release_handle artifact has no ID[/red]" )
354+ console .print (f "[red]{ artifact_name } artifact has no ID[/red]" )
344355 return None
345356
346- console .print (f"[blue]Extracting release_handle from artifact { artifact_id } [/blue]" )
357+ console .print (f"[blue]Extracting { json_file_name } from artifact { artifact_id } [/blue]" )
347358
348359 if self .dry_run :
349- console .print ("[yellow] (DRY RUN - returning mock release_handle )[/yellow]" )
360+ console .print (f "[yellow] (DRY RUN - returning mock { json_file_name } )[/yellow]" )
350361 return {
351362 "mock" : True ,
352363 "version" : "1.0.0" ,
@@ -356,10 +367,10 @@ def extract_release_handle(self, repo: str, artifacts: Dict[str, Dict]) -> Optio
356367 }
357368 }
358369
359- # Download the artifact and extract release_handle.json
360- download_url = release_handle_artifact .get ("archive_download_url" )
370+ # Download the artifact and extract JSON file
371+ download_url = target_artifact .get ("archive_download_url" )
361372 if not download_url :
362- console .print ("[red]release_handle artifact has no download URL[/red]" )
373+ console .print (f "[red]{ artifact_name } artifact has no download URL[/red]" )
363374 return None
364375
365376 headers = {
@@ -373,27 +384,41 @@ def extract_release_handle(self, repo: str, artifacts: Dict[str, Dict]) -> Optio
373384 response = requests .get (download_url , headers = headers , timeout = 30 )
374385 response .raise_for_status ()
375386
376- # Extract release_handle.json from the zip
387+ # Extract JSON file from the zip
377388 import zipfile
378389 import io
379390
380391 with zipfile .ZipFile (io .BytesIO (response .content )) as zip_file :
381- if "release_handle.json" in zip_file .namelist ():
382- with zip_file .open ("release_handle.json" ) as json_file :
383- release_handle_data = json .load (json_file )
384- console .print ("[green]Successfully extracted release_handle.json [/green]" )
385- return release_handle_data
392+ if json_file_name in zip_file .namelist ():
393+ with zip_file .open (json_file_name ) as json_file :
394+ result_data = json .load (json_file )
395+ console .print (f "[green]Successfully extracted { json_file_name } [/green]" )
396+ return result_data
386397 else :
387- console .print ("[red]release_handle.json not found in artifact[/red]" )
398+ console .print (f "[red]{ json_file_name } not found in artifact[/red]" )
388399 return None
389400
390401 except requests .exceptions .RequestException as e :
391- console .print (f"[red]Failed to download release_handle artifact: { e } [/red]" )
402+ console .print (f"[red]Failed to download { artifact_name } artifact: { e } [/red]" )
392403 return None
393404 except (zipfile .BadZipFile , json .JSONDecodeError , KeyError ) as e :
394- console .print (f"[red]Failed to extract release_handle.json : { e } [/red]" )
405+ console .print (f"[red]Failed to extract { json_file_name } : { e } [/red]" )
395406 return None
396407
408+ def extract_release_handle (self , repo : str , artifacts : Dict [str , Dict ]) -> Optional [Dict [str , Any ]]:
409+ """Extract release_handle JSON from artifacts.
410+
411+ This is a backward compatibility wrapper around extract_result.
412+
413+ Args:
414+ repo: Repository name
415+ artifacts: Dictionary of artifacts from get_workflow_artifacts
416+
417+ Returns:
418+ Parsed JSON content from release_handle.json file, or None if not found
419+ """
420+ return self .extract_result (repo , artifacts , "release_handle" , "release_handle.json" )
421+
397422 def _get_recent_workflow_runs (
398423 self , repo : str , workflow_file : str , limit : int = 10
399424 ) -> List [WorkflowRun ]:
0 commit comments