![](/img/trans.png)
[英]add POST HOOK to a bitbucket repository using their REST API and python-requests
[英]BitBucket Rest API, change repository settings
所以我有這個倉庫: 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 內容,如圖所示。
現在我知道我與存儲庫有連接。 然后我想向這個 repo 添加一個 Webhook,但我似乎無法找到如何做到這一點。
我試圖做這樣的事情,但這不起作用。
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)
如何將 webhook 添加到存儲庫中,似乎無法在互聯網上找到太多關於這如何可能的信息?
我從評論中嘗試了這個
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]>
您可能需要查看 API 的官方 Atlassian 文檔。 有這個 HTTP (POST) /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/webhooks可以解決您的需求。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.