def download_results_artifact(bk: Buildkite, artifact: Artifact) -> Dict: blob = bk.artifacts().download_artifact( organization=artifact.job.build.organization, pipeline=artifact.job.build.pipeline, build=artifact.job.build.number, job=artifact.job.id, artifact=artifact.id, ) data_dict = json.loads(blob) return data_dict.get("results", {})
def get_results_artifact_for_job(bk: Buildkite, job: Job) -> Optional[Dict]: artifacts = bk.artifacts().list_artifacts_for_job( organization=job.build.organization, pipeline=job.build.pipeline, build=job.build.number, job=job.id, ) for artifact in artifacts: if "result.json" in artifact["filename"]: artifact = Artifact(job=job, id=artifact["id"]) return download_results_artifact(bk=bk, artifact=artifact) return None
def get_build_artifacts(buildkite: Buildkite, org: str, pipeline: str, build_number: int) -> List[Dict]: list = buildkite.artifacts().list_artifacts_for_build page = 1 artifacts = [] while page: response = list(org, pipeline, build_number, page=page, with_pagination=True) for artifact in response.body: artifacts.append(artifact) page = response.next_page if page: logger.debug('Fetching page {} of artifacts.'.format(page)) return artifacts