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(docker): Check if owner is an organization or user #8300

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 18 additions & 5 deletions .github/actions/ortdocker/check_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
import sys

import requests
from requests import Response

""" Use current GitHub API to check if a container image with the
given name and version exists.
"""

token = os.getenv("INPUT_TOKEN")
org = os.getenv("GITHUB_REPOSITORY_OWNER")
owner = os.getenv("GITHUB_REPOSITORY_OWNER")
name = os.getenv("INPUT_NAME")
base_version = os.getenv("INPUT_VERSION")
build_args = os.getenv("BUILD_ARGS")
Expand All @@ -41,19 +42,31 @@
print(version)
sys.exit(0)

url = f"https://api.github.com/orgs/{org}/packages/container/ort%2F{name}/versions"

headers = {
headers: dict[str, str] = {
"Accept": "application/vnd.github+json",
"Authorization": f"Bearer {token}",
"X-GitHub-Api-Version": "2022-11-28",
}

url: str = f"https://api.github.com/users/{owner}"
response = requests.get(url, headers=headers)
data: Response = response.json()

if data.get("type") == "Organization":
url = (
f"https://api.github.com/orgs/{owner}/packages/container/ort%2F{name}/versions"
)
else:
url = f"https://api.github.com/user/packages/container/ort%2F{name}/versions"

response = requests.get(url, headers=headers)
if response.status_code == 404:
print("none")
else:
data = response.json()
versions = [
item
for sublist in [v["metadata"]["container"]["tags"] for v in response.json()]
for sublist in [v["metadata"]["container"]["tags"] for v in data]
if sublist
for item in sublist
]
Expand Down
Loading