使用 Python 推送创建 Api 将文件上传/推送到 Azure Devops Repo 时如何查找 oldobjectid
The oldobjectid
is the 最新提交 ID在 Azure Devops Repo 的当前分支上。
为了得到oldObjectId
(最新提交 ID),我们可以使用 REST API推送 - 列表 https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pushes/list?view=azure-devops-rest-6.0带 URI 参数top=1
and searchCriteria.refName=refs/heads/master
:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pushes?&$top=1&searchCriteria.refName=refs/heads/master&api-version=6.0
现在,我们得到pushId
,我们可以使用 REST API推送 - 获取 https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pushes/get?view=azure-devops-rest-6.0得到commitId
:
然后,我们可以使用 REST API Pushes - Create with request body:
{
"refUpdates": [
{
"name": "refs/heads/master",
"oldObjectId": "e71544e80870e83cfd3eb3a797eda9c6227c66a7"
}
],
"commits": [
{
"comment": "Added task markdown file.",
"changes": [
{
"changeType": "add",
"item": {
"path": "/tasks.md"
},
"newContent": {
"content": "# Tasks\n\n* Item 1\n* Item 2",
"contentType": "rawtext"
}
}
]
}
]
}
测试结果: