gpt4 book ai didi

python - 使用 Pushes Create Api with Python 将文件上传/推送到 Azure Devops Repo 时如何查找 oldobjectid

转载 作者:行者123 更新时间:2023-12-05 02:02:13 24 4
gpt4 key购买 nike

我试图自动执行将一些文件推送到存储库中的各个文件夹的任务。我尝试使用 azure 提供的 Rest API。当使用 Pushes Create API 时,从文档中这是请求正文中的内容

请求正文快照:

这是我不知道如何进入 python 脚本的具体内容"oldObjectId": "8b67126d2500e28c771f82c9ddc292679978197c"

我知道我必须使用 python 请求库发送一个包含与上述类似的数据的 JSON 变量。但我不知道如何在 python 脚本中获取 oldobjectid。我尝试到处寻找(文档、stackoverflow ....),但无法找到我们如何找到 oldobjectid。

api 文档的链接

最佳答案

How to find oldobjectid when Uploading/pushing a file to Azure Devops Repo using Pushes Create Api with Python

oldobjectid 是 Azure Devops Repo 当前分支上的最新提交 ID

要获取 oldObjectId(最新提交 ID),我们可以使用 REST API Pushes - List使用 URI 参数 top=1searchCriteria.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

enter image description here

现在,我们得到了 pushId,我们可以使用 REST API Pushes - Get获取 commitId:

enter image description here

然后,我们可以使用 REST API 推送 - 使用请求主体创建:

{
"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"
}
}
]
}
]
}

测试结果:

enter image description here

关于python - 使用 Pushes Create Api with Python 将文件上传/推送到 Azure Devops Repo 时如何查找 oldobjectid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66014038/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com