From f00c6d163f7ae209d024824c6a54afa4043700b5 Mon Sep 17 00:00:00 2001 From: Felix Yan Date: Wed, 18 Nov 2020 01:28:45 +0800 Subject: [PATCH] Add a mercurial source This uses the json api of mercurial repositories. Verified to work on the following hosting sites: www.mercurial-scm.org/repo hg.code.sf.net hg.nginx.org hg.mozilla.org --- docs/usage.rst | 13 +++++++++++++ nvchecker_source/mercurial.py | 10 ++++++++++ tests/test_mercurial.py | 11 +++++++++++ 3 files changed, 34 insertions(+) create mode 100644 nvchecker_source/mercurial.py create mode 100644 tests/test_mercurial.py diff --git a/docs/usage.rst b/docs/usage.rst index 5ae2b39..7346036 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -673,6 +673,19 @@ git This source returns tags and supports :ref:`list options`. +Check Mercurial repository +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +:: + + source = "mercurial" + +This enables you to check tags of an arbitrary mercurial repository. + +mercurial + URL of the Mercurial repository. + +This source returns tags and supports :ref:`list options`. + Check container registry ~~~~~~~~~~~~~~~~~~~~~~~~ :: diff --git a/nvchecker_source/mercurial.py b/nvchecker_source/mercurial.py new file mode 100644 index 0000000..db3cd34 --- /dev/null +++ b/nvchecker_source/mercurial.py @@ -0,0 +1,10 @@ +# MIT licensed +# Copyright (c) 2020 Felix Yan , et al. + +async def get_version(name, conf, *, cache, **kwargs): + url = conf.get('mercurial') + '/json-tags' + + data = await cache.get_json(url) + + version = [tag['tag'] for tag in data['tags']] + return version diff --git a/tests/test_mercurial.py b/tests/test_mercurial.py new file mode 100644 index 0000000..07349a8 --- /dev/null +++ b/tests/test_mercurial.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_mercurial(get_version): + assert await get_version("example", { + "source": "mercurial", + "mercurial": "https://www.mercurial-scm.org/repo/users/sid0/hg-git", + }) == "0.8.0"