Add ignored_tags support

Ignore certain tags while sorting. This option must be used together with
use_max_tag. This can be useful to avoid some known badly versioned tags,
so the newer tags won't be "overriden" by the old broken ones.
This commit is contained in:
Felix Yan 2015-12-23 21:02:06 +08:00
parent b34861f9cd
commit e723053c41
7 changed files with 40 additions and 11 deletions

View file

@ -174,6 +174,11 @@ use_max_tag
this option includes both annotated tags and lightweight ones, and return the biggest one
sorted by ``pkg_resources.parse_version``.
ignored_tags
Ignore certain tags while sorting. Tags are separate by whitespaces. This option must be
used together with use_max_tag. This can be useful to avoid some known badly versioned
tags, so the newer tags won't be "overridden" by the old broken ones.
An environment variable ``NVCHECKER_GITHUB_TOKEN`` can be set to a GitHub OAuth token in order to request more frequently than anonymously.
Check BitBucket
@ -190,6 +195,11 @@ use_max_tag
Set this to ``true`` to check for the max tag on BitBucket. Will return the biggest one
sorted by ``pkg_resources.parse_version``.
ignored_tags
Ignore certain tags while sorting. Tags are separate by whitespaces. This option must be
used together with use_max_tag. This can be useful to avoid some known badly versioned
tags, so the newer tags won't be "overridden" by the old broken ones.
Check GitCafe
-------------
Check `GitCafe <https://gitcafe.com/>`_ for updates. The version returned is in date format ``%Y%m%d``, e.g. ``20130701``.
@ -216,6 +226,11 @@ use_max_tag
Set this to ``true`` to check for the max tag on BitBucket. Will return the biggest one
sorted by ``pkg_resources.parse_version``.
ignored_tags
Ignore certain tags while sorting. Tags are separate by whitespaces. This option must be
used together with use_max_tag. This can be useful to avoid some known badly versioned
tags, so the newer tags won't be "overridden" by the old broken ones.
host
Hostname for self-hosted GitLab instance.

View file

@ -13,18 +13,19 @@ def get_version(name, conf, callback):
repo = conf.get('bitbucket')
br = conf.get('branch', '')
use_max_tag = conf.getboolean('use_max_tag', False)
ignored_tags = conf.get("ignored_tags", "").split()
if use_max_tag:
url = BITBUCKET_MAX_TAG % repo
else:
url = BITBUCKET_URL % (repo, br)
request = HTTPRequest(url, user_agent='lilydjwg/nvchecker')
AsyncHTTPClient().fetch(request,
callback=partial(_bitbucket_done, name, use_max_tag, callback))
callback=partial(_bitbucket_done, name, use_max_tag, ignored_tags, callback))
def _bitbucket_done(name, use_max_tag, callback, res):
def _bitbucket_done(name, use_max_tag, ignored_tags, callback, res):
data = json.loads(res.body.decode('utf-8'))
if use_max_tag:
data = list(data)
data = [tag for tag in data if tag not in ignored_tags]
data.sort(key=parse_version)
version = data[-1]
else:

View file

@ -14,6 +14,7 @@ def get_version(name, conf, callback):
br = conf.get('branch', 'master')
use_latest_release = conf.getboolean('use_latest_release', False)
use_max_tag = conf.getboolean('use_max_tag', False)
ignored_tags = conf.get("ignored_tags", "").split()
if use_latest_release:
url = GITHUB_LATEST_RELEASE % repo
elif use_max_tag:
@ -25,15 +26,16 @@ def get_version(name, conf, callback):
headers['Authorization'] = 'token %s' % os.environ['NVCHECKER_GITHUB_TOKEN']
request = HTTPRequest(url, headers=headers, user_agent='lilydjwg/nvchecker')
AsyncHTTPClient().fetch(request,
callback=partial(_github_done, name, use_latest_release, use_max_tag, callback))
callback=partial(_github_done, name, use_latest_release, use_max_tag, ignored_tags, callback))
def _github_done(name, use_latest_release, use_max_tag, callback, res):
def _github_done(name, use_latest_release, use_max_tag, ignored_tags, callback, res):
data = json.loads(res.body.decode('utf-8'))
if use_latest_release:
version = data['tag_name']
elif use_max_tag:
data.sort(key=lambda tag: parse_version(tag["name"]))
version = data[-1]["name"]
data = [tag["name"] for tag in data if tag["name"] not in ignored_tags]
data.sort(key=parse_version)
version = data[-1]
else:
version = data[0]['commit']['committer']['date'].split('T', 1)[0].replace('-', '')
callback(name, version)

View file

@ -17,6 +17,7 @@ def get_version(name, conf, callback):
br = conf.get('branch', 'master')
host = conf.get('host', "gitlab.com")
use_max_tag = conf.getboolean('use_max_tag', False)
ignored_tags = conf.get("ignored_tags", "").split()
env_name = "NVCHECKER_GITLAB_TOKEN_" + host.upper().replace(".", "_").replace("/", "_")
token = conf.get('token', os.environ.get(env_name, None))
@ -33,13 +34,14 @@ def get_version(name, conf, callback):
headers = {"PRIVATE-TOKEN": token}
request = HTTPRequest(url, headers=headers, user_agent='lilydjwg/nvchecker')
AsyncHTTPClient().fetch(request,
callback=partial(_gitlab_done, name, use_max_tag, callback))
callback=partial(_gitlab_done, name, use_max_tag, ignored_tags, callback))
def _gitlab_done(name, use_max_tag, callback, res):
def _gitlab_done(name, use_max_tag, ignored_tags, callback, res):
data = json.loads(res.body.decode('utf-8'))
if use_max_tag:
data.sort(key=lambda tag: parse_version(tag["name"]))
version = data[-1]["name"]
data = [tag["name"] for tag in data if tag["name"] not in ignored_tags]
data.sort(key=parse_version)
version = data[-1]
else:
version = data[0]['created_at'].split('T', 1)[0].replace('-', '')
callback(name, version)

View file

@ -7,3 +7,6 @@ class BitBucketTest(ExternalVersionTestCase):
def test_bitbucket_max_tag(self):
self.assertEqual(self.sync_get_version("example", {"bitbucket": "prawee/git-tag", "use_max_tag": 1}), "1.7.0")
def test_bitbucket_max_tag_with_ignored_tags(self):
self.assertEqual(self.sync_get_version("example", {"bitbucket": "prawee/git-tag", "use_max_tag": 1, "ignored_tags": "1.6.0 1.7.0"}), "v1.5")

View file

@ -14,3 +14,6 @@ class GitHubTest(ExternalVersionTestCase):
def test_github_max_tag(self):
self.assertEqual(self.sync_get_version("example", {"github": "harry-sanabria/ReleaseTestRepo", "use_max_tag": 1}), "second_release")
def test_github_max_tag_with_ignored_tags(self):
self.assertEqual(self.sync_get_version("example", {"github": "harry-sanabria/ReleaseTestRepo", "use_max_tag": 1, "ignored_tags": "second_release release3"}), "first_release")

View file

@ -14,3 +14,6 @@ class GitLabTest(ExternalVersionTestCase):
def test_gitlab_max_tag(self):
self.assertEqual(self.sync_get_version("example", {"gitlab": "gitlab-org/gitlab-test", "use_max_tag": 1}), "v1.1.0")
def test_gitlab_max_tag_with_ignored_tags(self):
self.assertEqual(self.sync_get_version("example", {"gitlab": "gitlab-org/gitlab-test", "use_max_tag": 1, "ignored_tags": "v1.1.0"}), "v1.0.0")