コード例 #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 create_repository(auth_user: AuthUser, # pylint: disable=too-many-arguments
                      repository_project_id,
                      repository_name,
                      repository_organization_name, 
                      repository_type,
                      repository_url,
                      repository_external_id=None):
    """
    Creates a repository and returns the newly created repository in dict format.

    :param repository_project_id: The ID of the repository project.
    :type repository_project_id: string
    :param repository_name: The new repository name.
    :type repository_name: string
    :param repository_type: The new repository type ('github', 'gerrit', etc).
    :type repository_organization_name: string
    :param repository_organization_name: The repository organization name
    :type repository_type: string
    :param repository_url: The new repository URL.
    :type repository_url: string
    :param repository_external_id: The ID of the repository from the repository provider.
    :type repository_external_id: string
    :return: dict representation of the new repository object.
    :rtype: dict
    """

    # Check that organization exists 
    github_organization = GitHubOrg()
    try:
        github_organization.load(str(repository_organization_name))
    except DoesNotExist as err:
        return {'errors': {'organization_name': str(err)}}

    # Check that project is valid. 
    project = Project()
    try:
        project.load(str(repository_project_id))
    except DoesNotExist as err:
        return {'errors': {'repository_project_id': str(err)}}

    # Get SFDC project identifier
    sfdc_id = project.get_project_external_id()

    # Validate user is authorized for this project
    can_access = cla.controllers.project.check_user_authorization(auth_user, sfdc_id)
    if not can_access['valid']:
      return can_access['errors']

    # Validate if exist already repository linked to a contract group
    if repository_external_id is not None:
        # Seach for the repository
        linked_repository = Repository().get_repository_by_external_id(repository_external_id, 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 = Repository()
    repository.set_repository_id(str(uuid.uuid4()))
    repository.set_repository_project_id(str(repository_project_id))
    repository.set_repository_sfdc_id(str(sfdc_id))
    repository.set_repository_name(repository_name)
    repository.set_repository_organization_name(repository_organization_name)
    repository.set_repository_type(repository_type)
    repository.set_repository_url(repository_url)
    if repository_external_id is not None:
        repository.set_repository_external_id(repository_external_id)
    repository.save()
    return repository.to_dict()