async def clone_projectversion(request): """ Clone a given projectversion --- description: Toggles the ci enabled flag on a projectversion. tags: - ProjectVersions consumes: - application/json parameters: - name: projectversion_id in: path required: true type: integer - name: body in: body required: true schema: type: object properties: name: type: string example: "1.0.0" produces: - text/json responses: "200": description: successful "400": description: Invalid data received. "500": description: internal server error """ params = await request.json() name = params.get("name") projectversion_id = parse_int(request.match_info["projectversion_id"]) if not projectversion_id: return web.Response(status=400, text="No valid project id received") if not name: return web.Response( status=400, text="No valid name for the projectversion recieived") if not is_name_valid(name): return web.Response(status=400, text="Invalid project name!") projectversion = (request.cirrina.db_session.query(ProjectVersion).filter( ProjectVersion.id == projectversion_id).first()) if (request.cirrina.db_session.query(ProjectVersion).join(Project).filter( ProjectVersion.name == name).filter( Project.id == projectversion.project_id).first()): return web.Response(status=400, text="Projectversion already exists.") # remove association from database new_projectversion = ProjectVersion( name=name, project=projectversion.project, dependencies=projectversion.dependencies, buildvariants=projectversion.buildvariants, sourcerepositories=projectversion.sourcerepositories, ci_builds_enabled=projectversion.ci_builds_enabled, ) for repo in new_projectversion.sourcerepositories: sourepprover_id = (( request.cirrina.db_session.query(SouRepProVer) # pylint: disable=no-member .filter(SouRepProVer.c.sourcerepository_id == repo.id).filter( SouRepProVer.c.projectversion_id == projectversion.id) ).first().id) new_sourepprover_id = (( request.cirrina.db_session.query(SouRepProVer) # pylint: disable=no-member .filter(SouRepProVer.c.sourcerepository_id == repo.id).filter( SouRepProVer.c.projectversion_id == new_projectversion.id) ).first().id) buildconfs = ( request.cirrina.db_session.query(BuildConfiguration).filter( BuildConfiguration.sourcerepositoryprojectversion_id == sourepprover_id).all()) for buildconf in buildconfs: new_buildconf = BuildConfiguration( buildvariant=buildconf.buildvariant, sourcerepositoryprojectversion_id=new_sourepprover_id, ) request.cirrina.db_session.add(new_buildconf) request.cirrina.db_session.add(new_projectversion) request.cirrina.db_session.commit() basemirror = new_projectversion.buildvariants[0].base_mirror architectures = [ b.architecture.name for b in new_projectversion.buildvariants ] await request.cirrina.aptly_queue.put({ "init_repository": [ new_projectversion.id, basemirror.project.name, basemirror.name, new_projectversion.project.name, new_projectversion.name, architectures, ] }) return web.json_response({ "id": new_projectversion.id, "name": new_projectversion.name })
async def create_projectversion_overlay(request): """ Creates an overlay of a project version --- description: Creates an overlay of a project version tags: - ProjectVersions consumes: - application/json parameters: - name: projectversion_id in: path required: true type: integer - name: body in: body required: true schema: type: object properties: name: type: string produces: - text/json responses: "200": description: successful "400": description: Invalid data received. "500": description: internal server error """ params = await request.json() name = params.get("name") projectversion_id = parse_int(request.match_info["projectversion_id"]) if not projectversion_id: return web.Response(status=400, text="No valid project id received") if not name: return web.Response( status=400, text="No valid name for the projectversion recieived") if not is_name_valid(name): return web.Response(status=400, text="Invalid project name!") projectversion = (request.cirrina.db_session.query(ProjectVersion).filter( ProjectVersion.id == projectversion_id).first()) if (request.cirrina.db_session.query(ProjectVersion).join(Project).filter( ProjectVersion.name == name).filter( Project.id == projectversion.project_id).first()): return web.Response(status=400, text="Projectversion already exists.") # remove association from database overlay_projectversion = ProjectVersion( name=name, project=projectversion.project, # add the projectversion where the overlay is created from as a dependency dependencies=[projectversion], buildvariants=projectversion.buildvariants, ) request.cirrina.db_session.add(overlay_projectversion) request.cirrina.db_session.commit() basemirror = overlay_projectversion.buildvariants[0].base_mirror architectures = [ b.architecture.name for b in overlay_projectversion.buildvariants ] await request.cirrina.aptly_queue.put({ "init_repository": [ overlay_projectversion.id, basemirror.project.name, basemirror.name, overlay_projectversion.project.name, overlay_projectversion.name, architectures, ] }) return web.json_response({ "id": overlay_projectversion.id, "name": overlay_projectversion.name })
async def create_projectversions(request): """ Creates a new projectversion. --- description: Creates a new projectversion. tags: - ProjectVersions consumes: - application/json parameters: - name: project_id in: path required: true type: integer - name: body in: body required: true schema: type: object properties: name: type: string example: "1.0.0" basemirror: type: string example: "stretch/9.6" architectures: type: array example: ["amd64", "armhf"] FIXME: only accept existing archs on mirror! produces: - text/json responses: "200": description: successful "400": description: invalid data received "500": description: internal server error """ params = await request.json() name = params.get("name") architectures = params.get("architectures", []) basemirror = params.get("basemirror") project_id = parse_int(request.match_info["project_id"]) if not project_id: return web.Response(status=400, text="No valid project id received") if not name: return web.Response( status=400, text="No valid name for the projectversion recieived") if not basemirror or not ("/" in basemirror): return web.Response( status=400, text="No valid basemirror received (format: 'name/version')") if not architectures: return web.Response(status=400, text='No valid architecture received') if not is_name_valid(name): return web.Response(status=400, text="Invalid project name!") basemirror_name, basemirror_version = basemirror.split("/") project = request.cirrina.db_session.query(Project).filter( Project.id == project_id).first() if not project: return web.Response( status=400, text="Project with id '{}' could not be found".format(project_id)) projectversion = ( request.cirrina.db_session.query(ProjectVersion).join(Project).filter( ProjectVersion.name == name).filter( Project.id == project.id).first()) if projectversion: return web.Response(status=400, text="Projectversion already exists. {}".format( "And is marked as deleted!" if projectversion. is_deleted else "")) buildvariants = get_buildvariants(request.cirrina.db_session, basemirror_name, basemirror_version, architectures) projectversion = ProjectVersion(name=name, project=project) projectversion.buildvariants = buildvariants request.cirrina.db_session.add(projectversion) request.cirrina.db_session.commit() logger.info( "ProjectVersion '%s/%s' with id '%s' added", projectversion.project.name, projectversion.name, projectversion.id, ) project_name = projectversion.project.name project_version = projectversion.name await request.cirrina.aptly_queue.put({ "init_repository": [ projectversion.id, basemirror_name, basemirror_version, project_name, project_version, architectures ] }) return web.json_response({ "id": projectversion.id, "name": projectversion.name })