Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = [
"redo>=2.0",
"requests>=2.25",
"slugid>=2.0",
"taskcluster>=91.0,<92.0",
"taskcluster>=92.0",
"taskcluster-urls>=11.0",
"voluptuous>=0.12.1",
]
Expand Down
19 changes: 5 additions & 14 deletions src/taskgraph/util/taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,9 @@ def get_taskcluster_client(service: str):


def _handle_artifact(
path: str, response: Union[requests.Response, dict[str, Any]]
path: str,
response: requests.Response,
) -> Any:
# When taskcluster client returns non-JSON responses, it wraps them in {"response": <Response>}
if (
isinstance(response, dict)
and "response" in response
and isinstance(response["response"], requests.Response)
):
response = response["response"]

if not isinstance(response, requests.Response):
# At this point, if we don't have a response object, it's already parsed, return it
return response

# We have a response object, load the content based on the path extension.
if path.endswith(".json"):
return response.json()

Expand Down Expand Up @@ -159,6 +147,7 @@ def get_artifact(task_id, path):
"""
queue = get_taskcluster_client("queue")
response = queue.getLatestArtifact(task_id, path)
response = get_session().get(response["url"])
return _handle_artifact(path, response)


Expand Down Expand Up @@ -231,6 +220,8 @@ def pagination_handler(response):
def get_artifact_from_index(index_path, artifact_path):
index = get_taskcluster_client("index")
response = index.findArtifactFromTask(index_path, artifact_path)
assert 300 <= response["response"].status_code < 400
response = get_session().get(response["response"].headers["location"])
return _handle_artifact(artifact_path, response)


Expand Down
9 changes: 8 additions & 1 deletion test/test_util_taskcluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ def test_get_artifact_from_index(responses, root_url):

responses.get(
f"{root_url}/api/index/v1/task/{index}/artifacts/{path}",
body=b"foobar",
status=303,
headers={"Location": f"http://foo.bar/{path}"},
)
responses.get(f"http://foo.bar/{path}", body="foobar")

result = tc.get_artifact_from_index(index, path)
assert result.read() == b"foobar"
Expand All @@ -252,6 +254,11 @@ def test_get_artifact_from_index_uses_artifact_path_for_parsing(responses, root_

responses.get(
f"{root_url}/api/index/v1/task/{index_path}/artifacts/{artifact_path}",
status=303,
headers={"Location": f"http://foo.bar/{artifact_path}"},
)
responses.get(
f"http://foo.bar/{artifact_path}",
body=b"key: value",
)

Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading