Skip to content

Commit 9ba52ba

Browse files
Merge pull request #1785 from atlassian/crowd-apps-count
added crowd apps count calculation
2 parents a4f167e + 789c4ec commit 9ba52ba

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

app/util/analytics/analytics_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ 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]:
110+
if collector.app_type in [JIRA, JSM, CONFLUENCE, BITBUCKET, CROWD]:
111111
summary_report.append(f'Applications count|{collector.apps_count}')
112112
summary_report.append(f'Custom applications count|{collector.custom_apps_count}')
113113
summary_report.append(f'Custom applications count enabled|{collector.custom_apps_count_enabled}')

app/util/analytics/application_info.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,36 @@ def __users_count(self):
315315
def dataset_information(self):
316316
return f"{self.__users_count()} users"
317317

318+
@property
319+
def apps_count(self):
320+
return len(self.__get_apps)
321+
322+
@cached_property
323+
def __get_apps(self):
324+
try:
325+
return self.client.get_installed_apps()
326+
except Exception as e:
327+
print(f'ERROR: Could not get the installed applications. Error: {e}')
328+
return []
329+
330+
@cached_property
331+
def __get_custom_apps(self):
332+
all_apps = self.__get_apps
333+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
334+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
335+
app['vendor']['name'] and app['userInstalled'] == True]
336+
return non_atlassian_apps
337+
338+
@property
339+
def custom_app_count(self):
340+
return len(self.__get_custom_apps)
341+
342+
@property
343+
def custom_app_count_enabled(self):
344+
non_atlassian_apps = self.__get_custom_apps
345+
non_atlassian_apps_enabled = [app for app in non_atlassian_apps if app['enabled'] == True]
346+
return len(non_atlassian_apps_enabled)
347+
318348

319349
class Bamboo(BaseApplication):
320350
type = BAMBOO

app/util/api/crowd_clients.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,9 @@ def get_status(self):
108108
else:
109109
print(f"Warning: failed to get {api_url}: Error: {e}")
110110
return False
111+
112+
def get_installed_apps(self):
113+
api_url = f'{self.host}/rest/plugins/1.0/'
114+
r = self.get(api_url, error_msg="ERROR: Could not get installed plugins.",
115+
headers={'X-Atlassian-Token': 'no-check'})
116+
return r.json()['plugins']

app/util/data_preparation/crowd_prepare_data.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ def write_test_data_to_files(dataset):
4040
__write_to_file(CROWD_USERS, users)
4141

4242

43+
def __check_number_of_custom_app(client):
44+
try:
45+
all_apps = client.get_installed_apps()
46+
apps_with_vendor_defined = [app for app in all_apps if 'vendor' in app]
47+
non_atlassian_apps = [app for app in apps_with_vendor_defined if 'Atlassian' not in
48+
app['vendor']['name'] and app['userInstalled'] == True]
49+
non_atlassian_apps_names = [app['name'] for app in non_atlassian_apps]
50+
print(f"Custom application count: {len(non_atlassian_apps)}")
51+
if non_atlassian_apps:
52+
print(f'Custom app names:')
53+
print(*non_atlassian_apps_names, sep='\n')
54+
except Exception as e:
55+
print(f'ERROR: Could not get the installed applications. Error: {e}')
56+
57+
4358
def main():
4459
print("Started preparing data")
4560

@@ -48,9 +63,11 @@ def main():
4863

4964
client = CrowdRestClient(url, CROWD_SETTINGS.application_name,
5065
CROWD_SETTINGS.application_password, verify=CROWD_SETTINGS.secure)
51-
66+
crowd_admin_client = CrowdRestClient(url, CROWD_SETTINGS.admin_login,
67+
CROWD_SETTINGS.admin_password, verify=CROWD_SETTINGS.secure)
5268
dataset = __create_data_set(client)
5369
write_test_data_to_files(dataset)
70+
__check_number_of_custom_app(crowd_admin_client)
5471

5572
print("Finished preparing data")
5673

0 commit comments

Comments
 (0)