Пример #1
0
def delete_project(id, organization=None, detect=None):  # pylint: disable=redefined-builtin
    """Delete team project.
    :param id: The id (UUID) of the project to delete.
    :type id: str
    :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/
    :type organization: str
    :param detect: When 'On' unsupplied arg values will be detected from the current working
                   directory's repo.
    :type detect: str
    """
    try:
        organization = resolve_instance(detect=detect,
                                        organization=organization)
        core_client = get_core_client(organization)
        operation_reference = core_client.queue_delete_project(project_id=id)
        operation = wait_for_long_running_operation(organization,
                                                    operation_reference.id, 1)
        status = operation.status.lower()
        if status == 'failed':
            raise CLIError('Project deletion failed.')
        elif status == 'cancelled':
            raise CLIError('Project deletion was cancelled.')
        print('Deleted project {}'.format(id))
        return operation
    except VstsServiceError as ex:
        raise CLIError(ex)
Пример #2
0
def delete_project(id, organization=None, detect=None):  # pylint: disable=redefined-builtin
    """Delete team project.
    :param id: The id of the project to delete.
    :type id: str
    """
    organization = resolve_instance(detect=detect, organization=organization)
    core_client = get_core_client(organization)
    operation_reference = core_client.queue_delete_project(project_id=id)
    operation = wait_for_long_running_operation(organization, operation_reference.id, 1)
    status = operation.status.lower()
    if status == 'failed':
        raise CLIError('Project deletion failed.')
    if status == 'cancelled':
        raise CLIError('Project deletion was cancelled.')
    print('Deleted project {}'.format(id))
    return operation
def create_project(name,
                   organization=None,
                   process=None,
                   source_control='git',
                   description=None,
                   visibility='private',
                   detect=None,
                   open=False):  # pylint: disable=redefined-builtin
    """Create a team project.
    :param name: Name of the new project.
    :type name: str
    :param process: Process to use. Default if not specified.
    :type process: str
    :param source_control: Source control type of the initial code repository created.
    :type source_control: str
    :param description: Description for the new project.
    :type description: str
    :param visibility: Project visibility.
    :type visibility: str
    :param open: Open the team project in the default web browser.
    :type open: bool
    :rtype: :class:`<TeamProject> <v5_0.core.models.TeamProject>`
    """
    organization = resolve_instance(detect=detect, organization=organization)

    team_project = TeamProject()
    team_project.name = name
    team_project.description = description

    # private is the only allowed value by vsts right now.
    team_project.visibility = visibility

    core_client = get_core_client(organization)

    # get process template id
    process_id = None
    process_list = core_client.get_processes()
    if process is not None:
        process_lower = process.lower()
        for prc in process_list:
            if prc.name.lower() == process_lower:
                process_id = prc.id
                break
        if process_id is None:
            raise CLIError(
                'Could not find a process template with name: "{}"'.format(
                    name))
    if process_id is None:
        for prc in process_list:
            if prc.is_default:
                process_id = prc.id
                break
        if process_id is None:
            raise CLIError(
                'Could not find a default process template: "{}"'.format(name))

    # build capabilities
    version_control_capabilities = {
        VERSION_CONTROL_CAPABILITY_ATTRIBUTE_NAME: source_control
    }
    process_capabilities = {
        PROCESS_TEMPLATE_CAPABILITY_TEMPLATE_TYPE_ID_ATTRIBUTE_NAME: process_id
    }
    team_project.capabilities = {
        VERSION_CONTROL_CAPABILITY_NAME: version_control_capabilities,
        PROCESS_TEMPLATE_CAPABILITY_NAME: process_capabilities
    }

    # queue project creation
    operation_reference = core_client.queue_create_project(
        project_to_create=team_project)
    operation = wait_for_long_running_operation(organization,
                                                operation_reference.id, 1)
    status = operation.status.lower()
    if status == 'failed':
        raise CLIError('Project creation failed.')
    if status == 'cancelled':
        raise CLIError('Project creation was cancelled.')

    team_project = core_client.get_project(project_id=name,
                                           include_capabilities=True)
    if open:
        _open_project(team_project)
    return team_project