diff --git a/README.rst b/README.rst index 9e7a63e..596aaee 100644 --- a/README.rst +++ b/README.rst @@ -249,6 +249,9 @@ github branch Which branch to track? Default: ``master``. +path + Only commits containing this file path will be returned. + use_latest_release Set this to ``true`` to check for the latest release on GitHub. An annotated tag creates a "release" on GitHub. It's not the same with git tags, which diff --git a/nvchecker/source/github.py b/nvchecker/source/github.py index 2edd049..cc0b5be 100644 --- a/nvchecker/source/github.py +++ b/nvchecker/source/github.py @@ -4,6 +4,7 @@ import os import re import time +from urllib.parse import urlencode from functools import partial import structlog @@ -26,6 +27,7 @@ async def get_version(name, conf, **kwargs): async def get_version_real(name, conf, **kwargs): repo = conf.get('github') br = conf.get('branch') + path = conf.get('path') use_latest_release = conf.getboolean('use_latest_release', False) use_max_tag = conf.getboolean('use_max_tag', False) include_tags_pattern = conf.get("include_tags_pattern", "") @@ -37,8 +39,12 @@ async def get_version_real(name, conf, **kwargs): url = GITHUB_MAX_TAG % repo else: url = GITHUB_URL % repo + parameters = {} if br: - url += '?sha=' + br + parameters['sha'] = br + if path: + parameters['path'] = path + url += '?' + urlencode(parameters) headers = { 'Accept': 'application/vnd.github.quicksilver-preview+json', 'User-Agent': 'lilydjwg/nvchecker', diff --git a/tests/test_github.py b/tests/test_github.py index 59fbed1..ff7aae2 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -23,6 +23,12 @@ async def test_github_max_tag(get_version): async def test_github_max_tag_with_ignored_tags(get_version): assert await get_version("example", {"github": "harry-sanabria/ReleaseTestRepo", "use_max_tag": 1, "ignored_tags": "second_release release3"}) == "first_release" +async def test_github_with_path(get_version): + assert await get_version("example", {"github": "petronny/ReleaseTestRepo", "path": "test_directory"}) == "20140122.012101" + +async def test_github_with_path_and_branch(get_version): + assert await get_version("example", {"github": "petronny/ReleaseTestRepo", "branch": "test", "path": "test_directory/test_directory"}) == "20190128.113201" + async def test_github_max_tag_with_include(get_version): version = await get_version("example", { "github": "EFForg/https-everywhere",