1111
1212def get_packages (owner , tag , api_token = None ):
1313 """Function to collect GHCR packages for a given owner & tag
14-
14+
1515 Parameters
1616 ----------
1717 owner : str
1818 username or org name
19-
19+
2020 tag : str
2121 image tag (part left of the colon)
2222
2323 api_token : str or None
2424 GitHub API personal access token with read.packages permission
25-
25+
2626 Returns
2727 -------
2828 list
@@ -32,11 +32,11 @@ def get_packages(owner, tag, api_token=None):
3232
3333 def fetch (url ):
3434 """Method to make API call and return response, given a URL
35-
35+
3636 Parameters
3737 ----------
3838 url : str
39-
39+
4040 Returns
4141 -------
4242 dict or list
@@ -59,34 +59,36 @@ def fetch(url):
5959 '$VERSION_TAG $GITHUB_TOKEN`'
6060 ]))
6161 return response
62- packages = fetch (
62+ _packages = fetch (
6363 f'https://api.github.com/orgs/{ owner } /packages/container/'
6464 f'{ tag } /versions' )
65- if packages .get ('message' , 'Not Found' ) == 'Not Found' :
66- packages = fetch (
67- f'https://api.github.com/users/{ owner } /packages/container/'
68- f'{ tag } /versions' )
65+ packages = []
66+ for _package in _packages :
67+ if _package .get ('message' , 'Not Found' ) == 'Not Found' :
68+ packages += fetch (
69+ f'https://api.github.com/users/{ owner } /packages/container/'
70+ f'{ tag } /versions' )
6971 return packages
7072
7173
7274def id_from_tag (owner , image , tag , api_token = None ):
7375 """Function to return a package ID given an image version tag
74-
76+
7577 Parameters
7678 ----------
7779 owner : str
7880 GitHub username or org name
79-
81+
8082 image : str
8183 Image tag (the part to the left of the colon)
82-
84+
8385 tag : str
8486 Image version tag (the part to the right of the colon)
8587
8688 api_token: str or None
8789 GitHub API personal access token with read.packages permission
8890 """
89- packages = get_packages (owner , image )
91+ packages = get_packages (owner , image , api_token )
9092 versions = [image ['id' ] for image in packages if tag in image .get (
9193 'metadata' , {}
9294 ).get ('container' , {}).get ('tags' , [])]
0 commit comments