Add a git source

It's a thin wrapper around the cmd source, and reuses its get_cmd
function.
This commit is contained in:
Felix Yan 2020-09-24 04:25:08 +08:00
parent a78c06163c
commit c9b689d67b
No known key found for this signature in database
GPG Key ID: 786C63F330D7CB92
3 changed files with 39 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
~~~~~~~~~~~~~~~~~
::

15
nvchecker_source/git.py Normal file
View File

@ -0,0 +1,15 @@
# MIT licensed
# Copyright (c) 2020 Felix Yan <felixonmars@archlinux.org>, et al.
import re
from nvchecker_source.cmd import run_cmd
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)
regex = "(?<=refs/tags/).*$"
return re.findall(regex, data)

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"