microsoft / microsoft/azure-devops-python-api

Create new git branch: azure.devops.exceptions.AzureDevOpsClientRequestError: The requested resource does not support http method 'PATCH'

未关闭
#449 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Python
星标
684
派生
218
平均合并
8 天 10 小时
30 天内合并 PR
1

描述

Background:

I'm using the azure-devops-python-api - library in order to programmatically push a commit to my Azure DevOps organization (git) repository.

The Azure DevOps REST API docs for "Update - Ref" did not help me to figure out the solution.
This discussion did not help me either.

Problem:

"The requested resource does not support http method 'PATCH'" when calling update_ref() in module azure\devops\released\git\git_client_base.py.

There is no obvious function for creating a branch, which would be called create_branch() according to the principle of least surprise.
As opposed to this Azure DevOps API, this is much more intuitively resolved in e.g. the AWS CodeCommit API.

Anyways, I would like understand what exactly goes wrong here.
The error message is very generic, I could not determine which of the inputs are the problem.

Even when I provide the filter - argument instead of being None to the target or source branch name, it throws the following error:

azure.devops.exceptions.AzureDevOpsServiceError: The only property which can be patched is isLocked.

For the sake of completeness, the short docstring of filter from the above-mentioned module:

:param str filter: The name of the branch to lock/unlock

I would also be greatful for any other way of simply creating a new branch which does not exist.


Source Code:

The code involved until invoking the git_client.update_ref() - method, is:

from azure.devops.v5_1.git.models import (
    GitRefUpdate,
)
from azure.devops.connection import Connection


release_head_commit_id = '12312314123123123213123123123'
project_name = 'project_x'
repo_name = 'project_x'
release_branch_name = 'target-branch'
feature_branch_name = 'feature-branch'
git_client = Connection(base_url=organization_url, creds=credentials).clients.get_git_client()

filter_name = None  # or feature_branch_name or release_branch_name alternatively

git_client.update_ref(
                GitRefUpdate(
                    is_locked=False,
                    name=feature_branch_name,
                    new_object_id=release_head_commit_id,
                    old_object_id='0' * 40,
                    repository_id=repo_name,
                ),
                repo_name,
                filter_name ,
                project=project_name,
                project_id=project_name,
            )

The old_object_id='0' * 40 was set like this based on this comment.

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 azure/devops/released/git/git_client_base.py 和 update_ref() 入口点开始,然后查看链接的 Azure DevOps REST API 文档以及提供的 GitRefUpdate 调用。确定是否支持通过此方法创建分支,或者是否需要单独的 API 路径,并将有效输入或客户端缺失的能力作为结果记录下来。

由索引模型根据 Issue 内容生成。

评估

技术栈
azure, python
领域
api, backend
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。