-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path__main__.py
More file actions
230 lines (190 loc) · 6.83 KB
/
__main__.py
File metadata and controls
230 lines (190 loc) · 6.83 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#! /usr/bin/env python3
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import argparse
import sys
from constants import (
PROJECTS_MOBILE,
PROJECTS_ECOSYSTEM,
PROJECTS_DESKTOP,
PROJECTS_SENTRY,
PLATFORMS,
REPORT_TYPES,
)
from handlers.bitrise import (
handle_bitrise_builds,
)
from handlers.bugzilla import (
handle_bugzilla_desktop_bugs,
handle_bugzilla_desktop_overall_bugs,
handle_bugzilla_desktop_release_flags_for_bugs,
handle_bugzilla_meta_bugs,
handle_bugzilla_qe_verify,
handle_bugzilla_query_by_keyword,
)
from handlers.confluence import (
handle_confluence_build_validation,
handle_confluence_updates,
)
from handlers.github import (
handle_github_issue_regression,
handle_github_issues,
)
from handlers.jira import (
handle_jira_qa_requests,
handle_jira_qa_needed,
handle_jira_softvision_worklogs,
handle_jira_qa_requests_desktop,
)
from handlers.sentry import (
handle_sentry_issues,
handle_sentry_rates,
)
from handlers.testrail import (
handle_testrail_test_plans_and_runs,
handle_testrail_test_results,
handle_testrail_milestones,
handle_testrail_users,
handle_testrail_test_case_coverage, handle_testrail_test_health,
# handle_testrail_test_run_counts_update,
)
def parse_args(cmdln_args):
parser = argparse.ArgumentParser(
description="Retrieve and update mobile project test data"
)
parser.add_argument(
"--project",
help="Indicate project",
required=False,
)
parser.add_argument(
"--platform",
help="Select the platform: Mobile, Ecosystem or Desktop",
required=False,
choices=PLATFORMS,
)
parser.add_argument(
"--report-type",
help="Indicate report type",
required=False,
choices=REPORT_TYPES
)
parser.add_argument(
"--num-days",
help="Indicate number of historic days of records to include",
required=False
)
parser.add_argument(
"--meta-bug-id",
help="Indicate Bugzilla metabug ID for bugzilla-meta-bugs",
required=False,
type=int,
)
parser.add_argument(
"--bz-keyword",
help="Indicate Bugzilla keyword for bugzilla-query-by-keyword",
required=False,
type=str,
)
return parser.parse_args(args=cmdln_args)
# Function to validate the project based on the platform
def validate_project(platform, project, report_type):
# Conditionally require --platform and --project
# if --report-type is 'test-case-coverage'
if report_type in ('test-case-coverage', 'testrail-milestones'):
if not project:
print("--project is required for the report selected")
if not platform:
print("--platform is required for the report selected")
if (report_type in ('sentry-issues', 'sentry-rates')
and project not in PROJECTS_SENTRY):
print(
f"Error: Invalid project '{project}' for Sentry reports. "
f"Valid options are {PROJECTS_SENTRY}"
)
sys.exit(1)
if (report_type == 'github-issues'
and project not in PROJECTS_MOBILE):
print(
f"Error: Invalid project '{project}' for GitHub new bugs report. "
f"Valid options are {PROJECTS_MOBILE}"
)
sys.exit(1)
if platform == 'mobile' and project not in PROJECTS_MOBILE:
print(
f"Error: Invalid project '{project}' for mobile. "
f"Valid options are {PROJECTS_MOBILE}"
)
sys.exit(1)
elif platform == 'desktop' and project not in PROJECTS_DESKTOP:
print(
f"Error: Invalid project '{project}' for desktop. "
f"Valid options are {PROJECTS_DESKTOP}"
)
sys.exit(1)
elif platform == 'ecosystem' and project not in PROJECTS_ECOSYSTEM:
print(
f"Error: Invalid project '{project}' for ecosystem. "
f"Valid options are {PROJECTS_ECOSYSTEM}"
)
sys.exit(1)
def expand_project_args(platform, projects):
projects_list = []
platform = (platform or "").lower()
projects = (projects or "").lower()
if isinstance(projects, str):
if projects == 'all':
if platform == 'desktop':
for project in PROJECTS_DESKTOP[:-1]:
projects_list.append(project)
if platform == 'mobile':
for project in PROJECTS_MOBILE[:-1]:
projects_list.append(project)
if platform == 'ecosystem':
for project in PROJECTS_ECOSYSTEM[:-1]:
projects_list.append(project)
else:
projects_list = [projects]
return projects_list
# === DISPATCH MAP ===
COMMAND_MAP = {
'bitrise-builds': handle_bitrise_builds,
'bugzilla-desktop-bugs': handle_bugzilla_desktop_bugs,
'bugzilla-desktop-overall-bugs': handle_bugzilla_desktop_overall_bugs,
'bugzilla-desktop-release-flags-for-bugs': handle_bugzilla_desktop_release_flags_for_bugs, # noqa
'bugzilla-meta-bugs': handle_bugzilla_meta_bugs,
'bugzilla-qe-verify': handle_bugzilla_qe_verify,
'bugzilla-query-by-keyword': handle_bugzilla_query_by_keyword,
'confluence-updates': handle_confluence_updates,
'confluence-build-validation': handle_confluence_build_validation,
'github-issue-regression': handle_github_issue_regression,
'github-issues': handle_github_issues,
'jira-qa-needed': handle_jira_qa_needed,
'jira-qa-requests': handle_jira_qa_requests,
'jira-qa-requests-desktop': handle_jira_qa_requests_desktop,
'jira-softvision-worklogs': handle_jira_softvision_worklogs,
'sentry-issues': handle_sentry_issues,
'sentry-rates': handle_sentry_rates,
'testrail-milestones': handle_testrail_milestones,
'testrail-users': handle_testrail_users,
'testrail-test-health': handle_testrail_test_health,
'testrail-test-case-coverage': handle_testrail_test_case_coverage,
# 'testrail-test-run-counts': handle_testrail_test_run_counts_update,
'testrail-test-plans-and-runs': handle_testrail_test_plans_and_runs,
'testrail-test-results': handle_testrail_test_results,
}
def main():
args = parse_args(sys.argv[1:])
args.arg_list = expand_project_args(args.platform, args.project)
report_type = args.report_type
# DIAGNOSTIC
print(f"args: {args}")
print(f"args.report_type: {args.report_type}")
print(f"args.arg_list: {args.arg_list}")
if report_type not in COMMAND_MAP:
sys.exit(f"Unknown or unsupported report type: {report_type}")
validate_project(args.platform, args.project, report_type)
COMMAND_MAP[report_type](args)
if __name__ == "__main__":
main()