From 28f1ab51443d88a7ab4f52feaf71aaa359f5fe9e Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Sun, 3 Nov 2024 19:08:40 +0800 Subject: [PATCH] github: make use_release_name=false work with include_prereleases also make gitref uses the full ref path format. (If someone handles this value to git, it should still works.) --- nvchecker_source/github.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/nvchecker_source/github.py b/nvchecker_source/github.py index 7f8e728..8585366 100644 --- a/nvchecker_source/github.py +++ b/nvchecker_source/github.py @@ -120,8 +120,8 @@ async def get_latest_tag(key: Tuple[str, str, str, str]) -> RichResult: url = f'https://github.com/{repo}/releases/tag/{version}', ) -async def get_latest_release_with_prereleases(key: Tuple[str, str, str]) -> RichResult: - host, repo, token = key +async def get_latest_release_with_prereleases(key: Tuple[str, str, str, str]) -> RichResult: + host, repo, token, use_release_name = key owner, reponame = repo.split('/') headers = { 'Authorization': f'bearer {token}', @@ -143,9 +143,15 @@ async def get_latest_release_with_prereleases(key: Tuple[str, str, str]) -> Rich if not refs: raise GetVersionError('no release found') + tag_name = refs[0]['node']['tag']['name'] + if use_release_name: + version = refs[0]['node']['name'] + else: + version = tag_name + return RichResult( - version = refs[0]['node']['name'], - gitref = refs[0]['node']['tag']['name'], + version = version, + gitref = f"refs/tags/{tag_name}", revision = refs[0]['node']['tagCommit']['oid'], url = refs[0]['node']['url'], ) @@ -174,11 +180,14 @@ async def get_version_real( use_latest_release = conf.get('use_latest_release', False) include_prereleases = conf.get('include_prereleases', False) + use_release_name = conf.get('use_release_name', False) if use_latest_release and include_prereleases: if not token: raise GetVersionError('token not given but it is required') - return await cache.get((host, repo, token), get_latest_release_with_prereleases) # type: ignore + return await cache.get( + (host, repo, token, use_release_name), + get_latest_release_with_prereleases) # type: ignore br = conf.get('branch') path = conf.get('path') @@ -220,7 +229,6 @@ async def get_version_real( if 'tag_name' not in data: raise GetVersionError('No release found in upstream repository.') - use_release_name = conf.get('use_release_name', False) if use_release_name: version = data['name'] else: