Skip to content

Commit a5d16a8

Browse files
committed
Add TR milestone support
1 parent fd6f354 commit a5d16a8

File tree

4 files changed

+61
-16
lines changed

4 files changed

+61
-16
lines changed

__main__.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import argparse
22
import sys
33

4-
from bugz import BugzillaClient
5-
from github import GithubClient
6-
from jira import JiraClient
4+
#from bugz import BugzillaClient
5+
#from github import GithubClient
6+
#from jira import JiraClient
77
from testrail import TestRailClient
88
from utils.constants import PROJECTS_MOBILE, PROJECTS_ECOSYSTEM, PLATFORM, REPORT_TYPES # noqa
99

@@ -29,7 +29,7 @@ def parse_args(cmdln_args):
2929
parser.add_argument(
3030
"--report-type",
3131
help="Indicate report type",
32-
required=True,
32+
required=False,
3333
choices=REPORT_TYPES
3434
)
3535

@@ -46,7 +46,8 @@ def parse_args(cmdln_args):
4646
def validate_project(platform, project, report_type):
4747
# Conditionally require --platform and --project
4848
# if --report-type is 'test-case-coverage'
49-
if report_type == 'test-case-coverage':
49+
# if report_type == 'test-case-coverage':
50+
if report_type in ('test-case-coverage', 'milestones'):
5051
if not project:
5152
print("--project is required for the report selected")
5253
if not platform:
@@ -63,7 +64,7 @@ def validate_project(platform, project, report_type):
6364
def main():
6465
args = parse_args(sys.argv[1:])
6566
validate_project(args.platform, args.project, args.report_type)
66-
67+
6768
if args.report_type == 'test-case-coverage':
6869
h = TestRailClient()
6970
h.data_pump(args.project.lower())
@@ -74,10 +75,15 @@ def main():
7475
else:
7576
num_days = ''
7677
h.testrail_run_counts_update(args.project, num_days)
78+
if args.report_type == 'milestones':
79+
h = TestRailClient()
80+
h.test_rail_milestones('59')
81+
'''
7782
if args.report_type == 'issue-regression':
7883
h = GithubClient()
7984
h.github_issue_regression(args.project)
8085
h = GithubClient()
86+
8187
if args.report_type == 'jira-qa-requests':
8288
h = JiraClient()
8389
h.jira_qa_requests()
@@ -87,7 +93,7 @@ def main():
8793
if args.report_type == 'bugzilla-qe-verify':
8894
h = BugzillaClient()
8995
h.bugzilla_qe_verify()
90-
96+
'''
9197

9298
if __name__ == '__main__':
9399
main()

lib/testrail_conn.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def __send_request(self, method, uri, data):
8484
while True:
8585
response = requests.get(f"{url}&limit={limit}&offset={offset}", headers=headers)
8686
data = response.json()
87+
print(data)
8788

8889
# Check if 'cases' key exists in the response
8990
if 'cases' in data:
@@ -92,6 +93,12 @@ def __send_request(self, method, uri, data):
9293
# Break if fewer items are returned than the limit, indicating the last page
9394
if len(data['cases']) < limit:
9495
break
96+
if 'milestones' in data:
97+
all_items.extend(data['milestones'])
98+
99+
# Break if fewer items are returned than the limit, indicating the last page
100+
if len(data['milestones']) < limit:
101+
break
95102
else:
96103
all_items = data
97104
break # If 'cases' key is not present, exit the loop

testrail.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import pandas as pd
55

66
from lib.testrail_conn import APIClient
7+
'''
78
from database import (
89
Database,
910
Projects,
1011
TestSuites,
1112
ReportTestCaseCoverage,
1213
# ReportTestRunCounts
1314
)
14-
15+
'''
1516
from utils.datetime_utils import DatetimeUtils as dt
1617

1718

@@ -21,12 +22,17 @@ def __init__(self):
2122
try:
2223
TESTRAIL_HOST = os.environ['TESTRAIL_HOST']
2324
self.client = APIClient(TESTRAIL_HOST)
24-
self.client.user = os.environ['TESTRAIL_USERNAME']
25+
self.client.user = os.environ['TESTRAIL_USERNAME']
2526
self.client.password = os.environ['TESTRAIL_PASSWORD']
2627
except KeyError:
2728
print("ERROR: Missing testrail env var")
2829
sys.exit(1)
2930

31+
# API: Milestones
32+
# https://mozilla.testrail.io/index.php?/api/v2/get_milestones/59
33+
def milestones(self, project_id):
34+
return self.client.send_get('get_milestones/{0}'.format(project_id))
35+
3036
# API: Projects
3137
def projects(self):
3238
return self.client.send_get('get_projects')
@@ -81,8 +87,8 @@ class TestRailClient(TestRail):
8187

8288
def __init__(self):
8389
super().__init__()
84-
self.db = DatabaseTestRail()
85-
90+
#self.db = DatabaseTestRail()
91+
'''
8692
def data_pump(self, project='all', suite='all'):
8793
# call database for 'all' values
8894
# convert inputs to a list so we can easily
@@ -157,7 +163,7 @@ def testrail_coverage_update(self, projects_id,
157163
158164
# Insert data in 'totals' array into DB
159165
self.db.report_test_coverage_insert(projects_id, payload)
160-
166+
161167
def testrail_run_counts_update(self, project, num_days):
162168
start_date = dt.start_date(num_days)
163169
@@ -181,7 +187,30 @@ def testrail_run_counts_update(self, project, num_days):
181187
# Insert data in 'totals' array into DB
182188
self.db.report_test_runs_insert(projects_id, totals)
183189
184-
190+
'''
191+
def test_rail_milestones(self, project_id):
192+
payload = self.milestones('59')
193+
194+
df = pd.json_normalize(payload)
195+
196+
selected_columns = {
197+
"id": "id",
198+
"project_id": "project_id",
199+
"name": "name",
200+
"started_on": "started_on",
201+
"is_completed": "is_completed",
202+
"description": "description",
203+
"completed_on": "completed_on",
204+
"url": "url"
205+
}
206+
# Select specific columns
207+
df_selected = df[selected_columns.keys()]
208+
df_selected['started_on'] = df_selected['started_on'].apply(dt.convert_epoch_to_datetime) # noqa
209+
210+
df_selected.to_csv('output.csv', index=False)
211+
print(df_selected)
212+
213+
'''
185214
class DatabaseTestRail(Database):
186215
187216
def __init__(self):
@@ -294,7 +323,7 @@ def report_test_runs_insert(self, project_id, payload):
294323
if t['testrail_completed_on']:
295324
created_on = dt.convert_epoch_to_datetime(t['testrail_created_on']) # noqa
296325
completed_on = dt.convert_epoch_to_datetime(t['testrail_completed_on']) # noqa
297-
'''
326+
298327
report = ReportTestRunCounts(
299328
projects_id=project_id,
300329
testrail_run_id=t['testrail_run_id'],
@@ -304,6 +333,8 @@ def report_test_runs_insert(self, project_id, payload):
304333
test_case_blocked_count=t['blocked_count'],
305334
testrail_created_on=created_on,
306335
testrail_completed_on=completed_on)
307-
'''
336+
337+
308338
# self.session.add(report)
309339
self.session.commit()
340+
'''

utils/constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
'issue-regression',
2323
'jira-qa-requests',
2424
'jira-qa-needed',
25-
'bugzilla-qe-verify'
25+
'bugzilla-qe-verify',
26+
'milestones'
2627
]
2728

2829
# JQL query All QA Requests since 2022 filter_id: 13856

0 commit comments

Comments
 (0)