Skip to content

Commit ed3c555

Browse files
author
admin
committed
added apps count for bamboo
1 parent f965821 commit ed3c555

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]:
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
@@ -336,6 +336,36 @@ def __build_plans_count(self):
336336
def dataset_information(self):
337337
return f"{self.__build_plans_count()} build plans"
338338

339+
@property
340+
def apps_count(self):
341+
return len(self.__get_apps)
342+
343+
@cached_property
344+
def __get_apps(self):
345+
try:
346+
return self.client.get_installed_apps()
347+
except Exception as e:
348+
print(f'ERROR: Could not get the installed applications. Error: {e}')
349+
return []
350+
351+
@cached_property
352+
def __get_custom_apps(self):
353+
all_apps = self.__get_apps
354+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
355+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
356+
app['vendor']['name'] and app['userInstalled'] == True]
357+
return non_atlassian_apps
358+
359+
@property
360+
def custom_app_count(self):
361+
return len(self.__get_custom_apps)
362+
363+
@property
364+
def custom_app_count_enabled(self):
365+
non_atlassian_apps = self.__get_custom_apps
366+
non_atlassian_apps_enabled = [app for app in non_atlassian_apps if app['enabled'] == True]
367+
return len(non_atlassian_apps_enabled)
368+
339369

340370
class Insight(Jsm):
341371
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)