def add_build_tags(build_id,
                   tags,
                   organization=None,
                   project=None,
                   detect=None):
    """Add tag(s) for a build.
    :param build_id: ID of the build.
    :type build_id: int
    :param tags: Tag(s) to be added to the build. [Comma seperated values]
    :type tags: str
    :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/
    :type organization: str
    :param project: Name or ID of the team project.
    :type project: str
    :param detect: Automatically detect instance and project. Default is "on".
    :type detect: str
    :rtype: list of str
    """
    try:
        organization, project = resolve_instance_and_project(
            detect=detect, organization=organization, project=project)
        client = get_build_client(organization)
        tags = list(map(str, tags.split(',')))
        if len(tags) == 1:
            tags = client.add_build_tag(project=project,
                                        build_id=build_id,
                                        tag=tags[0])
        else:
            tags = client.add_build_tags(tags=tags,
                                         project=project,
                                         build_id=build_id)
        return tags
    except VstsServiceError as ex:
        raise CLIError(ex)
Пример #2
0
def add_build_tags(build_id,
                   tags,
                   organization=None,
                   project=None,
                   detect=None):
    """Add tag(s) for a build.
    :param build_id: ID of the build.
    :type build_id: int
    :param tags: Tag(s) to be added to the build. [Comma seperated values]
    :type tags: str
    :rtype: list of str
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    client = get_build_client(organization)
    tags = list(map(str, tags.split(',')))
    if len(tags) == 1:
        tags = client.add_build_tag(project=project,
                                    build_id=build_id,
                                    tag=tags[0])
    else:
        tags = client.add_build_tags(tags=tags,
                                     project=project,
                                     build_id=build_id)
    return tags
Пример #3
0
def create_repo(name,
                organization=None,
                project=None,
                detect=None,
                open=False):  # pylint: disable=redefined-builtin
    """Create a Git repository in a team project.
    :param name: Name for the new repository.
    :type name: str
    :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/
    :type organization: str
    :param project: Name or ID of the team project.
    :type project: str
    :param detect: Automatically detect organization and project. Default is "on".
    :type detect: str
    :param open: Open the repository page in your web browser.
    :type open: bool
    :rtype: :class:`<GitRepository> <git.v4_0.models.GitRepository>`
    """
    try:
        organization, project = resolve_instance_and_project(
            detect=detect, organization=organization, project=project)
        git_client = get_git_client(organization)
        create_options = GitRepositoryCreateOptions()
        create_options.name = name
        repository = git_client.create_repository(
            git_repository_to_create=create_options, project=project)
        if open:
            _open_repository(repository, organization)
        return repository
    except VstsServiceError as ex:
        raise CLIError(ex)
Пример #4
0
def update_policy_work_item_linking(policy_id,
                                    repository_id=None, branch=None, is_blocking=None, is_enabled=None,
                                    organization=None, project=None, detect=None):
    """Update work item linking policy.
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    policy_client = get_policy_client(organization)
    current_policy = policy_client.get_policy_configuration(project=project, configuration_id=policy_id)

    current_scope = current_policy.settings['scope'][0]

    updated_configuration = create_configuration_object(
        repository_id or current_scope['repositoryId'],
        branch or current_scope['refName'],
        is_blocking or str(current_policy.is_blocking),
        is_enabled or str(current_policy.is_enabled),
        '40e92b44-2fe1-4dd6-b3d8-74a9c21d0c6e',
        [],
        []
    )

    return policy_client.update_policy_configuration(
        configuration=updated_configuration,
        project=project,
        configuration_id=policy_id
    )
Пример #5
0
def update_policy_case_enforcement(policy_id,
                                   repository_id=None, is_blocking=None, is_enabled=None,
                                   organization=None, project=None, detect=None):
    """Update case enforcement policy.
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    policy_client = get_policy_client(organization)
    current_policy = policy_client.get_policy_configuration(project=project, configuration_id=policy_id)

    current_scope = current_policy.settings['scope'][0]

    updated_configuration = create_configuration_object(
        repository_id or current_scope['repositoryId'],
        None,
        is_blocking or str(current_policy.is_blocking),
        is_enabled or str(current_policy.is_enabled),
        '40e92b44-2fe1-4dd6-b3d8-74a9c21d0c6e',
        ['enforceConsistentCase'],
        ['true']
    )

    return policy_client.update_policy_configuration(
        configuration=updated_configuration,
        project=project,
        configuration_id=policy_id
    )
Пример #6
0
def update_policy_merge_strategy(policy_id,
                                 repository_id=None, branch=None, is_blocking=None, is_enabled=None,
                                 use_squash_merge=None,
                                 organization=None, project=None, detect=None):
    """Update merge strategy policy
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    policy_client = get_policy_client(organization)
    current_policy = policy_client.get_policy_configuration(project=project, configuration_id=policy_id)
    param_name_array = ['useSquashMerge']

    current_setting = current_policy.settings
    current_scope = current_policy.settings['scope'][0]

    param_value_array = [
        use_squash_merge or current_setting.get('useSquashMerge', None)
    ]

    updated_configuration = create_configuration_object(
        repository_id or current_scope['repositoryId'],
        branch or current_scope['refName'],
        is_blocking or str(current_policy.is_blocking),
        is_enabled or str(current_policy.is_enabled),
        'fa4e907d-c16b-4a4c-9dfa-4916e5d171ab',
        param_name_array,
        param_value_array
    )

    return policy_client.update_policy_configuration(
        configuration=updated_configuration,
        project=project,
        configuration_id=policy_id
    )
Пример #7
0
def update_policy_file_size(policy_id,
                            repository_id=None, is_blocking=None, is_enabled=None,
                            maximum_git_blob_size=None, use_uncompressed_size=None,
                            organization=None, project=None, detect=None):
    """Update file size policy
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    policy_client = get_policy_client(organization)
    current_policy = policy_client.get_policy_configuration(project=project, configuration_id=policy_id)
    param_name_array = ['maximumGitBlobSizeInBytes', 'useUncompressedSize']

    current_setting = current_policy.settings
    current_scope = current_policy.settings['scope'][0]

    param_value_array = [
        maximum_git_blob_size or current_setting.get('maximumGitBlobSizeInBytes', None),
        use_uncompressed_size or current_setting.get('useUncompressedSize', None)
    ]

    updated_configuration = create_configuration_object(
        repository_id or current_scope['repositoryId'],
        None,
        is_blocking or str(current_policy.is_blocking),
        is_enabled or str(current_policy.is_enabled),
        '2e26e725-8201-4edd-8bf5-978563c34a80',
        param_name_array,
        param_value_array
    )

    return policy_client.update_policy_configuration(
        configuration=updated_configuration,
        project=project,
        configuration_id=policy_id
    )
Пример #8
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)
Пример #9
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)
Пример #10
0
def create_github_service_endpoint(name,
                                   github_url,
                                   organization=None,
                                   project=None,
                                   detect=None):
    """ Create a GitHub service endpoint.
    :param name: Name of service endpoint to create
    :type name: str
    :param github_url: Url for github for creating service endpoint
    :type github_url: str
    :rtype: :class:`ServiceEndpoint <service_endpoint.v4_1.models.ServiceEndpoint>`
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    client = get_service_endpoint_client(organization)
    if AZ_DEVOPS_GITHUB_PAT_ENVKEY not in os.environ:
        error_message = 'Please pass GitHub access token in ' + AZ_DEVOPS_GITHUB_PAT_ENVKEY +\
                        ' environment variable in non-interactive mode.'
        verify_is_a_tty_or_raise_error(error_message)
        github_access_token = prompt_pass('GitHub access token:', confirm=True)
    else:
        logger.debug('Picking GitHub PAT from environment variable')
        github_access_token = os.environ[AZ_DEVOPS_GITHUB_PAT_ENVKEY]

    service_endpoint_authorization = EndpointAuthorization(
        parameters={'accessToken': github_access_token},
        scheme=SERVICE_ENDPOINT_AUTHORIZATION_PERSONAL_ACCESS_TOKEN)
    service_endpoint_to_create = ServiceEndpoint(
        authorization=service_endpoint_authorization,
        name=name,
        type=SERVICE_ENDPOINT_TYPE_GITHUB,
        url=github_url)
    return client.create_service_endpoint(service_endpoint_to_create, project)
Пример #11
0
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)
Пример #12
0
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 release_list(definition_id=None, source_branch=None, organization=None, project=None, detect=None, top=None,
                 status=None):
    """List release results.
    :param definition_id: ID of definition to list releases for.
    :type definition_id: int
    :param branch: Filter by releases for this branch.
    :type branch: str
    :param top: Maximum number of releases to list. Default is 50.
    :type top: int
    :param status: Limit to releases with this status.
    :type status: str
    :param source_branch: Filter releases for this branch.
    :type source_branch: str
    :rtype: :class:`<Release> <v5_0.release.models.Release>`
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    client = get_release_client(organization)

    releases = client.get_releases(definition_id=definition_id,
                                   project=project,
                                   source_branch_filter=source_branch,
                                   top=top,
                                   status_filter=status)
    return releases
def delete_build_tag(build_id,
                     tag,
                     organization=None,
                     project=None,
                     detect=None):
    """Delete a build tag.
    :param build_id: ID of the build.
    :type build_id: int
    :param tag: Tag to be deleted from the build.
    :type tag: str
    :param organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/
    :type organization: str
    :param project: Name or ID of the team project.
    :type project: str
    :param detect: Automatically detect instance and project. Default is "on".
    :type detect: str
    :rtype: list of str
    """
    try:
        organization, project = resolve_instance_and_project(
            detect=detect, organization=organization, project=project)
        client = get_build_client(organization)
        tags = client.delete_build_tag(project=project,
                                       build_id=build_id,
                                       tag=tag)
        return tags
    except VstsServiceError as ex:
        raise CLIError(ex)
def update_policy_case_enforcement(policy_id,
                                   repository_id=None,
                                   blocking=None,
                                   enabled=None,
                                   organization=None,
                                   project=None,
                                   detect=None):
    """Update case enforcement policy.
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    policy_client = get_policy_client(organization)
    current_policy = policy_client.get_policy_configuration(
        project=project, configuration_id=policy_id)

    current_scope = current_policy.settings['scope'][0]

    updated_configuration = create_configuration_object(
        repository_id or current_scope['repositoryId'], None,
        blocking if blocking is not None else current_policy.is_blocking,
        enabled if enabled is not None else current_policy.is_enabled,
        '7ed39669-655c-494e-b4a0-a08b4da0fcce', ['enforceConsistentCase'],
        ['true'])

    return policy_client.update_policy_configuration(
        configuration=updated_configuration,
        project=project,
        configuration_id=policy_id)
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
Пример #17
0
def list_policy(organization=None, project=None, repository_id=None, branch=None, detect=None):
    """List all policies in a project.
    :param repository_id: Id (UUID) of the repository.
    :type repository_id: string
    :param branch: Branch. (--repository-id is required)
    :type branch: string
    :rtype: [PolicyConfiguration]
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)

    if branch is not None and repository_id is None:
        raise CLIError('--repository-id is required with --branch')

    scope = None

    if repository_id is not None:
        repository_id = repository_id.replace('-', '')
        scope = repository_id
        if branch is not None:
            branch = resolve_git_ref_heads(branch)
            scope = scope + ':' + branch

    policy_client = get_policy_client(organization)
    return policy_client.get_policy_configurations(project=project, scope=scope)
def pipeline_show(id=None, name=None, open=False, organization=None, project=None,  # pylint: disable=redefined-builtin
                  folder_path=None, detect=None):
    """ Get the details of a pipeline.
    :param id: ID of the pipeline.
    :type id: int
    :param name: Name of the pipeline. Ignored if --id is supplied.
    :type name: str
    :param folder_path: Folder path of pipeline. Default is root level folder.
    :type folder_path: str
    :param open: Open the pipeline summary page in your web browser.
    :type open: bool
    :param detect: Automatically detect values for instance and project. Default is "on".
    :type detect: str
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    client = get_build_client(organization)
    if id is None:
        if name is not None:
            id = get_definition_id_from_name(name, client, project, path=folder_path)
        else:
            raise CLIError("Either the --id argument or the --name argument must be supplied for this command.")
    build_definition = client.get_definition(definition_id=id, project=project)
    if open:
        _open_pipeline(build_definition, organization)
    return build_definition
Пример #19
0
def create_policy_build(repository_id, branch, branch_match_type, is_blocking, is_enabled,
                        build_definition_id, queue_on_source_update_only, manual_queue_only, display_name, valid_duration,
                        path_filter=None,
                        organization=None, project=None, detect=None):
    """Create build policy
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    policy_client = get_policy_client(organization)
    param_name_array = [
        'buildDefinitionId',
        'queueOnSourceUpdateOnly',
        'manualQueueOnly',
        'displayName',
        'validDuration',
        'filenamePatterns']
    param_value_array = [
        build_definition_id,
        queue_on_source_update_only,
        manual_queue_only,
        display_name,
        valid_duration,
        createFileNamePatterns(path_filter)]
    configuration = create_configuration_object(repository_id, branch, is_blocking, is_enabled,
                                                '0609b952-1397-4640-95ec-e00a01b2c241',
                                                param_name_array, param_value_array,
                                                branch_match_type)

    return policy_client.create_policy_configuration(configuration=configuration, project=project)
Пример #20
0
def pipeline_update(
        name=None,
        id=None,
        description=None,
        new_name=None,  # pylint: disable=redefined-builtin
        branch=None,
        yml_path=None,
        queue_id=None,
        organization=None,
        project=None,
        detect=None,
        new_folder_path=None):
    """ Update a pipeline
    :param name: Name of the pipeline to update.
    :type name: str
    :param id: Id of the pipeline to update.
    :type id: str
    :param new_name: New updated name of the pipeline.
    :type new_name: str
    :param description: New description for the pipeline.
    :type description: str
    :param branch: Branch name for which the pipeline will be configured.
    :type branch: str
    :param yml_path: Path of the pipelines yaml file in the repo.
    :type yml_path: str
    :param queue_id: Queue id of the agent pool where the pipeline needs to run.
    :type queue_id: int
    :param new_folder_path: New full path of the folder to move the pipeline to.
    e.g. "user1/production_pipelines"
    :type new_folder_path: str
    """
    # pylint: disable=too-many-branches
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    pipeline_client = get_new_pipeline_client(organization=organization)
    if id is None:
        if name is not None:
            id = get_definition_id_from_name(name, pipeline_client, project)
        else:
            raise CLIError(
                "Either --id or --name argument must be supplied for this command."
            )
    definition = pipeline_client.get_definition(definition_id=id,
                                                project=project)
    if new_name:
        definition.name = new_name
    if description:
        definition.description = description
    if branch:
        definition.repository.default_branch = branch
    if queue_id:
        definition.queue = AgentPoolQueue()
        definition.queue.id = queue_id
    if yml_path:
        definition.process = _create_process_object(yml_path)
    if new_folder_path:
        definition.path = new_folder_path
    return pipeline_client.update_definition(project=project,
                                             definition_id=id,
                                             definition=definition)
Пример #21
0
def update_policy_comment_required(policy_id,
                                   repository_id=None, branch=None, is_blocking=None, is_enabled=None,
                                   organization=None, project=None, detect=None):
    """Update comment resolution required policy.
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    policy_client = get_policy_client(organization)
    current_policy = policy_client.get_policy_configuration(project=project, configuration_id=policy_id)

    current_scope = current_policy.settings['scope'][0]

    updated_configuration = create_configuration_object(
        repository_id or current_scope['repositoryId'],
        branch or current_scope['refName'],
        is_blocking or str(current_policy.is_blocking),
        is_enabled or str(current_policy.is_enabled),
        'c6a1889d-b943-4856-b76f-9e46bb6b0df2',
        [],
        []
    )

    return policy_client.update_policy_configuration(
        configuration=updated_configuration,
        project=project,
        configuration_id=policy_id
    )
def build_definition_show(
        id=None,
        name=None,
        open=False,
        organization=None,
        project=None,  # pylint: disable=redefined-builtin
        detect=None):
    """Get the details of a build definition.
    :param id: ID of the definition.
    :type id: int
    :param name: Name of the definition. Ignored if --id is supplied.
    :type name: str
    :param open: Open the definition summary page in your web browser.
    :type open: bool
    :rtype: BuildDefinitionReference
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    client = get_build_client(organization)
    if id is None:
        if name is not None:
            id = get_definition_id_from_name(name, client, project)
        else:
            raise ValueError(
                "Either the --id argument or the --name argument must be supplied for this command."
            )
    build_definition = client.get_definition(definition_id=id, project=project)
    if open:
        _open_definition(build_definition, organization)
    return build_definition
Пример #23
0
def get_policy(policy_id, organization=None, project=None, detect=None):
    """Show policy details.
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    policy_client = get_policy_client(organization)
    return policy_client.get_policy_configuration(project=project, configuration_id=policy_id)
def pipeline_variable_list(pipeline_id=None,
                           pipeline_name=None,
                           organization=None,
                           project=None,
                           detect=None):
    """List the variables in a pipeline
    :param pipeline_id: Id of the pipeline.
    :type pipeline_id: int
    :param pipeline_name: Name of the pipeline. Ignored if --pipeline-id parameter is supplied.
    :type pipeline_name: str
     """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    if pipeline_id is None and pipeline_name is None:
        raise ValueError(
            'Either the --pipeline-id or --pipeline-name argument ' +
            'must be supplied for this command.')
    pipeline_client = get_build_client(organization)
    if pipeline_id is None:
        pipeline_id = get_definition_id_from_name(pipeline_name,
                                                  pipeline_client, project)
    # get pipeline definition
    pipeline_definition = pipeline_client.get_definition(
        definition_id=pipeline_id, project=project)
    return pipeline_definition.variables
Пример #25
0
def delete_policy(policy_id, organization=None, project=None, detect=None):
    """Delete a policy.
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    policy_client = get_policy_client(organization)
    return policy_client.delete_policy_configuration(project=project, configuration_id=policy_id)
def create_policy_approver_count(repository_id,
                                 branch,
                                 blocking,
                                 enabled,
                                 minimum_approver_count,
                                 creator_vote_counts,
                                 allow_downvotes,
                                 reset_on_source_push,
                                 branch_match_type='exact',
                                 organization=None,
                                 project=None,
                                 detect=None):
    """Create approver count policy
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    policy_client = get_policy_client(organization)
    param_name_array = [
        'minimumApproverCount', 'creatorVoteCounts', 'allowDownvotes',
        'resetOnSourcePush'
    ]
    param_value_array = [
        minimum_approver_count, creator_vote_counts, allow_downvotes,
        reset_on_source_push
    ]
    configuration = create_configuration_object(
        repository_id, branch, blocking, enabled,
        'fa4e907d-c16b-4a4c-9dfa-4906e5d171dd', param_name_array,
        param_value_array, branch_match_type)

    return policy_client.create_policy_configuration(
        configuration=configuration, project=project)
Пример #27
0
def get_page(
        wiki,
        path,
        version=None,
        open=False,  # pylint: disable=redefined-builtin
        include_content=False,
        organization=None,
        project=None,
        detect=None):
    """Get the content of a page or open a page.
    :param wiki: Name or Id of the wiki.
    :type wiki: str
    :param path: Path of the wiki page.
    :type path: str
    :param version: Version (ETag) of the wiki page.
    :type version: str
    :param include_content: Include content of the page.
    :type include_content: str
    :param open: Open the wiki page in your web browser.
    :type open: bool
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    wiki_client = get_wiki_client(organization)
    page_object = wiki_client.get_page(wiki_identifier=wiki,
                                       project=project,
                                       path=path,
                                       recursion_level=None,
                                       version_descriptor=version,
                                       include_content=include_content)
    if open:
        webbrowser.open_new(url=page_object.page.remote_url)
    return page_object
def create_policy_required_reviewer(repository_id,
                                    branch,
                                    blocking,
                                    enabled,
                                    message,
                                    required_reviewer_ids,
                                    branch_match_type='exact',
                                    path_filter=None,
                                    organization=None,
                                    project=None,
                                    detect=None):
    """Create required reviewer policy
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    requiredReviewerIds = resolveIdentityMailsToIds(required_reviewer_ids,
                                                    organization)
    policy_client = get_policy_client(organization)
    param_name_array = ['requiredReviewerIds', 'message', 'filenamePatterns']
    param_value_array = [
        requiredReviewerIds, message,
        createFileNamePatterns(path_filter)
    ]
    configuration = create_configuration_object(
        repository_id, branch, blocking, enabled,
        'fd2167ab-b0be-447a-8ec8-39368250530e', param_name_array,
        param_value_array, branch_match_type)

    return policy_client.create_policy_configuration(
        configuration=configuration, project=project)
def pipeline_variable_delete(name, pipeline_id=None, pipeline_name=None, organization=None, project=None, detect=None):
    """Delete a variable from pipeline
    :param pipeline_id: Id of the pipeline.
    :type pipeline_id: int
    :param pipeline_name: Name of the pipeline.
    :type pipeline_name: str
    :param name: Name of the variable to delete.
    :type name: str
     """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    if pipeline_id is None and pipeline_name is None:
        raise ValueError('Either the --pipeline-id or --pipeline-name argument ' +
                         'must be supplied for this command.')
    pipeline_client = get_build_client(organization)
    if pipeline_id is None:
        pipeline_id = get_definition_id_from_name(name, pipeline_client, project)
    # get pipeline definition
    pipeline_definition = pipeline_client.get_definition(definition_id=pipeline_id, project=project)

    key_to_delete = None
    # Check if the variable already exists
    key = None
    if pipeline_definition.variables:
        for key in pipeline_definition.variables.keys():
            if key.lower() == name.lower():
                key_to_delete = key
                break
    if not key_to_delete:
        raise CLIError('Variable \'{}\' does not exist. '.format(name))
    _ = pipeline_definition.variables.pop(key)
    _ = pipeline_client.update_definition(project=project, definition_id=pipeline_id, definition=pipeline_definition)
    print('Deleted variable \'{}\' successfully.'.format(key_to_delete))
Пример #30
0
def release_definition_list(name=None, top=None, organization=None, project=None,
                            artifact_type=None, artifact_source_id=None, detect=None):
    """List release definitions.
    :param name: Limit results to definitions with this name or contains this name. Example: "FabCI"
    :type name: str
    :param top: Maximum number of definitions to list.
    :type top: int
    :param artifact_type: Release definitions with given artifactType will be returned.
    :type artifact_type: str
    :param artifact_source_id: Limit results to definitions associated with this artifact_source_id.
    e.g. For build it would be {projectGuid}:{BuildDefinitionId}, for Jenkins it would be
    {JenkinsConnectionId}:{JenkinsDefinitionId}, for TfsOnPrem it would be
    {TfsOnPremConnectionId}:{ProjectName}:{TfsOnPremDefinitionId}.
    For third-party artifacts e.g. TeamCity, BitBucket you may refer 'uniqueSourceIdentifier'
    inside vss-extension.json at https://github.com/Microsoft/vsts-rm-extensions/blob/master/Extensions.
    :type artifact_source_id: str
    :rtype: [ReleaseDefinitionReference]
    """
    organization, project = resolve_instance_and_project(
        detect=detect, organization=organization, project=project)
    client = get_release_client(organization)
    query_order = 'nameAscending'
    definition_references = client.get_release_definitions(
        project=project, search_text=name, artifact_source_id=artifact_source_id, artifact_type=artifact_type,
        top=top, query_order=query_order)
    return definition_references