-
Notifications
You must be signed in to change notification settings - Fork 0
/
sonar_qube.py
55 lines (49 loc) · 1.9 KB
/
sonar_qube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Utilities for configuring the Bitbucket SonarQube plugin.
"""
import requests
from utils import log
class SonarQube:
"""Utilities for configuring the Bitbucket SonarQube plugin."""
__sonar_qube_project_data__ = {
'project': {
'analysisMode': 'BRANCH_DIFF',
'showOnlyNewOrChangedLines': True,
'illegalBranchCharReplacement': '',
'pullRequestBranch': '',
'projectCleanupEnabled': False,
'forkCleanupEnabled': False
}
}
__sonar_qube_repo_data__ = {
'project': {
'sonarEnabled': True,
'inheritFromProject': True,
'serverConfigId': 1,
'masterProjectKey': '',
'projectBaseKey': '',
'analysisMode': 'BRANCH_DIFF'
}
}
@log
def configure_for_project(self, **kwargs):
"""Configures the SonarQube plugin for this project."""
bitbucket = kwargs.get('bitbucket')
data = self.__sonar_qube_project_data__
url = f"http://{bitbucket.get('host')}/rest/sonar4stash/1.0"
url += f"/projects/{bitbucket.get('project')}/settings"
return requests.request(
'POST', url, headers=kwargs.get('default_headers'), json=data)
@log
def configure(self, project_base_key, **kwargs):
"""Configures the SonarQube plugin for this repo."""
bitbucket = kwargs.get('bitbucket')
data = self.__sonar_qube_repo_data__
key = f"{project_base_key}:{bitbucket.get('repo')}"
data['project']['masterProjectKey'] = f"{key}:master"
data['project']['projectBaseKey'] = key
url = f"http://{bitbucket.get('host')}/rest/sonar4stash/1.0"
url += f"/projects/{bitbucket.get('project')}"
url += f"/repos/{bitbucket.get('repo')}/settings"
return requests.request(
'POST', url, headers=kwargs.get('default_headers'), json=data)