Skip to content

Commit

Permalink
Merge pull request #118 from Nerixyz/fix/more-pr
Browse files Browse the repository at this point in the history
fix: download artifacts as binary blobs and follow redirects
  • Loading branch information
ZedThree authored Mar 26, 2024
2 parents 9a32adc + 1d30432 commit fddb616
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 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
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

0 comments on commit fddb616

Please sign in to comment.