def upgrade(active_plugins=None, options=None): bind = op.get_bind() validator = NameType() projects = list( bind.execute( sa.select(columns=['*'], from_obj=sa.Table('projects', MetaData())))) projects_table = table( 'projects', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(), nullable=False), sa.Column('description', sa.UnicodeText(), nullable=True), ) last_idx = 0 for project in projects: project_name = project["name"] project_id = project["id"] need_rename = False try: validator.validate(project_name) except Exception: need_rename = True if need_rename: # This project needs renaming temp_name = "Project-%d" % last_idx last_idx += 1 updated_description = "%s This project was renamed to fit new " \ "naming validation. Original name was: %s" \ % (project["description"], project_name) bind.execute(projects_table.update().where( projects_table.c.id == project_id).values( name=temp_name, description=updated_description))
def upgrade(active_plugins=None, options=None): bind = op.get_bind() validator = NameType() projects = list(bind.execute( sa.select(columns=['*'], from_obj=sa.Table('projects', MetaData())))) projects_table = table( 'projects', sa.Column('id', sa.Integer(), nullable=False), sa.Column('name', sa.String(), nullable=False), sa.Column('description', sa.UnicodeText(), nullable=True), ) last_idx = 0 for project in projects: project_name = project["name"] project_id = project["id"] need_rename = False try: validator.validate(project_name) except Exception: need_rename = True if need_rename: # This project needs renaming temp_name = "Project-%d" % last_idx last_idx += 1 updated_description = "%s This project was renamed to fit new " \ "naming validation. Original name was: %s" \ % (project["description"], project_name) bind.execute(projects_table.update() .where(projects_table.c.id == project_id) .values(name=temp_name, description=updated_description))
class Team(base.APIBase): """The Team is a group of Users with a fixed set of permissions.""" name = NameType() """The Team unique name. This name will be displayed in the URL. At least 3 alphanumeric symbols. Minus and dot symbols are allowed as separators.""" description = wtypes.text """Details about the team.""" @classmethod def sample(cls): return cls(name="StoryBoard-core", description="Core reviewers of StoryBoard team.")
def _get_project(project, session): validator = NameType() name = six.text_type(project['project']) if 'description' in project: description = six.text_type(project['description']) else: description = '' try: validator.validate(name) except Exception: # Skipping invalid project names LOG.warn(_LW("Project %s was not loaded. Validation failed.") % [name, ]) return None db_project = session.query(Project) \ .filter_by(name=name).first() if not db_project: db_project = Project() db_project.name = name db_project.description = description db_project.groups = [] session.add(db_project) session.flush() master_branch = session.query(Branch).\ filter_by(name='master', project_id=db_project.id).first() if not master_branch: master_branch = Branch() master_branch.update(MasterBranchHelper(db_project.id).as_dict()) session.add(master_branch) return db_project
def _get_project(project, session): validator = NameType() name = six.text_type(project['project']) if 'description' in project: description = six.text_type(project['description']) else: description = '' try: validator.validate(name) except Exception: # Skipping invalid project names LOG.warning(_LW("Project %s was not loaded. Validation failed.") % [name, ]) return None db_project = session.query(Project) \ .filter_by(name=name).first() if not db_project: db_project = Project() db_project.name = name db_project.description = description db_project.groups = [] session.add(db_project) session.flush() master_branch = session.query(Branch).\ filter_by(name='master', project_id=db_project.id).first() if not master_branch: master_branch = Branch() master_branch.update(MasterBranchHelper(db_project.id).as_dict()) session.add(master_branch) return db_project
class ProjectGroup(base.APIBase): """Represents a group of projects.""" name = NameType() """The Project Group unique name. This name will be displayed in the URL. At least 3 alphanumeric symbols. Minus and dot symbols are allowed as separators. """ title = wtypes.text """The full name of the project group, which can contain spaces, special characters, etc. """ @classmethod def sample(cls): return cls(id=1, created_at=datetime.fromtimestamp(1321009871), name="Infra", title="Awesome projects")
class Project(base.APIBase): """The Storyboard Registry describes the open source world as ProjectGroups and Projects. Each ProjectGroup may be responsible for several Projects. For example, the OpenStack Infrastructure ProjectGroup has Zuul, Nodepool, Storyboard as Projects, among others. """ name = NameType() """The Project unique name. This name will be displayed in the URL. At least 3 alphanumeric symbols. Minus and dot symbols are allowed as separators. """ description = wtypes.text """Details about the project's work, highlights, goals, and how to contribute. Use plain text, paragraphs are preserved and URLs are linked in pages. """ is_active = bool """Is this an active project, or has it been deleted?""" repo_url = wtypes.text """This is a repo link for this project""" autocreate_branches = bool """This flag means that storyboard will try to create task branches automatically from the branches declared in the code repository. """ @classmethod def sample(cls): return cls( id=3, created_at=datetime.fromtimestamp(1321009871), name="StoryBoard", description="This is an awesome project.", is_active=True, repo_url="git://git.openstack.org/openstack-infra/storyboard.git")