From 5f8db2fa47a4dba11fcd4e9ec0c662ecbcdbeebc Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Tue, 27 Aug 2024 18:48:09 -0500 Subject: [PATCH] source/docker: Add regex match for tags Repositories on Docker Hub often have images we do not want to consider when determining the "latest" version of an application, such as non=container images, development/testing versions, etc. To exclude these, project sources can now define a `version_re` property that contains a regular expression. Images that do not match the expression will be ignored. --- updatebot.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/updatebot.py b/updatebot.py index 589b5f9..953923c 100644 --- a/updatebot.py +++ b/updatebot.py @@ -79,6 +79,7 @@ class DockerHubSource(BaseSource): kind: Literal['docker'] namespace: str repository: str + version_re: str = r'^(?P[0-9]+(\.[0-9]+)*(-[0-9]+)?)$' def get_latest_version(self) -> str: session = _get_session() @@ -89,10 +90,18 @@ class DockerHubSource(BaseSource): r = session.get(url) data = r.json() versions = [] + regex = re.compile(self.version_re) for result in data['results']: - if result['name'] == 'latest': + m = regex.match(result['name']) + if not m: + log.debug( + 'Skipping tag %s: does not match regex %s', + result['name'], + self.version_re, + ) continue - versions.append((result['last_updated'], result['name'])) + version = m.groupdict()['version'] + versions.append((result['last_updated'], version)) versions.sort() return versions[-1][-1]