def get_gerrit_by_project_id(project_id): gerrit = Gerrit() try: gerrits = gerrit.get_gerrit_by_project_id(project_id) except DoesNotExist: cla.log.warning( 'gerrit project id: {} does not exist'.format(project_id)) return [] except Exception as e: cla.log.warning( 'gerrit project id: {} does not exist, error: {}'.format( project_id, e)) return { 'errors': { f'a gerrit instance does not exist with the given project ID: {project_id}': str(e) } } if gerrits is None: cla.log.warning( 'gerrit project id: {} does not exist'.format(project_id)) return [] return [gerrit.to_dict() for gerrit in gerrits]
def get_gerrit(gerrit_id): gerrit = Gerrit() try: gerrit.load(str(gerrit_id)) except DoesNotExist as err: return { 'errors': { 'a gerrit instance does not exist with the given Gerrit ID. ': str(err) } } return gerrit.to_dict()
def get_gerrit_by_project_id(project_id): gerrit = Gerrit() try: gerrits = gerrit.get_gerrit_by_project_id(project_id) except DoesNotExist: return [] except Exception as e: return { 'errors': { 'a gerrit instance does not exist with the given project ID. ': str(e) } } if gerrits is None: return [] return [gerrit.to_dict() for gerrit in gerrits]
def delete_gerrit(gerrit_id): """ Deletes a gerrit instance :param gerrit_id: The ID of the gerrit instance. """ gerrit = Gerrit() try: gerrit.load(str(gerrit_id)) except DoesNotExist as err: return {'errors': {'gerrit_id': str(err)}} gerrit.delete() return {'success': True}
def delete_gerrit(gerrit_id): """ Deletes a gerrit instance :param gerrit_id: The ID of the gerrit instance. """ gerrit = Gerrit() try: gerrit.load(str(gerrit_id)) except DoesNotExist as err: cla.log.warning( 'a gerrit instance does not exist with the ' 'given Gerrit ID: {} - unable to delete'.format(gerrit_id)) return {'errors': {'gerrit_id': str(err)}} gerrit.delete() cla.log.debug( 'deleted gerrit instance with gerrit_id: {}'.format(gerrit_id)) return {'success': True}
def create_gerrit(project_id, gerrit_name, gerrit_url, group_id_icla, group_id_ccla): """ Creates a gerrit instance and returns the newly created gerrit object dict format. :param gerrit_project_id: The project ID of the gerrit instance :type gerrit_project_id: string :param gerrit_name: The new gerrit instance name :type gerrit_name: string :param gerrit_url: The new Gerrit URL. :type gerrit_url: string :param group_id_icla: The id of the LDAP group for ICLA. :type group_id_icla: string :param group_id_ccla: The id of the LDAP group for CCLA. :type group_id_ccla: string """ gerrit = Gerrit() # Check if at least ICLA or CCLA is specified if group_id_icla is None and group_id_ccla is None: return { 'error': 'Should specify at least a LDAP group for ICLA or CCLA.' } # Check if ICLA exists if group_id_icla is not None: ldap_group_icla = lf_group.get_group(group_id_icla) if ldap_group_icla.get('error') is not None: return { 'error_icla': 'The specified LDAP group for ICLA does not exist. ' } gerrit.set_group_name_icla(ldap_group_icla.get('title')) gerrit.set_group_id_icla(str(group_id_icla)) # Check if CCLA exists if group_id_ccla is not None: ldap_group_ccla = lf_group.get_group(group_id_ccla) if ldap_group_ccla.get('error') is not None: return { 'error_ccla': 'The specified LDAP group for CCLA does not exist. ' } gerrit.set_group_name_ccla(ldap_group_ccla.get('title')) gerrit.set_group_id_ccla(str(group_id_ccla)) # Save Gerrit Instance gerrit.set_gerrit_id(str(uuid.uuid4())) gerrit.set_project_id(str(project_id)) gerrit.set_gerrit_url(gerrit_url) gerrit.set_gerrit_name(gerrit_name) gerrit.save() return gerrit.to_dict()