Skip to content

Commit 6746498

Browse files
Merge pull request #1786 from atlassian/bamboo-apps-count
added apps count for bamboo calculation
2 parents 9ba52ba + 88fec56 commit 6746498

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

app/util/analytics/analytics_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ def generate_report_summary(collector):
107107
summary_report.append(f'Success|{success}')
108108
summary_report.append(f'Has app-specific actions|{bool(collector.app_specific_rates)}')
109109

110-
if collector.app_type in [JIRA, JSM, CONFLUENCE, BITBUCKET, CROWD]:
111-
summary_report.append(f'Applications count|{collector.apps_count}')
112-
summary_report.append(f'Custom applications count|{collector.custom_apps_count}')
113-
summary_report.append(f'Custom applications count enabled|{collector.custom_apps_count_enabled}')
110+
111+
summary_report.append(f'Applications count|{collector.apps_count}')
112+
summary_report.append(f'Custom applications count|{collector.custom_apps_count}')
113+
summary_report.append(f'Custom applications count enabled|{collector.custom_apps_count_enabled}')
114114

115115
if collector.app_type == JSM:
116116
insight = collector.insight

app/util/analytics/application_info.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,36 @@ def __build_plans_count(self):
366366
def dataset_information(self):
367367
return f"{self.__build_plans_count()} build plans"
368368

369+
@property
370+
def apps_count(self):
371+
return len(self.__get_apps)
372+
373+
@cached_property
374+
def __get_apps(self):
375+
try:
376+
return self.client.get_installed_apps()
377+
except Exception as e:
378+
print(f'ERROR: Could not get the installed applications. Error: {e}')
379+
return []
380+
381+
@cached_property
382+
def __get_custom_apps(self):
383+
all_apps = self.__get_apps
384+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
385+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
386+
app['vendor']['name'] and app['userInstalled'] == True]
387+
return non_atlassian_apps
388+
389+
@property
390+
def custom_app_count(self):
391+
return len(self.__get_custom_apps)
392+
393+
@property
394+
def custom_app_count_enabled(self):
395+
non_atlassian_apps = self.__get_custom_apps
396+
non_atlassian_apps_enabled = [app for app in non_atlassian_apps if app['enabled'] == True]
397+
return len(non_atlassian_apps_enabled)
398+
369399

370400
class Insight(Jsm):
371401
type = INSIGHT

app/util/api/bamboo_clients.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,9 @@ def get_status(self):
246246
else:
247247
print(f"Warning: failed to get {api_url}: Error: {e}")
248248
return False
249+
250+
def get_installed_apps(self):
251+
api_url = f'{self.host}/rest/plugins/1.0/'
252+
r = self.get(api_url, error_msg="ERROR: Could not get installed plugins.",
253+
headers={'X-Atlassian-Token': 'no-check'})
254+
return r.json()['plugins']

app/util/data_preparation/bamboo_prepare_data.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ def write_test_data_to_files(dataset):
7575
__write_to_file(BAMBOO_USERS, users)
7676

7777

78+
def __check_number_of_custom_app(client):
79+
try:
80+
all_apps = client.get_installed_apps()
81+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
82+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
83+
app['vendor']['name'] and app['userInstalled'] == True]
84+
non_atlassian_apps_names = [app['name'] for app in non_atlassian_apps]
85+
print(f"Custom application count: {len(non_atlassian_apps)}")
86+
if non_atlassian_apps:
87+
print(f'Custom app names:')
88+
print(*non_atlassian_apps_names, sep='\n')
89+
except Exception as e:
90+
print(f'ERROR: Could not get the installed applications. Error: {e}')
91+
92+
7893
def main():
7994
print("Started preparing data")
8095
verify_agents_plans_setup()
@@ -84,7 +99,7 @@ def main():
8499

85100
client = BambooClient(url, BAMBOO_SETTINGS.admin_login, BAMBOO_SETTINGS.admin_password,
86101
verify=BAMBOO_SETTINGS.secure)
87-
102+
__check_number_of_custom_app(client)
88103
dataset = __create_dataset(client)
89104
write_test_data_to_files(dataset)
90105
assert_number_of_agents(client)

0 commit comments

Comments
 (0)