mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
git source: support fetching commit hash on a branch
This commit is contained in:
parent
a0c32ce5f0
commit
491a71add7
3 changed files with 39 additions and 6 deletions
|
@ -666,12 +666,18 @@ Check Git repository
|
||||||
|
|
||||||
source = "git"
|
source = "git"
|
||||||
|
|
||||||
This enables you to check tags of an arbitrary git repository, also useful for scenarios like a github project having too many tags.
|
This enables you to check tags or branch commits of an arbitrary git repository, also useful for scenarios like a github project having too many tags.
|
||||||
|
|
||||||
git
|
git
|
||||||
URL of the Git repository.
|
URL of the Git repository.
|
||||||
|
|
||||||
This source returns tags and supports :ref:`list options`.
|
use_commit
|
||||||
|
Return a commit hash instead of tags.
|
||||||
|
|
||||||
|
branch
|
||||||
|
When ``use_commit`` is true, return the commit on the specified branch instead of the default one.
|
||||||
|
|
||||||
|
When this source returns tags (``use_commit`` is not true) it supports :ref:`list options`.
|
||||||
|
|
||||||
Check container registry
|
Check container registry
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
|
@ -7,7 +7,19 @@ async def get_version(
|
||||||
name, conf, *, cache, keymanager=None
|
name, conf, *, cache, keymanager=None
|
||||||
):
|
):
|
||||||
git = conf['git']
|
git = conf['git']
|
||||||
cmd = f"git ls-remote -t --refs {git}"
|
|
||||||
|
use_commit = conf.get('use_commit', False)
|
||||||
|
if use_commit:
|
||||||
|
ref = conf.get('branch')
|
||||||
|
if ref is None:
|
||||||
|
ref = 'HEAD'
|
||||||
|
else:
|
||||||
|
ref = 'refs/heads/' + ref
|
||||||
|
cmd = f"git ls-remote {git} {ref}"
|
||||||
|
data = await cache.get(cmd, run_cmd)
|
||||||
|
return data.split(None, 1)[0]
|
||||||
|
else:
|
||||||
|
cmd = f"git ls-remote --tags --refs {git}"
|
||||||
data = await cache.get(cmd, run_cmd)
|
data = await cache.get(cmd, run_cmd)
|
||||||
versions = [line.split("refs/tags/")[1] for line in data.splitlines()]
|
versions = [line.split("refs/tags/")[1] for line in data.splitlines()]
|
||||||
return versions
|
return versions
|
||||||
|
|
|
@ -9,3 +9,18 @@ async def test_git(get_version):
|
||||||
"source": "git",
|
"source": "git",
|
||||||
"git": "https://gitlab.com/gitlab-org/gitlab-test.git",
|
"git": "https://gitlab.com/gitlab-org/gitlab-test.git",
|
||||||
}) == "v1.1.1"
|
}) == "v1.1.1"
|
||||||
|
|
||||||
|
async def test_git_commit(get_version):
|
||||||
|
assert await get_version("example", {
|
||||||
|
"source": "git",
|
||||||
|
"git": "https://gitlab.com/gitlab-org/gitlab-test.git",
|
||||||
|
"use_commit": True,
|
||||||
|
}) == "ddd0f15ae83993f5cb66a927a28673882e99100b"
|
||||||
|
|
||||||
|
async def test_git_commit_branch(get_version):
|
||||||
|
assert await get_version("example", {
|
||||||
|
"source": "git",
|
||||||
|
"git": "https://gitlab.com/gitlab-org/gitlab-test.git",
|
||||||
|
"use_commit": True,
|
||||||
|
"branch": "with-executables",
|
||||||
|
}) == "6b8dc4a827797aa025ff6b8f425e583858a10d4f"
|
||||||
|
|
Loading…
Add table
Reference in a new issue