diff --git a/README.rst b/README.rst index 4096829..03e6eaf 100644 --- a/README.rst +++ b/README.rst @@ -56,6 +56,7 @@ Contents * `Check Anitya (release-monitoring.org) <#check-anitya>`_ * `Check Android SDK <#check-android-sdk>`_ * `Check Sparkle framework <#check-sparkle-framework>`_ + * `Check Pagure <#check-pagure>`_ * `Manually updating <#manually-updating>`_ * `Extending <#extending>`_ @@ -633,6 +634,20 @@ This enables you to track updates of macOS applications which using `Sparkle fra sparkle The url of the sparkle appcast. +Check Pagure +------------ +:: + + source = "pagure" + +This enables you to check updates from `Pagure `_. + +pagure + The project name, optionally with a namespace. + +host + Hostname of alternative instance like src.fedoraproject.org. + Manually updating ----------------- :: diff --git a/nvchecker_source/pagure.py b/nvchecker_source/pagure.py new file mode 100644 index 0000000..9d725c8 --- /dev/null +++ b/nvchecker_source/pagure.py @@ -0,0 +1,31 @@ +# MIT licensed +# Copyright (c) 2020 Felix Yan , et al. + +import urllib.parse + +import structlog + +from nvchecker.api import ( + VersionResult, Entry, AsyncCache, KeyManager, +) + +PAGURE_URL = 'https://%s/api/0/%s/git/tags' + +logger = structlog.get_logger(logger_name=__name__) + +async def get_version(name, conf, **kwargs): + return await get_version_real(name, conf, **kwargs) + +async def get_version_real( + name: str, conf: Entry, *, + cache: AsyncCache, keymanager: KeyManager, + **kwargs, +) -> VersionResult: + repo = conf['pagure'] + host = conf.get('host', "pagure.io") + + url = PAGURE_URL % (host, repo) + + data = await cache.get_json(url) + version = data["tags"] + return version diff --git a/tests/test_pagure.py b/tests/test_pagure.py new file mode 100644 index 0000000..daeb966 --- /dev/null +++ b/tests/test_pagure.py @@ -0,0 +1,29 @@ +# MIT licensed +# Copyright (c) 2020 Felix Yan , et al. + +import pytest +pytestmark = [pytest.mark.asyncio, pytest.mark.needs_net] + +async def test_pagure(get_version): + ver = await get_version("example", { + "source": "pagure", + "pagure": "nvchecker-test", + }) + assert ver == "0.2" + +async def test_pagure_with_ignored(get_version): + ver = await get_version("example", { + "source": "pagure", + "pagure": "nvchecker-test", + "ignored": "0.2", + }) + assert ver == "0.1" + +async def test_pagure_with_alternative_host(get_version): + ver = await get_version("example", { + "source": "pagure", + "pagure": "rpms/glibc", + "host": "src.fedoraproject.org", + "include_regex": r"F-\d+-start", + }) + assert ver == "F-13-start"