Skip to content

Commit 1d30432

Browse files
committed
fix: download artifact as blob and follow redirects
1 parent 3fb42e9 commit 1d30432

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

post/clang_tidy_review/clang_tidy_review/__init__.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import subprocess
1616
import textwrap
1717
import unidiff
18+
import urllib3
1819
import yaml
1920
import contextlib
2021
import datetime
@@ -26,7 +27,6 @@
2627
from github.Requester import Requester
2728
from github.PaginatedList import PaginatedList
2829
from github.WorkflowRun import WorkflowRun
29-
from github.Artifact import Artifact
3030
from typing import Any, List, Optional, TypedDict
3131

3232
DIFF_HEADER_LINE_LENGTH = 5
@@ -354,16 +354,6 @@ def post_annotations(self, review):
354354
"POST", url, parameters=review, headers=headers
355355
)
356356

357-
def download_json_artifact(self, artifact: Artifact) -> Any:
358-
headers = {
359-
"Accept": "application/vnd.github+json",
360-
"Authorization": f"Bearer {self.token}",
361-
}
362-
_, data = self.repo._requester.requestJsonAndCheck(
363-
"GET", artifact.archive_download_url, headers=headers
364-
)
365-
return data
366-
367357

368358
@contextlib.contextmanager
369359
def message_group(title: str):
@@ -935,17 +925,18 @@ def download_artifacts(pull: PullRequest, workflow_id: int):
935925
)
936926
return None, None
937927

938-
try:
939-
data = pull.download_json_artifact(artifact)
940-
except GithubException as exc:
928+
headers = {
929+
"Accept": "application/vnd.github+json",
930+
"Authorization": f"Bearer {pull.token}",
931+
}
932+
r = urllib3.request("GET", artifact.archive_download_url, headers=headers)
933+
if r.status is not 200:
941934
print(
942-
f"WARNING: Couldn't automatically download artifacts for workflow '{workflow_id}', response was: {exc}"
935+
f"WARNING: Couldn't automatically download artifacts for workflow '{workflow_id}', response was: {r}: {r.reason}"
943936
)
944937
return None, None
945938

946-
contents = b"".join(data["data"].iter_content())
947-
948-
data = zipfile.ZipFile(io.BytesIO(contents))
939+
data = zipfile.ZipFile(io.BytesIO(r.data))
949940
filenames = data.namelist()
950941

951942
metadata = (

post/clang_tidy_review/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies = [
1616
"PyGithub ~= 2.1",
1717
"unidiff ~= 0.6.0",
1818
"pyyaml ~= 6.0.1",
19+
"urllib3 ~= 2.2.1",
1920
]
2021
keywords = ["C++", "static-analysis"]
2122
dynamic = ["version"]

0 commit comments

Comments
 (0)