所以我有了这个repo:https://bitbucket.com/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/这个URL输出了很多关于存储库的信息

然后,我尝试创建一个Python脚本,该脚本专门处理以下URL信息:
import requests
headers = {
'Content-Type': 'application/json',
}
response = requests.get('https://bitbucket.com/rest/api/1.0/projects/GGT/repos/GRP1/', headers=headers, auth=('USERNAME', 'TOKEN'))
print(response.text)这将打印出相同的JSON内容,如图所示。
现在我知道我有一个到存储库的连接。然后,我想在这个回购中添加一个Web钩子,但我似乎找不出如何做到这一点。
我试着做这样的事,但那行不通。
json_data = {
'title': 'BitBucket_Webhook',
'url': 'http://uua231z:5000/bitbucket',
'enabled': 'true',
}
response = requests.put('https://bitbucket.com/rest/webhook/1.0/projects/GGT/repos/GRP1/configurations', headers=headers, json=json_data, auth=('USERNAME', 'TOKEN'))
print(response)我怎么能添加一个网络钩子到一个存储库,似乎找不到那么多在互联网上,这是如何可能的?
--我从评论中尝试了这一点
headers = {
# Already added when you pass json= but not when you pass data=
# 'Content-Type': 'application/json',
}
json_data = {
'title': 'BitBucket_Webhook2',
'url': 'http://test123:5000/bitbucket',
'enabled': 'true',
}
# Found here: https://docs.atlassian.com/bitbucket-server/rest/4.1.0/bitbucket-rest.html
response = requests.put('https://bitbucket.com/rest/api/1.0/projects/GGT/repos/grp1/webhooks', headers=headers, json=json_data, auth=('USERNAME', 'TOKEN'))
print(response)但我得到了<Response [405]>
发布于 2022-09-12 07:57:13
您可能想要查看官方的API文档以获得API。有一个HTTP (POST) /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/webhooks可以解决您的需求。
https://stackoverflow.com/questions/73685931
复制相似问题