def update_team(team, name=None, description=None, organization=None, project=None, detect=None): """Update a team's name and/or description. :param team: The name or id of the team to be updated. :type team: str :param name: New name of the team. :type name: str :param description: New description of the team. :type description: str :rtype: :class:`<WebApiTeam> <core.v4_0.models.WebApiTeam>` """ if name is None and description is None: raise CLIError('Either name or description argument must be provided.') try: organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) core_client = get_core_client(organization) updated_team_data = WebApiTeam(name=name, description=description) return core_client.update_team(team_data=updated_team_data, project_id=project, team_id=team) except VstsServiceError as ex: raise CLIError(ex)
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)
def update_team(team, name=None, description=None, organization=None, project=None, detect=None): """Update a team's name and/or description. :param team: The name or id of the team to be updated. :type team: str :param name: New name of the team. :type name: str :param description: New description of the team. :type description: str :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/ :type organization: str :param project: Name or ID of the project. :type project: str :param detect: When 'On' unsupplied arg values will be detected from the current working directory's repo. :rtype: :class:`<WebApiTeam> <core.v4_0.models.WebApiTeam>` """ if name is None and description is None: raise CLIError('Either name or description argument must be provided.') try: organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) core_client = get_core_client(organization) updated_team_data = WebApiTeam(name=name, description=description) return core_client.update_team(team_data=updated_team_data, project_id=project, team_id=team) except VstsServiceError as ex: raise CLIError(ex)
def get_teams(top=None, skip=None, organization=None, project=None, detect=None): """List of all teams for a project. :param top: Maximum number of teams to return. :type top: int :param skip: Number of teams to skip. :type skip: int :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/ :type organization: str :param project: Name or ID of the project. :type project: str :param detect: Automatically detect organization and project. Default is "on". :type detect: str :rtype: [WebApiTeam] """ try: organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) core_client = get_core_client(organization) return core_client.get_teams(top=top, skip=skip, project_id=project) except VstsServiceError as ex: raise CLIError(ex)
def create_team(name, description=None, organization=None, project=None, detect=None): """Create a team. :param name: Name of the new team. :type name: str :param description: Description of the new team. :type description: str :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/ :type organization: str :param project: Name or ID of the project. :type project: str :param detect: Automatically detect organization and project. Default is "on". :type detect: str :rtype: :class:`<WebApiTeam> <core.v4_0.models.WebApiTeam>` """ try: organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) core_client = get_core_client(organization) team_to_create = WebApiTeam(name=name, description=description) return core_client.create_team(team=team_to_create, project_id=project) except VstsServiceError as ex: raise CLIError(ex)
def delete_team(id, organization=None, project=None, detect=None): # pylint: disable=redefined-builtin """Delete a team. :param id: The id (UUID) of the team to delete. :type id: str """ organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) core_client = get_core_client(organization) return core_client.delete_team(team_id=id, project_id=project)
def get_team(team, organization=None, project=None, detect=None): """Show team details. :param team: The name or id of the team to show. :type team: str :rtype: :class:`<WebApiTeam> <core.v4_0.models.WebApiTeam>` """ organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) core_client = get_core_client(organization) return core_client.get_team(team_id=team, project_id=project)
def list_projects(organization=None, top=None, skip=None, detect=None): """List team projects :param top: Maximum number of results to list. :type top: int :param skip: Number of results to skip. :type skip: int :rtype: list of :class:`<TeamProject> <v5_0.core.models.TeamProject>` """ organization = resolve_instance(detect=detect, organization=organization) core_client = get_core_client(organization) team_projects = core_client.get_projects(state_filter='all', top=top, skip=skip) return team_projects
def get_teams(top=None, skip=None, organization=None, project=None, detect=None): """List all teams in a project. :param top: Maximum number of teams to return. :type top: int :param skip: Number of teams to skip. :type skip: int :rtype: [WebApiTeam] """ organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) core_client = get_core_client(organization) return core_client.get_teams(top=top, skip=skip, project_id=project)
def create_team(name, description=None, organization=None, project=None, detect=None): """Create a team. :param name: Name of the new team. :type name: str :param description: Description of the new team. :type description: str :rtype: :class:`<WebApiTeam> <v5_0.core.models.WebApiTeam>` """ organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) core_client = get_core_client(organization) team_to_create = WebApiTeam(name=name, description=description) return core_client.create_team(team=team_to_create, project_id=project)
def show_project(project, organization=None, detect=None, open=False): # pylint: disable=redefined-builtin """Show team project. :param project: The id or name of the project to show. :type project: 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) core_client = get_core_client(organization) team_project = core_client.get_project(project_id=project, include_capabilities=True) if open: _open_project(team_project) return team_project
def get_team_members(team, top=None, skip=None, organization=None, project=None, detect=None): """List members of a team. :param team: The name or id of the team to show members of. :type team: str :param top: Maximum number of members to return. :type top: int :param skip: Number of members to skip. :type skip: int :rtype: [IdentityRef] """ organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) core_client = get_core_client(organization) return core_client.get_team_members_with_extended_properties(team_id=team, top=top, skip=skip, project_id=project)
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 delete_team(team, organization=None, project=None, detect=None): """Deletes a team. :param team: The name or id of the team to delete. :type team: str :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/ :type organization: str :param project: Name or ID of the project. :type project: str :param detect: Automatically detect organization and project. Default is "on". :type detect: str """ try: organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) core_client = get_core_client(organization) return core_client.delete_team(team_id=team, project_id=project) except VstsServiceError as ex: raise CLIError(ex)
def get_team(team, organization=None, project=None, detect=None): """Show team details. :param team: The name or id of the team to show. :type team: str :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/ :type organization: str :param project: Name or ID of the project. :type project: str :param detect: Automatically detect organization and project. Default is "on". :type detect: str :rtype: :class:`<WebApiTeam> <core.v4_0.models.WebApiTeam>` """ try: organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) core_client = get_core_client(organization) return core_client.get_team(team_id=team, project_id=project) except VstsServiceError as ex: raise CLIError(ex)
def list_projects(organization=None, top=None, skip=None, detect=None): """List team projects :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/ :type organization: str :param top: Maximum number of results to list. :type top: int :param skip: Number of results to skip. :type skip: int :param detect: When 'On' unsupplied arg values will be detected from the current working directory's repo. :type detect: str :rtype: list of :class:`<TeamProject> <core.v4_0.models.TeamProject>` """ try: organization = resolve_instance(detect=detect, organization=organization) core_client = get_core_client(organization) team_projects = core_client.get_projects(state_filter='all', top=top, skip=skip) return team_projects except VstsServiceError as ex: raise CLIError(ex)
def show_project(project, organization=None, detect=None, open=False): # pylint: disable=redefined-builtin """Show team project. :param project: The id (UUID) or name of the project to show. :type project: 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 :param open: Open the team project in the default web browser. :type open: bool :rtype: :class:`<TeamProject> <core.v4_0.models.TeamProject>` """ try: organization = resolve_instance(detect=detect, organization=organization) core_client = get_core_client(organization) team_project = core_client.get_project(project_id=project, include_capabilities=True) if open: _open_project(team_project) return team_project except VstsServiceError as ex: raise CLIError(ex)
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