Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3f4530

Browse files
author
altflg
authored
Add support for getting audit log (atlassian-api#768)
1 parent 649c991 commit b3f4530

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

atlassian/bitbucket/__init__.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,28 @@ def delete_project_condition(self, project_key, id_condition):
589589
url = self._url_project_condition(project_key, id_condition)
590590
return self.delete(url) or {}
591591

592+
def _url_project_audit_log(self, project_key):
593+
if self.cloud:
594+
raise Exception("Not supported in Bitbucket Cloud")
595+
596+
return "{}/events".format(self._url_project(project_key, api_root="rest/audit"))
597+
598+
def get_project_audit_log(self, project_key, start=0, limit=None):
599+
"""
600+
Get the audit log of the project
601+
:param start:
602+
:param limit:
603+
:param project_key: The project key
604+
:return: List of events of the audit log
605+
"""
606+
url = self._url_project_audit_log(project_key)
607+
params = {}
608+
if start:
609+
params["start"] = start
610+
if limit:
611+
params["limit"] = limit
612+
return self._get_paged(url, params=params)
613+
592614
def _url_repos(self, project_key, api_root=None, api_version=None):
593615
return "{}/repos".format(self._url_project(project_key, api_root, api_version))
594616

@@ -923,6 +945,29 @@ def set_repo_label(self, project_key, repository_slug, label_name):
923945
data = {"name": label_name}
924946
return self.post(url, data=data)
925947

948+
def _url_repo_audit_log(self, project_key, repository_slug):
949+
if self.cloud:
950+
raise Exception("Not supported in Bitbucket Cloud")
951+
952+
return "{}/events".format(self._url_repo(project_key, repository_slug, api_root="rest/audit"))
953+
954+
def get_repo_audit_log(self, project_key, repository_slug, start=0, limit=None):
955+
"""
956+
Get the audit log of the repository
957+
:param start:
958+
:param limit:
959+
:param project_key: Key of the project you wish to look in.
960+
:param repository_slug: url-compatible repository identifier
961+
:return: List of events of the audit log
962+
"""
963+
url = self._url_repo_audit_log(project_key, repository_slug)
964+
params = {}
965+
if start:
966+
params["start"] = start
967+
if limit:
968+
params["limit"] = limit
969+
return self._get_paged(url, params=params)
970+
926971
def _url_repo_branches(self, project_key, repository_slug, api_root=None):
927972
return "{}/branches".format(self._url_repo(project_key, repository_slug, api_root=api_root))
928973

0 commit comments

Comments
 (0)