Handle exception for no-tag situation

Before:
```
[E 01-09 11:26:03.736 core:132] unexpected error happened with dnscrypt-proxy
    Traceback (most recent call last):
      File "/usr/lib/python3.6/site-packages/nvchecker/core.py", line 128, in future_done
        version = fu.result()
      File "/usr/lib/python3.6/site-packages/nvchecker/get_version.py", line 43, in get_version
        version = await func(name, conf)
      File "/usr/lib/python3.6/site-packages/nvchecker/source/github.py", line 43, in get_version
        version = data[-1]
    IndexError: list index out of range
```

After:
```
[E 01-09 11:32:35.308 github:50] dnscrypt-proxy: No tag found in upstream repository.
```
This commit is contained in:
Felix Yan 2018-01-09 11:32:50 +08:00
parent 1693d82fd4
commit 9ad63287eb
No known key found for this signature in database
GPG Key ID: 786C63F330D7CB92

View File

@ -2,6 +2,7 @@
# Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al. # Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al.
import os import os
import logging
from . import session from . import session
from ..sortversion import sort_version_keys from ..sortversion import sort_version_keys
@ -10,6 +11,8 @@ GITHUB_URL = 'https://api.github.com/repos/%s/commits?sha=%s'
GITHUB_LATEST_RELEASE = 'https://api.github.com/repos/%s/releases/latest' GITHUB_LATEST_RELEASE = 'https://api.github.com/repos/%s/releases/latest'
GITHUB_MAX_TAG = 'https://api.github.com/repos/%s/tags' GITHUB_MAX_TAG = 'https://api.github.com/repos/%s/tags'
logger = logging.getLogger(__name__)
async def get_version(name, conf): async def get_version(name, conf):
repo = conf.get('github') repo = conf.get('github')
br = conf.get('branch', 'master') br = conf.get('branch', 'master')
@ -36,10 +39,16 @@ async def get_version(name, conf):
async with session.get(url, headers=headers, **kwargs) as res: async with session.get(url, headers=headers, **kwargs) as res:
data = await res.json() data = await res.json()
if use_latest_release: if use_latest_release:
if 'tag_name' not in data:
logger.error('%s: No tag found in upstream repository.', name)
return
version = data['tag_name'] version = data['tag_name']
elif use_max_tag: elif use_max_tag:
data = [tag["name"] for tag in data if tag["name"] not in ignored_tags] data = [tag["name"] for tag in data if tag["name"] not in ignored_tags]
data.sort(key=sort_version_key) data.sort(key=sort_version_key)
if not len(data):
logger.error('%s: No tag found in upstream repository.', name)
return
version = data[-1] version = data[-1]
else: else:
# YYYYMMDD.HHMMSS # YYYYMMDD.HHMMSS