Merge pull request #65 from felixonmars/handle-exception

Handle exception for no-tag situation
This commit is contained in:
依云 2018-01-09 14:23:16 +08:00 committed by GitHub
commit 48c394b693
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,7 @@
# Copyright (c) 2013-2017 lilydjwg <lilydjwg@gmail.com>, et al.
import os
import logging
from . import session
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_MAX_TAG = 'https://api.github.com/repos/%s/tags'
logger = logging.getLogger(__name__)
async def get_version(name, conf):
repo = conf.get('github')
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:
data = await res.json()
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']
elif use_max_tag:
data = [tag["name"] for tag in data if tag["name"] not in ignored_tags]
data.sort(key=sort_version_key)
if not len(data):
logger.error('%s: No tag found in upstream repository.', name)
return
version = data[-1]
else:
# YYYYMMDD.HHMMSS