Пример #1
0
def delete_ref(name, object_id=None, repository=None, organization=None, project=None, detect=None):
    """Delete a reference.
    :param str name: Name of the reference to delete (example: heads/my_branch).
    :param str object_id: Id of the reference to delete.
    :param str repository: Name or ID of the repository.
    :param str project: Name or ID of the project.
    :param str detect: Automatically detect organization and project. Default is "on".
    """
    organization, project, repository = resolve_instance_project_and_repo(
        detect=detect,
        organization=organization,
        project=project,
        repo=repository)
    client = get_git_client(organization)

    if object_id is None:
        ref = client.get_refs(repository_id=repository, project=project, filter=name)
        if not ref or len(ref) != 1:
            logger.error('ref not found')
            raise CLIError("Failed to find object_id for ref " + name + ". Please provide object_id.")

        object_id = ref[0].object_id

    ref_update = GitRefUpdate(name=resolve_git_refs(name),
                              new_object_id='0000000000000000000000000000000000000000',
                              old_object_id=object_id)
    return client.update_refs(ref_updates=[ref_update],
                              repository_id=repository,
                              project=project)[0]
Пример #2
0
def create_ref(name, object_id, repository=None, organization=None, project=None, detect=None):
    """Create a reference.
    :param str name: Name of the reference to create (example: heads/my_branch or tags/my_tag).
    :param str object_id: Id of the object to create the reference from.
    :param str repository: Name or ID of the repository.
    :param str project: Name or ID of the project.
    :param str detect: Automatically detect organization and project. Default is "on".
    """
    organization, project, repository = resolve_instance_project_and_repo(
        detect=detect,
        organization=organization,
        project=project,
        repo=repository)
    client = get_git_client(organization)
    # by default, the create method does not support setting the is_locked value
    # to True.
    ref_update = GitRefUpdate(is_locked=False,
                              name=resolve_git_refs(name),
                              new_object_id=object_id,
                              old_object_id='0000000000000000000000000000000000000000')
    response = client.update_refs(ref_updates=[ref_update],
                                  repository_id=repository,
                                  project=project)[0]
    if response.success is False:
        raise CLIError(response.custom_message)
    return response
Пример #3
0
def create_ref(name,
               object_id,
               repository=None,
               organization=None,
               project=None,
               detect=None):
    """Create a reference.
    :param str name: Name of the reference to create (example: heads/my_branch or tags/my_tag).
    :param str object_id: Id of the object to create the reference from.
    :param str repository: Name or ID of the repository.
    :param str organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/
    :param str project: Name or ID of the project.
    :param str detect: Automatically detect organization and project. Default is "on".
    """
    try:
        organization, project, repository = resolve_instance_project_and_repo(
            detect=detect,
            organization=organization,
            project=project,
            repo=repository)
        client = get_git_client(organization)
        # by default, the create method does not support setting the is_locked value
        # to True.
        ref_update = GitRefUpdate(
            is_locked=False,
            name=resolve_git_refs(name),
            new_object_id=object_id,
            old_object_id='0000000000000000000000000000000000000000')
        return client.update_refs(ref_updates=[ref_update],
                                  repository_id=repository,
                                  project=project)[0]
    except VstsServiceError as ex:
        raise CLIError(ex)
Пример #4
0
def delete_ref(name,
               object_id,
               repository=None,
               organization=None,
               project=None,
               detect=None):
    """Delete a reference.
    :param str name: Name of the reference to delete (example: heads/my_branch).
    :param str object_id: Id of the reference to delete.
    :param str repository: Name or ID of the repository.
    :param str organization: Azure Devops organization URL. Example: https://dev.azure.com/MyOrganizationName/
    :param str project: Name or ID of the project.
    :param str detect: Automatically detect organization and project. Default is "on".
    """
    try:
        organization, project, repository = resolve_instance_project_and_repo(
            detect=detect,
            organization=organization,
            project=project,
            repo=repository)
        client = get_git_client(organization)
        ref_update = GitRefUpdate(
            name=resolve_git_refs(name),
            new_object_id='0000000000000000000000000000000000000000',
            old_object_id=object_id)
        return client.update_refs(ref_updates=[ref_update],
                                  repository_id=repository,
                                  project=project)[0]
    except VstsServiceError as ex:
        raise CLIError(ex)
Пример #5
0
def delete_ref(name,
               object_id,
               repository=None,
               organization=None,
               project=None,
               detect=None):
    """Delete a reference.
    :param str name: Name of the reference to delete (example: heads/my_branch).
    :param str object_id: Id of the reference to delete.
    :param str repository: Name or ID of the repository.
    :param str project: Name or ID of the project.
    :param str detect: Automatically detect organization and project. Default is "on".
    """
    organization, project, repository = resolve_instance_project_and_repo(
        detect=detect,
        organization=organization,
        project=project,
        repo=repository)
    client = get_git_client(organization)
    ref_update = GitRefUpdate(
        name=resolve_git_refs(name),
        new_object_id='0000000000000000000000000000000000000000',
        old_object_id=object_id)
    return client.update_refs(ref_updates=[ref_update],
                              repository_id=repository,
                              project=project)[0]