Source code for flash_services.buddy
"""Defines the Buddy CI service integration."""
import logging
from .auth import BearerAuthHeaderMixin
from .core import ContinuousIntegrationService
from .utils import elapsed_time, estimate_time, health_summary, Outcome
logger = logging.getLogger(__name__)
[docs]class Buddy(BearerAuthHeaderMixin, ContinuousIntegrationService):
"""Show the current build status on Buddy.
Arguments:
api_token (:py:class:`str`): A valid token for the Buddy API.
domain (:py:class:`str`): The domain of the Buddy project.
pipeline_id (:py:class:`int`): The ID of the Buddy pipeline.
project_name (:py:class:`str`): The name of the Buddy project.
"""
ENDPOINT = '/workspaces/{domain}/projects/{project_name}/pipelines/{pipeline_id}/executions'
OUTCOMES = dict(
FAILED=Outcome.FAILED,
INPROGRESS=Outcome.WORKING,
SUCCESSFUL=Outcome.PASSED,
TERMINATED=Outcome.CANCELLED,
)
ROOT = 'https://api.buddy.works'
def __init__(self, *, domain, pipeline_id, project_name, **kwargs):
super().__init__(**kwargs)
self.domain = domain
self.pipeline_id = pipeline_id
self.project_name = project_name
[docs] @staticmethod
def get_message(build, commit):
"""Extract the message from the commit or comment.
Arguments:
build (:py:class:`dict`): The JSON data from the response.
commit (:py:class:`dict`): The JSON data from the response.
Returns:
:py:class:`str`: The commit or comment message.
"""
return build.get("comment") or commit.get('message')
[docs] @staticmethod
def get_name(commit):
"""Extract the name from the author or committer.
Arguments:
commit (:py:class:`dict`): The JSON data from the response.
Returns:
:py:class:`str`: The author (or committer) name.
"""
author = commit.get('author', {})
if 'name' in author:
return author['name']
return commit.get('committer', {}).get('name')