Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: download artifacts as binary blobs and follow redirects #118

Merged
merged 2 commits into from
Mar 26, 2024
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
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
2 changes: 1 addition & 1 deletion upload/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ branding:
runs:
using: 'composite'
steps:
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: clang-tidy-review
path: |
Expand Down
Loading