Merge pull request #153 from felixonmars/git

Add a git source
This commit is contained in:
依云 2020-09-24 16:44:50 +08:00 committed by GitHub
commit 121b94a7eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 0 deletions

View File

@ -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
~~~~~~~~~~~~~~~~~
::

13
nvchecker_source/git.py Normal file
View File

@ -0,0 +1,13 @@
# MIT licensed
# Copyright (c) 2020 Felix Yan <felixonmars@archlinux.org>, 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

11
tests/test_git.py Normal file
View File

@ -0,0 +1,11 @@
# MIT licensed
# Copyright (c) 2020 Felix Yan <felixonmars@archlinux.org>, 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"