Skip to content

Commit

Permalink
github: add option to use release name instead of tag
Browse files Browse the repository at this point in the history
fixes #278
  • Loading branch information
lilydjwg committed Nov 3, 2024
1 parent 8d3b6ad commit 4eb70a0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
9 changes: 8 additions & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,19 @@ use_latest_release
small ones like `nvchecker's <https://github.com/lilydjwg/nvchecker/releases>`_
are only git tags that should use ``use_max_tag`` below.

Will return the release name instead of date.
Will return the release's tag name instead of date. (For historical reasons
it doesn't return the release name. See below to change.)

use_release_name
When ``use_latest_release`` is ``true``, setting this to ``true`` will cause
nvchecker to return the release name instead of the tag name.

include_prereleases
When ``use_latest_release`` is ``true``, set this to ``true`` to take prereleases into
account.

This returns the release names (not the tag names).

This requires a token because it's using the v4 GraphQL API.

use_latest_tag
Expand Down
9 changes: 8 additions & 1 deletion nvchecker_source/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,15 @@ async def get_version_real(
if use_latest_release:
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:
version = data['tag_name']

return RichResult(
version = data['tag_name'],
version = version,
gitref = f"refs/tags/{data['tag_name']}",
url = data['html_url'],
)
Expand Down
16 changes: 16 additions & 0 deletions tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ async def test_github_latest_release_include_prereleases(get_version):
"include_prereleases": True,
}) == "v0.0.1-pre"

async def test_github_latest_release_with_release_name(get_version):
version = await get_version("example", {
"source": "github",
"github": "mamba-org/mamba",
"use_latest_release": True,
})
assert version.startswith('20') # tag name

version = await get_version("example", {
"source": "github",
"github": "mamba-org/mamba",
"use_latest_release": True,
"use_release_name": True,
})
assert not version.startswith('20') # release name

async def test_github_max_tag(get_version):
assert await get_version("example", {
"source": "github",
Expand Down

0 comments on commit 4eb70a0

Please sign in to comment.