diff --git a/docs/usage.rst b/docs/usage.rst index ce576b4..be6ba29 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -641,6 +641,19 @@ strip_release Note that either pkg or srcpkg needs to be specified (but not both) or the item name will be used as pkg. +Check Git repository +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +:: + + 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. + +url + URL of the Git repository. + +This source returns tags and supports :ref:`list options`. + Manually updating ~~~~~~~~~~~~~~~~~ :: diff --git a/nvchecker_source/git.py b/nvchecker_source/git.py new file mode 100644 index 0000000..2f70104 --- /dev/null +++ b/nvchecker_source/git.py @@ -0,0 +1,13 @@ +# MIT licensed +# Copyright (c) 2020 Felix Yan , et al. + +from .cmd import run_cmd # type: ignore + +async def get_version( + name, conf, *, cache, keymanager=None +): + git = conf['git'] + cmd = f"git ls-remote -t --refs {git}" + data = await cache.get(cmd, run_cmd) + versions = [line.split("refs/tags/")[1] for line in data.splitlines()] + return versions diff --git a/tests/test_git.py b/tests/test_git.py new file mode 100644 index 0000000..03a9c5a --- /dev/null +++ b/tests/test_git.py @@ -0,0 +1,11 @@ +# MIT licensed +# Copyright (c) 2020 Felix Yan , et al. + +import pytest +pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] + +async def test_git(get_version): + assert await get_version("example", { + "source": "git", + "git": "https://gitlab.com/gitlab-org/gitlab-test.git", + }) == "v1.1.1"