42 lines
1.2 KiB
Python

import requests
from secret_handler import return_credentials
github_token = return_credentials("/etc/secrets/github_token")
def find_package_version_with_tag(org:str,package:str,target_tag:str)->str:
"""
Iterates through the available pages looking for the supplied target_tag
Either returns None or a string when successful
"""
headers = {
"Authorization": f"Bearer {github_token}",
"Accept": "application/vnd.github+json"
}
page = 1
per_page = 100
while True:
url = f"https://api.github.com/orgs/{org}/packages/container/{package}/versions"
params = {"per_page": per_page, "page": page}
response = requests.get(url, headers=headers, params=params)
if response.status_code != 200:
print(f"Error {response.status_code}: {response.text}")
return None
versions = response.json()
if not versions:
print(f"Reached end of pages — tag '{target_tag}' not found.")
return None
for version in versions:
tags = version.get("metadata", {}).get("container", {}).get("tags", [])
if target_tag in tags:
print(f"Found tag '{target_tag}' on page {page}:\n")
return version["id"]
page += 1
if __name__ == "__main__":
find_package_version_with_tag("Suwayomi", "tachidesk", "stable")