我正在尝试更新test.json
文件托管在 Azure DevOps Repo 上。我正在使用逻辑应用程序。无法从文档中识别操作顺序。
我想我需要...
-
向以下地址发出 GET HTTP 请求Items端点: https://learn.microsoft.com/en-us/rest/api/azure/devops/git/items/get?view=azure-devops-rest-6.0#get-metadata
https://dev.azure.com/myOrg/myProject/_apis/git/repositories/myRepoID/items?scopePath=/data/test.json&$format=json&api-version=6.0
- 回复:
{
"count": 1,
"value": [
{
"objectId": "<longGUID>",
"gitObjectType": "blob",
"commitId": "<longGUID>",
"path": "/data/test.json",
"url": "https://dev.azure.com/myOrg/longGUID/_apis/git/repositories/myRepoID/items?path=%2Fdata%2Ftest.json&versionType=Branch&versionOptions=None"
}
]
}
-
Use the objectId
在响应中发出 POST HTTP 请求Pushes终点 https://learn.microsoft.com/en-us/rest/api/azure/devops/git/pushes/create?view=azure-devops-rest-6.0#add-a-binary-file
{
"refUpdates": [
{
"name": "refs/heads/main",
"oldObjectId": "<longGuid from previous response>"
}
],
"commits": [
{
"changes": [
{
"changeType": "edit",
"item": {
"path": "/data/test.json"
},
"newContent": {
"content": "CHECK CHECK!",
"contentType": "rawtext"
}
}
],
"comment": "My commit message"
}
]
}
Error:
{
"$id": "1",
"innerException": null,
"message": "TF401028: The reference 'refs/heads/main' has already been updated by another client, so you cannot update it. Please try again.",
"typeName": "Microsoft.TeamFoundation.Git.Server.GitReferenceStaleException, Microsoft.TeamFoundation.Git.Server",
"typeKey": "GitReferenceStaleException",
"errorCode": 0,
"eventId": 3000
}
问题:
- 我的操作顺序正确吗?
- 我该如何克服这个问题?
FIX:(谢谢@Leo_Liu-MSFT)
-
获取请求至https://dev.azure.com/myOrg/myProject/_apis/git/repositories/repoID/commits?searchCriteria.$top=1&searchCriteria.itemVersion.version=main&api-version=6.0
-
将请求发送至https://dev.azure.com/myOrg/myProject/_apis/git/repositories/repoID/pushes
{
"commits": [
{
"changes": [
{
"changeType": "edit",
"item": {
"path": "<Your File To Update>"
},
"newContent": {
"content": "CHECK CHECK!",
"contentType": "rawtext"
}
}
],
"comment": "<YOUR COMMIT MSG>"
}
],
"refUpdates": [
{
"name": "refs/heads/main",
"oldObjectId": "<commitId from previous response>"
}
]
}