Ejemplo n.º 1
0
def _process_recipe(session: database.Session, recipe_data: dict,
                    ecosystem: database.Ecosystem) -> database.Recipe:
    ecosystem_id = ecosystem.id
    name = recipe_data["name"]
    version = recipe_data["version"]
    user = recipe_data.get("user", None)
    channel = recipe_data.get("channel", None)

    recipe = session.query(database.Recipe).filter_by(
        ecosystem_id=ecosystem_id,
        name=name,
        version=version,
        user=user,
        channel=channel).first()

    if not recipe:
        recipe = database.Recipe()
        recipe.ecosystem = ecosystem
        recipe.name = name
        recipe.version = version
        recipe.user = user
        recipe.channel = channel

    logger.debug("Process recipe '%s' ('%s/%s@%s/%s')", recipe.id, recipe.name,
                 recipe.version, recipe.user, recipe.channel)
    return recipe
Ejemplo n.º 2
0
def _process_recipe_revision(session: database.Session, recipe_data: dict, ecosystem: database.Ecosystem)\
        -> database.RecipeRevision:
    recipe = _process_recipe(session, recipe_data, ecosystem)
    if not recipe:
        return None

    m = re.match("[\\w\\+\\.-]+/[\\w\\+\\.-]+(?:@\\w+/\\w+)?(#(\\w+))?",
                 recipe_data["id"])
    if m:
        revision = m.group(2) if m.group(2) else ""
    else:
        logger.error("Invalid recipe ID '%s'", recipe_data["id"])
        return None

    recipe_revision = session.query(database.RecipeRevision).filter_by(
        recipe_id=recipe.id, revision=revision).first()

    if not recipe_revision:
        recipe_revision = database.RecipeRevision()
        recipe_revision.recipe = recipe
        recipe_revision.revision = revision

    logger.debug("Process recipe revision '%s' (revision: '%s')",
                 recipe_revision.id, recipe_revision.revision)
    return recipe_revision
Ejemplo n.º 3
0
def _trigger_builds_for_package(session: database.Session,
                                package: database.Package):

    # Get all failed builds which are waiting a package of the same recipe revision. In these cases the package ID
    # should match exactly.
    same_recipe_revision = session.query(database.Build).filter(database.Build.status == database.BuildStatus.error).\
        filter(database.missing_package.columns['build_id'] == database.Build.id).\
        filter(database.missing_package.columns['package_id'] == package.id).\
        filter(database.Build.commit_id == database.Commit.id).\
        filter(database.Commit.status == database.CommitStatus.building).\
        all()

    # Get all failed builds which are waiting for a package of the same recipe but a different recipe revision. In these
    # cases a build is triggered regardless of the exact package ID (because the package ID might be computed
    # differently for a different recipe revision).
    different_recipe_revision = session.query(database.Build).\
        filter(database.Build.status == database.BuildStatus.error).\
        filter(database.missing_package.columns['build_id'] == database.Build.id).\
        filter(database.missing_package.columns['package_id'] == database.Package.id).\
        filter(database.Build.commit_id == database.Commit.id).\
        filter(database.Commit.status == database.CommitStatus.building).\
        filter(database.Package.recipe_revision_id == database.RecipeRevision.id).\
        filter(database.RecipeRevision.revision != package.recipe_revision.revision).\
        filter(database.RecipeRevision.recipe_id == package.recipe_revision.recipe.id).\
        all()

    # re-trigger these builds
    builds = same_recipe_revision + different_recipe_revision
    for build in builds:
        logger.info("Set status of build '%d' to 'new'", build.id)
        build.status = database.BuildStatus.new

    logger.debug("Trigger builds for package '%s' (ID: '%s')", package.id,
                 package.package_id)
    return builds
Ejemplo n.º 4
0
def _process_package(session: database.Session, package_data: dict, recipe_revision: database.RecipeRevision)\
        -> database.Package:
    package_id = package_data["id"]
    package = session.query(database.Package).filter_by(
        package_id=package_id, recipe_revision_id=recipe_revision.id).first()

    if not package:
        package = database.Package()
        package.package_id = package_id
        package.recipe_revision = recipe_revision
        session.add(package)

    logger.debug("Process package '%s' (ID: '%s')", package.id,
                 package.package_id)
    return package
Ejemplo n.º 5
0
def _trigger_builds_for_recipe(session: database.Session,
                               recipe: database.Recipe):

    # get all failed builds which are waiting for this recipe
    builds = session.query(database.Build).filter(database.Build.status==database.BuildStatus.error).\
        filter(database.missing_recipe.columns['build_id']==database.Build.id).\
        filter(database.missing_recipe.columns['recipe_id']==recipe.id).\
        filter(database.Build.commit_id==database.Commit.id).\
        filter(database.Commit.status==database.CommitStatus.building).\
        all()

    # re-trigger these builds
    for build in builds:
        logger.info("Set status of build '%d' to 'new'", build.id)
        build.status = database.BuildStatus.new

    logger.debug("Trigger builds for recipe '%s' ('%s/%s@%s/%s')", recipe.id,
                 recipe.name, recipe.version, recipe.user, recipe.channel)
    return builds