Source code for flash_services.coveralls
"""Defines the GitHub service integration."""
import logging
from .auth import Unauthenticated
from .core import Service, ThresholdMixin
from .utils import occurred, remove_tags
logger = logging.getLogger(__name__)
[docs]class Coveralls(Unauthenticated, ThresholdMixin, Service):
"""Show the current status of a Coveralls repository.
Arguments:
vcs_name (:py:class:`str`): The name of the linked VCS (e.g.
``'github'``).
account (:py:class:`str`): The name of the account.
repo (:py:class:`str`): The name of the repository.
ok_threshold (:py:class:`int`, optional): The minimum coverage
for OK tile status (defaults to ``80``).
neutral_threshold (:py:class:`int`, optional): The minimum
coverage for neutral tile status (defaults to ``50``).
Attributes:
repo_name (:py:class:`str`): The repository name, in the format
``vcs_name/account/repo``.
"""
ENDPOINT = '/{repo_name}.json'
FRIENDLY_NAME = 'Coveralls'
NEUTRAL_THRESHOLD = 50
OK_THRESHOLD = 80
ROOT = 'https://coveralls.io'
TEMPLATE = 'coveralls-section'
def __init__(self, *, vcs_name, account, repo, **kwargs):
super().__init__(**kwargs)
self.repo_name = '/'.join([vcs_name, account, repo])
@property
def url_params(self):
params = super().url_params
params['page'] = 1
return params
[docs] def health(self, last_build):
"""Determine the health of the last build.
Arguments:
last_build (:py:class:`dict`): The last build.
Returns:
:py:class:`str`: The health rating.
"""
if last_build is None:
return 'error'
coverage = last_build['raw_coverage']
if coverage is None or coverage < self.neutral_threshold:
return 'error'
elif coverage < self.ok_threshold:
return 'neutral'
return 'ok'