@@ -1307,6 +1307,105 @@ def disable_repo_hook_settings(self, project_key, repository_slug, hook_key):
13071307 url = "{}/{}/enabled" .format (self ._url_repo_hook_settings (project_key , repository_slug ), hook_key )
13081308 return self .delete (url )
13091309
1310+ def _url_webhooks (self , project_key , repository_slug ):
1311+ return "{}/webhooks" .format (self ._url_repo (project_key , repository_slug ))
1312+
1313+ def get_webhooks (
1314+ self ,
1315+ project_key ,
1316+ repository_slug ,
1317+ event = None ,
1318+ statistics = False ,
1319+ ):
1320+ """
1321+ Get webhooks
1322+ :param project_key:
1323+ :param repository_slug:
1324+ :param event: OPTIONAL: defaults to None
1325+ :param statistics: OPTIONAL: defaults to False
1326+ :return:
1327+ """
1328+ url = self ._url_webhooks (project_key , repository_slug )
1329+ params = {}
1330+ if event :
1331+ params ["event" ] = event
1332+ if statistics :
1333+ params ["statistics" ] = statistics
1334+ return self ._get_paged (url , params = params )
1335+
1336+ def create_webhook (
1337+ self ,
1338+ project_key ,
1339+ repository_slug ,
1340+ name ,
1341+ events ,
1342+ webhook_url ,
1343+ active ,
1344+ secret = None ,
1345+ ):
1346+ """Creates a webhook using the information provided in the request.
1347+
1348+ The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.
1349+
1350+ :param project_key: The project matching the projectKey supplied in the resource path as shown in URL.
1351+ :param repository_slug:
1352+ :param name: Name of webhook to create.
1353+ :param events: List of event. (i.e. ["repo:refs_changed", "pr:merged", "pr:opened"])
1354+ :param webhook_url:
1355+ :param active:
1356+ :param secret: The string is used to verify data integrity between Bitbucket and your endpoint.
1357+ :return:
1358+ """
1359+ url = self ._url_webhooks (project_key , repository_slug )
1360+ body = {
1361+ "name" : name ,
1362+ "events" : events ,
1363+ "url" : webhook_url ,
1364+ "active" : active ,
1365+ }
1366+ if secret :
1367+ body ["configuration" ] = {"secret" : secret }
1368+ return self .post (url , data = body )
1369+
1370+ def _url_webhook (self , project_key , repository_slug , webhook_id ):
1371+ return "{}/{}" .format (self ._url_webhooks (project_key , repository_slug ), webhook_id )
1372+
1373+ def get_webhook (self , project_key , repository_slug , webhook_id ):
1374+ """
1375+ Retrieve a webhook.
1376+ The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.
1377+ :param project_key:
1378+ :param repository_slug:
1379+ :param webhook_id: the ID of the webhook within the repository
1380+ :return:
1381+ """
1382+ url = self ._url_webhook (project_key , repository_slug , webhook_id )
1383+ return self .get (url )
1384+
1385+ def update_webhook (self , project_key , repository_slug , webhook_id , ** params ):
1386+ """
1387+ Update a webhook.
1388+ The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.
1389+ :param project_key:
1390+ :param repository_slug:
1391+ :param webhook_id: the ID of the webhook within the repository
1392+ :return:
1393+ """
1394+ url = self ._url_webhook (project_key , repository_slug , webhook_id )
1395+ return self .put (url , data = params )
1396+
1397+ def delete_webhook (self , project_key , repository_slug , webhook_id ):
1398+ """
1399+ Delete a webhook.
1400+ The authenticated user must have REPO_ADMIN permission for the context repository to call this resource.
1401+ :param project_key:
1402+ :param repository_slug:
1403+ :param webhook_id: the ID of the webhook within the repository
1404+ :return:
1405+ """
1406+ url = self ._url_webhook (project_key , repository_slug , webhook_id )
1407+ return self .delete (url )
1408+
13101409 def _url_pull_request_settings (self , project_key , repository_slug ):
13111410 return "{}/settings/pull-requests" .format (self ._url_repo (project_key , repository_slug ))
13121411
0 commit comments