Skip to content

Commit

Permalink
fix: download artifact as blob and follow redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
Nerixyz committed Mar 25, 2024
1 parent 3fb42e9 commit 1d30432
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
27 changes: 9 additions & 18 deletions post/clang_tidy_review/clang_tidy_review/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import subprocess
import textwrap
import unidiff
import urllib3
import yaml
import contextlib
import datetime
Expand All @@ -26,7 +27,6 @@
from github.Requester import Requester
from github.PaginatedList import PaginatedList
from github.WorkflowRun import WorkflowRun
from github.Artifact import Artifact
from typing import Any, List, Optional, TypedDict

DIFF_HEADER_LINE_LENGTH = 5
Expand Down Expand Up @@ -354,16 +354,6 @@ def post_annotations(self, review):
"POST", url, parameters=review, headers=headers
)

def download_json_artifact(self, artifact: Artifact) -> Any:
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {self.token}",
}
_, data = self.repo._requester.requestJsonAndCheck(
"GET", artifact.archive_download_url, headers=headers
)
return data


@contextlib.contextmanager
def message_group(title: str):
Expand Down Expand Up @@ -935,17 +925,18 @@ def download_artifacts(pull: PullRequest, workflow_id: int):
)
return None, None

try:
data = pull.download_json_artifact(artifact)
except GithubException as exc:
headers = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {pull.token}",
}
r = urllib3.request("GET", artifact.archive_download_url, headers=headers)
if r.status is not 200:
print(
f"WARNING: Couldn't automatically download artifacts for workflow '{workflow_id}', response was: {exc}"
f"WARNING: Couldn't automatically download artifacts for workflow '{workflow_id}', response was: {r}: {r.reason}"
)
return None, None

contents = b"".join(data["data"].iter_content())

data = zipfile.ZipFile(io.BytesIO(contents))
data = zipfile.ZipFile(io.BytesIO(r.data))
filenames = data.namelist()

metadata = (
Expand Down
1 change: 1 addition & 0 deletions post/clang_tidy_review/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies = [
"PyGithub ~= 2.1",
"unidiff ~= 0.6.0",
"pyyaml ~= 6.0.1",
"urllib3 ~= 2.2.1",
]
keywords = ["C++", "static-analysis"]
dynamic = ["version"]
Expand Down

0 comments on commit 1d30432

Please sign in to comment.