我在Azure DevOps上有两个回购协议,我们称它们为parent_repo
和child_repo
。child_repo
是父级的分支。我想做的是创建一个PR,使用Azure DevOps服务API,通过its Python library将child_repo
中的master
合并到parent_repo
中的master
根据these docs和this thread,forkSource
是指示源分支位于分支中并提供该分支的repo_id
所需的参数
from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication
_connection = Connection(base_url=URL, creds=BasicAuthentication("", PAT))
CLIENT = _connection.clients.get_git_client()
args = {
"git_pull_request_to_create": {
"sourceRefName": f"refs/heads/master",
"targetRefName": f"refs/heads/master",
"forkSource": {"repository": {"repository": child_repo_id}},
"title": "...",
"description": "...",
},
"repository_id": parent_repo_id,
}
res = CLIENT.create_pull_request(**args)
我为forkSource
提供的嵌套字典是该库反复尝试的结果,它确实成功地创建了一个PR。但是,它创建的PR是将parent:master
合并到parent:master
,因此它没有用
我如何更改args
,以便它将child:master
的PR创建为parent:master
好的,我深入研究了文档,从
forkSource
开始。在链接到here然后here之后,很明显forkSource
必须这样表述:"forkSource": {"repository": {"id": child_repo_id}}
奇怪的是,DevOpsAPI忽略了嵌套的
repository
参数,而不是(最好)抛出错误。这一变化解决了问题,并创建了一个类似于我所追求的公关完整代码:
相关问题 更多 >
编程相关推荐