Пример #1
0
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)
Пример #2
0
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 _prepare_team_field_values_patch_object(self,
                                             path,
                                             include_children=False,
                                             is_default=True):
     patch_obj = TeamFieldValuesPatch()
     patch_obj.values = []
     # add root node
     team_field_value = TeamFieldValue(include_children=False,
                                       value=self._TEAM_ROOT_AREA_PATH)
     patch_obj.values.append(team_field_value)
     patch_obj.default_value = self._TEAM_ROOT_AREA_PATH
     # add child node
     team_field_value = TeamFieldValue(include_children=include_children,
                                       value=path)
     if is_default:
         patch_obj.default_value = path
     patch_obj.values.append(team_field_value)
     team_field_value = TeamFieldValue(include_children=False,
                                       value=self._TEAM_ROOT_AREA_PATH)
     patch_obj.values.append(team_field_value)
     return patch_obj
Пример #4
0
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)
Пример #5
0
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
Пример #6
0
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