Skip to content

Commit 4eb70a0

Browse files
committed
github: add option to use release name instead of tag
fixes #278
1 parent 8d3b6ad commit 4eb70a0

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

docs/usage.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,12 +412,19 @@ use_latest_release
412412
small ones like `nvchecker's <https://github.com/lilydjwg/nvchecker/releases>`_
413413
are only git tags that should use ``use_max_tag`` below.
414414

415-
Will return the release name instead of date.
415+
Will return the release's tag name instead of date. (For historical reasons
416+
it doesn't return the release name. See below to change.)
417+
418+
use_release_name
419+
When ``use_latest_release`` is ``true``, setting this to ``true`` will cause
420+
nvchecker to return the release name instead of the tag name.
416421

417422
include_prereleases
418423
When ``use_latest_release`` is ``true``, set this to ``true`` to take prereleases into
419424
account.
420425

426+
This returns the release names (not the tag names).
427+
421428
This requires a token because it's using the v4 GraphQL API.
422429

423430
use_latest_tag

nvchecker_source/github.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,15 @@ async def get_version_real(
219219
if use_latest_release:
220220
if 'tag_name' not in data:
221221
raise GetVersionError('No release found in upstream repository.')
222+
223+
use_release_name = conf.get('use_release_name', False)
224+
if use_release_name:
225+
version = data['name']
226+
else:
227+
version = data['tag_name']
228+
222229
return RichResult(
223-
version = data['tag_name'],
230+
version = version,
224231
gitref = f"refs/tags/{data['tag_name']}",
225232
url = data['html_url'],
226233
)

tests/test_github.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ async def test_github_latest_release_include_prereleases(get_version):
3636
"include_prereleases": True,
3737
}) == "v0.0.1-pre"
3838

39+
async def test_github_latest_release_with_release_name(get_version):
40+
version = await get_version("example", {
41+
"source": "github",
42+
"github": "mamba-org/mamba",
43+
"use_latest_release": True,
44+
})
45+
assert version.startswith('20') # tag name
46+
47+
version = await get_version("example", {
48+
"source": "github",
49+
"github": "mamba-org/mamba",
50+
"use_latest_release": True,
51+
"use_release_name": True,
52+
})
53+
assert not version.startswith('20') # release name
54+
3955
async def test_github_max_tag(get_version):
4056
assert await get_version("example", {
4157
"source": "github",

0 commit comments

Comments
 (0)