Skip to content

Commit

Permalink
github: make use_release_name=false work with include_prereleases
Browse files Browse the repository at this point in the history
also make gitref uses the full ref path format. (If someone handles this
value to git, it should still works.)
  • Loading branch information
lilydjwg committed Nov 3, 2024
1 parent e1a6517 commit 28f1ab5
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions nvchecker_source/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand All @@ -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'],
)
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 28f1ab5

Please sign in to comment.