コード例 #1
0
ファイル: repository.py プロジェクト: zaclittleberry/easycla
def update_repository(repository_id, # pylint: disable=too-many-arguments
                      repository_project_id=None,
                      repository_type=None,
                      repository_name=None,
                      repository_url=None,
                      repository_external_id=None):
    """
    Updates a repository and returns the newly updated repository in dict format.
    Values of None means the field will not be updated.

    :param repository_id: ID of the repository to update.
    :type repository_id: ID
    :param repository_project_id: ID of the repository project.
    :type repository_project_id: string
    :param repository_name: New name for the repository.
    :type repository_name: string | None
    :param repository_type: New type for repository ('github', 'gerrit', etc).
    :type repository_type: string | None
    :param repository_url: New URL for the repository.
    :type repository_url: string | None
    :param repository_external_id: ID of the repository from the service provider.
    :type repository_external_id: string
    :return: dict representation of the repository object.
    :rtype: dict
    """
    repository = Repository()
    try:
        repository.load(str(repository_id))
    except DoesNotExist as err:
        return {'errors': {'repository_id': str(err)}}
    # TODO: Ensure project_id exists.
    if repository_project_id is not None:
        repository.set_repository_project_id(str(repository_project_id))
    if repository_type is not None:
        supported_repo_types = get_supported_repository_providers().keys()
        if repository_type in supported_repo_types:
            repository.set_repository_type(repository_type)
        else:
            return {'errors': {'repository_type':
                               'Invalid value passed. The accepted values are: (%s)' \
                               %'|'.join(supported_repo_types)}}
    if repository_external_id is not None:
        # Find a repository is already linked with this external_id
        linked_repository = Repository().get_repository_by_external_id(repository_external_id, repository.get_repository_type())
        # If found return an error
        if linked_repository is not None:
            return {'errors': {'repository_external_id': 'This repository is alredy configured for a contract group.'}}

        repository.set_repository_external_id(repository_external_id)
    if repository_name is not None:
        repository.set_repository_name(repository_name)
    if repository_url is not None:
        try:
            val = cla.hug_types.url(repository_url)
            repository.set_repository_url(val)
        except ValueError as err:
            return {'errors': {'repository_url': 'Invalid URL specified'}}
    repository.save()
    return repository.to_dict()
コード例 #2
0
ファイル: repository.py プロジェクト: zaclittleberry/easycla
def delete_repository(repository_id):
    """
    Deletes a repository based on ID.

    :param repository_id: The ID of the repository.
    :type repository_id: ID
    """
    repository = Repository()
    try:
        repository.load(str(repository_id))
    except DoesNotExist as err:
        return {'errors': {'repository_id': str(err)}}
    repository.delete()
    return {'success': True}