Ejemplo n.º 1
0
def trigger_ci_build(self, session, project_name, cause, branch, ci_type):
    ''' Triggers a new run of the CI system on the specified pull-request.

    '''
    pagure.lib.plugins.get_plugin('Pagure CI')

    user, namespace, project_name = split_project_fullname(project_name)

    _log.info('Pagure-CI: Looking for project: %s', project_name)
    project = pagure.lib.get_authorized_project(session=session,
                                                project_name=project_name,
                                                user=user,
                                                namespace=namespace)

    if project is None:
        _log.warning('Pagure-CI: No project could be found for the name %s',
                     project_name)
        session.close()
        return

    _log.info('Pagure-CI: project retrieved: %s', project.fullname)

    _log.info("Pagure-CI: Trigger from %s cause (PR# or commit) %s branch: %s",
              project.fullname, cause, branch)

    if ci_type == 'jenkins':

        if project.is_fork:
            url = project.parent.ci_hook.ci_url
            job = project.parent.ci_hook.ci_job
            token = project.parent.ci_hook.pagure_ci_token
        else:
            url = project.ci_hook.ci_url
            job = project.ci_hook.ci_job
            token = project.ci_hook.pagure_ci_token

        trigger_jenkins_build(project_path=project.path,
                              url=url,
                              job=job,
                              token=token,
                              branch=branch,
                              cause=cause)

    else:
        _log.warning('Pagure-CI:Un-supported CI type')

    _log.info('Pagure-CI: Ready for another')
Ejemplo n.º 2
0
def trigger_ci_build(self,
                     session,
                     cause,
                     branch,
                     ci_type,
                     project_name=None,
                     pr_uid=None):
    """ Triggers a new run of the CI system on the specified pull-request.

    """
    pagure.lib.plugins.get_plugin("Pagure CI")

    if not pr_uid and not project_name:
        _log.debug("No PR UID nor project name specified, can't trigger CI")
        session.close()
        return

    if pr_uid:
        pr = pagure.lib.query.get_request_by_uid(session, pr_uid)
        if pr.remote:
            project_name = pr.project_to.fullname
        else:
            project_name = pr.project_from.fullname

    user, namespace, project_name = split_project_fullname(project_name)

    _log.info("Pagure-CI: Looking for project: %s", project_name)
    project = pagure.lib.query.get_authorized_project(
        session=session,
        project_name=project_name,
        user=user,
        namespace=namespace,
    )

    if project is None:
        _log.warning(
            "Pagure-CI: No project could be found for the name %s",
            project_name,
        )
        session.close()
        return

    if project.is_fork:
        if (project.parent.ci_hook is None
                or project.parent.ci_hook.ci_url is None):
            raise pagure.exceptions.PagureException(
                "Project %s not configured or incorectly configured for ci",
                project.parent.fullname,
            )
    elif project.ci_hook is None or project.ci_hook.ci_url is None:
        raise pagure.exceptions.PagureException(
            "Project %s not configured or incorectly configured for ci",
            project.fullname,
        )

    _log.info("Pagure-CI: project retrieved: %s", project.fullname)

    _log.info(
        "Pagure-CI: Trigger from %s cause (PR# or commit) %s branch: %s",
        project.fullname,
        cause,
        branch,
    )

    if ci_type == "jenkins":

        if project.is_fork:
            url = project.parent.ci_hook.ci_url
            job = project.parent.ci_hook.ci_job
            token = project.parent.ci_hook.pagure_ci_token
        else:
            url = project.ci_hook.ci_url
            job = project.ci_hook.ci_job
            token = project.ci_hook.pagure_ci_token

        trigger_jenkins_build(
            project_path=project.path,
            url=url,
            job=job,
            token=token,
            branch=branch,
            cause=cause,
        )

    else:
        _log.warning("Pagure-CI:Un-supported CI type")

    _log.info("Pagure-CI: Ready for another")
Ejemplo n.º 3
0
def trigger_ci_build(
    self,
    session,
    cause,
    branch,
    branch_to,
    ci_type,
    project_name=None,
    pr_uid=None,
):

    """ Triggers a new run of the CI system on the specified pull-request.

    """
    pagure.lib.plugins.get_plugin("Pagure CI")

    if not pr_uid and not project_name:
        _log.debug("No PR UID nor project name specified, can't trigger CI")
        session.close()
        return

    if pr_uid:
        pr = pagure.lib.query.get_request_by_uid(session, pr_uid)
        if pr.remote:
            project_name = pr.project_to.fullname
        else:
            project_name = pr.project_from.fullname

    user, namespace, project_name = split_project_fullname(project_name)

    _log.info("Pagure-CI: Looking for project: %s", project_name)
    project = pagure.lib.query.get_authorized_project(
        session=session,
        project_name=project_name,
        user=user,
        namespace=namespace,
    )

    if project is None:
        _log.warning(
            "Pagure-CI: No project could be found for the name %s",
            project_name,
        )
        session.close()
        return

    if project.is_fork:
        if (
            project.parent.ci_hook is None
            or project.parent.ci_hook.ci_url is None
        ):
            raise pagure.exceptions.PagureException(
                "Project %s not configured or incorectly configured for ci",
                project.parent.fullname,
            )
    elif project.ci_hook is None or project.ci_hook.ci_url is None:
        raise pagure.exceptions.PagureException(
            "Project %s not configured or incorectly configured for ci",
            project.fullname,
        )

    _log.info("Pagure-CI: project retrieved: %s", project.fullname)

    _log.info(
        "Pagure-CI: Trigger from %s cause (PR# or commit) %s branch: %s",
        project.fullname,
        cause,
        branch,
    )

    if ci_type == "jenkins":

        jenk_project = project
        if project.is_fork:
            jenk_project = project.parent

        trigger_jenkins_build(
            project_path=project.path,
            url=jenk_project.ci_hook.ci_url,
            job=jenk_project.ci_hook.ci_job,
            token=jenk_project.ci_hook.pagure_ci_token,
            branch=branch,
            branch_to=branch_to,
            cause=cause,
            ci_username=jenk_project.ci_hook.ci_username,
            ci_password=jenk_project.ci_hook.ci_password,
        )

    else:
        _log.warning("Pagure-CI:Un-supported CI type")

    _log.info("Pagure-CI: Ready for another")