Skip to content

Commit 1d82c75

Browse files
[BITBUCKET] Add support for Code Insights annotations (atlassian-api#786)
* [BITBUCKET] Add support for Code Insights annotations This commit will allow users to extend Code Insight reports with additional code annotations. * fixup! [BITBUCKET] Add support for Code Insights annotations * fixup! [BITBUCKET] Add support for Code Insights annotations
1 parent 9ea1079 commit 1d82c75

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

atlassian/bitbucket/__init__.py

+27
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,33 @@ def get_changelog(self, project_key, repository_slug, ref_from, ref_to, start=0,
18171817
params["limit"] = limit
18181818
return self._get_paged(url, params=params)
18191819

1820+
def _url_code_insights_annotations(self, project_key, repository_slug, commit_id, report_key):
1821+
return "{}/reports/{}/annotations".format(
1822+
self._url_commit(
1823+
project_key,
1824+
repository_slug,
1825+
commit_id,
1826+
api_root="rest/insights",
1827+
api_version="1.0",
1828+
),
1829+
report_key,
1830+
)
1831+
1832+
def add_code_insights_annotations_to_report(self, project_key, repository_slug, commit_id, report_key, annotations):
1833+
"""
1834+
Adds annotations to an existing insight report.
1835+
For further information visit:
1836+
https://docs.atlassian.com/bitbucket-server/rest/6.6.1/bitbucket-code-insights-rest.html
1837+
:project_key: str
1838+
:repository_slug: str
1839+
:commit_id: str
1840+
:report_key: str
1841+
:annotations: list
1842+
"""
1843+
url = self._url_code_insights_annotations(project_key, repository_slug, commit_id, report_key)
1844+
data = {"annotations": annotations}
1845+
return self.post(url, data=data)
1846+
18201847
def _url_code_insights_report(self, project_key, repository_slug, commit_id, report_key):
18211848
return "{}/reports/{}".format(
18221849
self._url_commit(

docs/bitbucket.rst

+36
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,42 @@ Manage repositories
9898
# Delete a repository (DANGER!)
9999
bitbucket.delete_repo(project_key, repository_slug)
100100
101+
Manage Code Insights
102+
--------------------
103+
104+
.. code-block:: python
105+
106+
# Delete an existing Code Insights report
107+
bitbucket.delete_code_insights_report(project_key, repository_slug, commit_hash, report_key)
108+
109+
# Create a new Code Insights report
110+
report = {
111+
'details': 'This is an example report',
112+
'result': 'FAIL',
113+
'reporter': 'Anonymous',
114+
'link': 'http://some-url',
115+
'logo-url': 'http://some-url',
116+
'data': [
117+
{
118+
'title': 'Example coverage',
119+
'type': 'PERCENTAGE',
120+
'value': 85
121+
}
122+
]
123+
}
124+
bitbucket.create_code_insights_report(project_key, repository_slug, commit_hash, report_key, 'Code Insights Report', **report)
125+
126+
# Add annotations to a Code Insights report
127+
annotations = [
128+
{
129+
'path': 'some/path/to/file',
130+
'line': 32,
131+
'message': 'Roses are red, Violets are blue, Unexpected { on line 32',
132+
'severity': 'MEDIUM'
133+
}
134+
]
135+
bitbucket.add_code_insights_annotations_to_report(project_key, repository_slug, commit_hash, report_key, **annotations)
136+
101137
Groups and admins
102138
-----------------
103139

0 commit comments

Comments
 (0)