From f8f261c47673846f8da3a265fae7876e18c7a8b0 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Thu, 18 Mar 2021 13:18:03 +0800 Subject: [PATCH] gitlab: omit default branch if not specified, fix for blm --- nvchecker_source/gitlab.py | 8 +++++--- tests/test_gitlab.py | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/nvchecker_source/gitlab.py b/nvchecker_source/gitlab.py index 0a22ece..844d93b 100644 --- a/nvchecker_source/gitlab.py +++ b/nvchecker_source/gitlab.py @@ -10,7 +10,7 @@ from nvchecker.api import ( TemporaryError, ) -GITLAB_URL = 'https://%s/api/v4/projects/%s/repository/commits?ref_name=%s' +GITLAB_URL = 'https://%s/api/v4/projects/%s/repository/commits' GITLAB_MAX_TAG = 'https://%s/api/v4/projects/%s/repository/tags' logger = structlog.get_logger(logger_name=__name__) @@ -27,14 +27,16 @@ async def get_version_real( **kwargs, ) -> VersionResult: repo = urllib.parse.quote_plus(conf['gitlab']) - br = conf.get('branch', 'master') + br = conf.get('branch') host = conf.get('host', "gitlab.com") use_max_tag = conf.get('use_max_tag', False) if use_max_tag: url = GITLAB_MAX_TAG % (host, repo) else: - url = GITLAB_URL % (host, repo, br) + url = GITLAB_URL % (host, repo) + if br: + url += '?ref_name=%s' % br # Load token from config token = conf.get('token') diff --git a/tests/test_gitlab.py b/tests/test_gitlab.py index 85d269b..e279b46 100644 --- a/tests/test_gitlab.py +++ b/tests/test_gitlab.py @@ -12,6 +12,15 @@ async def test_gitlab(get_version): assert len(ver) == 8 assert ver.isdigit() +async def test_gitlab_blm(get_version): + # repo with a custom main branch + ver = await get_version("example", { + "source": "gitlab", + "gitlab": "asus-linux/asus-nb-ctrl", + }) + assert len(ver) == 8 + assert ver.isdigit() + async def test_gitlab_max_tag(get_version): assert await get_version("example", { "source": "gitlab",