Exemplo n.º 1
0
def build_context_from_config(config: Config) -> BuildContext:
    """Creates a new BuildContext instance from the provided *config*.

    This function is mainly for the purpose of a manual build trigger. For manually triggering a build there
    obviously is no request data from which to get the repo url / commit hash from, which is why it will use the
    information which were defined in the config file.

    :return: The build context which was based on the information in the config file in the ufotest folder
    """
    repository_url = config.get_ci_repository_url()
    repository_branch = config.get_ci_branch()
    repository_commit = 'FETCH_HEAD'
    test_suite = config.get_ci_suite()

    return BuildContext(repository_url, repository_branch, repository_commit,
                        test_suite)
Exemplo n.º 2
0
def build_context_from_request(data: dict) -> BuildContext:
    """Creates a new BuildContext instance from given json payload *data* from the github web hook request.

    This function extracts the information about which commit to clone from which repo from the given payload of the
    request.

    :return: the build context instance.
    """
    repository_url = data['repository']['clone_url']
    repository_branch = data['ref'].replace('refs/heads/', '')
    repository_commit = data['commits'][-1]

    config = Config()
    test_suite = config.get_ci_suite()

    return BuildContext(repository_url, repository_branch, repository_commit,
                        test_suite)