我正在尝试使用以下API将文件添加到respos文件夹中:
ado_req_headers_ATT = {'Content-Type':'application/octet-stream'}
Get_Branch_url = str(organization_url)+str('/_apis/git/repositories/')+str(ReposID)+str('/refs?filter=heads/&api-version=6.0')
print(Get_Branch_url)
Get_Branch_Details = requests.get(url=Get_Branch_url,headers=ado_req_headers_ATT,auth=('',ADO_AUTH_PAT))
#print(Get_Branch_Details.status_code)
print(Get_Branch_Details.text)
Get_Branch_Details=Get_Branch_Details.json()
for item in Get_Branch_Details["value"]:
if item["name"] == **'refs/heads/XXX'**:
old_object_ID = item["objectId"]
old_object_name= item["name"]
print(old_object_name,":-",old_object_ID) **## Prints refs/heads/XXX : YYYYYYYYYYYYYYYYYYYYYY**
对上述url的响应包括:
{
"value": [
{...
**"name": "refs/heads/XXX",
"objectId": "YYYYYYYYYYYYYYYYYYYYYY",**
"creator": {
"displayName": "AAAAAAAAAA",
"url": "https://spsprodsin1.vssps.visualstudio.com/UUUUUU",
"_links": {
"avatar": {
"href": "https://dev.azure.com/TTTTTT"
}
},
"id": "MMMMMMMMM",
"uniqueName": "PPPPPPPP",
并将此对象ID:yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
###### Push a File in Ref_Devops-dev ###############################
ado_req_headers_ATT = {"Content-Type":"application/json-patch+json"}
push_file_url = str(organization_url)+str('/_apis/git/repositories/')+str(ReposID)+str('/pushes?api-version=6.0')
Body_data = {"refUpdates": [{"name": refs/heads/XXX,"oldObjectId":YYYYYYYYYYYYYYYYYYYYYY}],"commits":[{"comment": "Added text file.","changes":[{"changeType": "add","item": {"path":"/test.txt"},"newContent": {"content": "# Tasks\n\n* Item 1\n* Item 2","contentType": "rawtext"}}]}]}
Body_data = json.dumps(Body_data)
print(Body_data)
Push_file= requests.post(url=push_file_url,headers=ado_req_headers_ATT,data=Body_data,auth=('',ADO_AUTH_PAT))
print(Push_file.json())
print(Push_file.status_code)
print(Push_file.text)
但答复是:
{"$id":"1","innerException":null,"message":"TF401035: The object 'YYYYYYYYYYYYYYYYYYYYYY' does not exist.","typeName":"Microsoft.TeamFoundation.Git.Server.GitObjectDoesNotExistException, Microsoft.TeamFoundation.Git.Server","typeKey":"GitObjectDoesNotExistException","errorCode":0,"eventId":3000}
肯定错过了最后一步&;基本的。有什么建议吗
可以通过引用提交API而不是上述API来消除上述错误&;获取最新的提交ID
相关问题 更多 >
编程相关推荐