def add_team_area(path, team, set_as_default=False, include_sub_areas=None, organization=None, project=None, detect=None): """(PREVIEW) Add area to a team. :param set_as_default: Set this area path as default area for this team. Default: False :type set_as_default: bool """ organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) get_response = client.get_team_field_values(team_context=team_context) patch_doc = TeamFieldValuesPatch() patch_doc.values = get_response.values if include_sub_areas is None: include_sub_areas = False team_field_value = TeamFieldValue(include_children=include_sub_areas, value=path) if set_as_default: patch_doc.default_value = path else: patch_doc.default_value = get_response.default_value patch_doc.values.append(team_field_value) try: update_response = client.update_team_field_values( patch=patch_doc, team_context=team_context) return update_response except AzureDevOpsServiceError as ex: handle_common_boards_errors(ex)
def set_default_iteration(team, id=None, default_iteration_macro=None, organization=None, project=None, detect=None): # pylint: disable=redefined-builtin """Set default iteration for a team. :param id: Identifier of the iteration which needs to be set as default. :type: str :param team: Name or ID of the team. :type: str :param default_iteration_macro: Default iteration macro. Example: @CurrentIteration. :type: str """ if default_iteration_macro is None and id is None: raise CLIError('Either --id or --default-iteration-macro is required.') organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) patch_object = TeamSettingsPatch() if id: patch_object.default_iteration = id if default_iteration_macro: patch_object.default_iteration_macro = default_iteration_macro team_iteration_setting = client.update_team_settings( team_settings_patch=patch_object, team_context=team_context) return team_iteration_setting
def remove_team_area(path, team, organization=None, project=None, detect=None): """(PREVIEW) Remove area from a team. """ organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) if path[0] == '\\': path = path[1:] get_response = client.get_team_field_values(team_context=team_context) if get_response.default_value == path: raise CLIError( 'You are trying to remove the default area for this team. ' 'Please change the default area node and then try this command again.' ) area_found = False for entry in get_response.values: if path == entry.value[:]: area_found = True get_response.values.remove(entry) if not area_found: raise CLIError('Path is not added to team area list.') patch_doc = TeamFieldValuesPatch() patch_doc.values = get_response.values patch_doc.default_value = get_response.default_value try: update_response = client.update_team_field_values( patch=patch_doc, team_context=team_context) return update_response except AzureDevOpsServiceError as ex: handle_common_boards_errors(ex)
def get_team_areas(team, organization=None, project=None, detect=None): """(PREVIEW) List areas for a team. """ organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) list_of_areas = client.get_team_field_values(team_context=team_context) return list_of_areas
def show_backlog_iteration(team, organization=None, project=None, detect=None): """(PREVIEW) Show backlog iteration for a team. :param team: Name or ID of the team. :type: str """ organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) team_iteration_setting = client.get_team_settings(team_context=team_context) return team_iteration_setting
def get_team_iteration(id, team, organization=None, project=None, detect=None): # pylint: disable=redefined-builtin """ Get iteration details for a team. :param id: Identifier of the iteration. :type: str :param team: Name or ID of the team. :type: str """ organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) team_iteration = client.get_team_iteration(team_context=team_context, id=id) return team_iteration
def set_backlog_iteration(team, id, organization=None, project=None, detect=None): # pylint: disable=redefined-builtin """(PREVIEW) Set backlog iteration for a team. :param id: Identifier of the iteration which needs to be set as backlog iteration. :type: str :param team: Name or ID of the team. :type: str """ organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) patch_object = TeamSettingsPatch() patch_object.backlog_iteration = id team_iteration_setting = client.update_team_settings(team_settings_patch=patch_object, team_context=team_context) return team_iteration_setting
def delete_team_iteration(id, team, organization=None, project=None, detect=None): # pylint: disable=redefined-builtin """(PREVIEW) Remove iteration from a team. :param id: Identifier of the iteration. :type: str :param team: Name or ID of the team. :type: str """ organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) try: team_iteration = client.delete_team_iteration(team_context=team_context, id=id) return team_iteration except AzureDevOpsServiceError as ex: handle_common_boards_errors(ex)
def list_iteration_work_items(id, team, organization=None, project=None, detect=None): # pylint: disable=redefined-builtin """(PREVIEW) List work-items for an iteration. :param id: Identifier of the iteration. :type: str :param team: Name or ID of the team. :type: str """ organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) work_items = client.get_iteration_work_items(iteration_id=id, team_context=team_context) wit_client = get_work_item_tracking_client(organization) relation_types = wit_client.get_relation_types() work_items = _fill_friendly_name_for_relations_in_iteration_work_items(relation_types_from_service=relation_types, iteration_work_items=work_items) return work_items
def post_team_iteration(id, team, organization=None, project=None, detect=None): # pylint: disable=redefined-builtin """(PREVIEW) Add iteration to a team. :param id: Identifier of the iteration. :type: str :param team: Name or ID of the team. :type: str """ organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) team_setting_iteration = TeamSettingsIteration(id=id) try: team_iteration = client.post_team_iteration(iteration=team_setting_iteration, team_context=team_context) return team_iteration except AzureDevOpsServiceError as ex: _handle_empty_backlog_iteration_id(ex=ex, client=client, team_context=team_context)
def get_team_iterations(team, timeframe=None, organization=None, project=None, detect=None): """(PREVIEW) List iterations for a team. :param team: The name or id of the team. :type team: str :param timeframe: A filter for which iterations are returned based on relative time. Only Current is supported currently. :type: str :rtype: :class:`<WebApiTeam> <v5_0.core.models.WebApiTeam>` """ organization, project = resolve_instance_and_project(detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) list_of_iterations = client.get_team_iterations(team_context=team_context, timeframe=timeframe) return list_of_iterations
def post_team_iteration(id, team, organization=None, project=None, detect=None): # pylint: disable=redefined-builtin """Add iteration to a team. :param id: Identifier of the iteration. :type: str :param team: Name or ID of the team. :type: str """ organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) team_setting_iteration = TeamSettingsIteration(id=id) team_iteration = client.post_team_iteration( iteration=team_setting_iteration, team_context=team_context) return team_iteration
def update_team_area(path, team, include_sub_areas=None, set_as_default=False, organization=None, project=None, detect=None): """(PREVIEW) Update team area. :param set_as_default: Set as default team area path. Default: False :type set_as_default: bool """ if include_sub_areas is None and set_as_default is False: raise CLIError( 'Either --set-as-default or --include-sub-areas parameter should be provided.' ) organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) get_response = client.get_team_field_values(team_context=team_context) patch_doc = TeamFieldValuesPatch() area_found = False for entry in get_response.values: if path == entry.value[:]: area_found = True if include_sub_areas is not None: entry.include_children = include_sub_areas if set_as_default is True: patch_doc.default_value = path else: patch_doc.default_value = get_response.default_value if not area_found: raise CLIError('Path is not added to team area list.') patch_doc.values = get_response.values try: update_response = client.update_team_field_values( patch=patch_doc, team_context=team_context) return update_response except AzureDevOpsServiceError as ex: handle_common_boards_errors(ex)
def remove_team_area(path, team, organization=None, project=None, detect=None): """Remove area from a team. """ organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) get_response = client.get_team_field_values(team_context=team_context) if get_response.default_value == path: raise CLIError( 'You are trying to remove the default area for this team. ' 'Please change the default area node and then try this command again.' ) for entry in get_response.values: if path == entry.value[:]: get_response.values.remove(entry) patch_doc = TeamFieldValuesPatch() patch_doc.values = get_response.values patch_doc.default_value = get_response.default_value update_response = client.update_team_field_values( patch=patch_doc, team_context=team_context) return update_response
def update_team_area(path, team, include_sub_areas=None, set_as_default=False, organization=None, project=None, detect=None): """Update any area to include/exclude sub areas OR Set already added area as default. :param default_area:set_as_default: Set as default team area path. :type set_as_default: bool """ if include_sub_areas is None and set_as_default is False: raise CLIError( 'Either --set-as-default or --include-sub-areas parameter should be provided.' ) organization, project = resolve_instance_and_project( detect=detect, organization=organization, project=project) client = get_work_client(organization) team_context = TeamContext(project=project, team=team) get_response = client.get_team_field_values(team_context=team_context) patch_doc = TeamFieldValuesPatch() area_found = False for entry in get_response.values: if path == entry.value[:]: area_found = True if include_sub_areas is not None: entry.include_children = include_sub_areas if set_as_default is True: patch_doc.default_value = path else: patch_doc.default_value = get_response.default_value if not area_found: raise CLIError('Path is not added to team area list.') patch_doc.values = get_response.values update_response = client.update_team_field_values( patch=patch_doc, team_context=team_context) return update_response