Skip to content

Commit

Permalink
Add TR milestone support
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelrios committed Nov 27, 2024
1 parent fd6f354 commit a5d16a8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 16 deletions.
20 changes: 13 additions & 7 deletions __main__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import argparse
import sys

from bugz import BugzillaClient
from github import GithubClient
from jira import JiraClient
#from bugz import BugzillaClient
#from github import GithubClient
#from jira import JiraClient
from testrail import TestRailClient
from utils.constants import PROJECTS_MOBILE, PROJECTS_ECOSYSTEM, PLATFORM, REPORT_TYPES # noqa

Expand All @@ -29,7 +29,7 @@ def parse_args(cmdln_args):
parser.add_argument(
"--report-type",
help="Indicate report type",
required=True,
required=False,
choices=REPORT_TYPES
)

Expand All @@ -46,7 +46,8 @@ def parse_args(cmdln_args):
def validate_project(platform, project, report_type):
# Conditionally require --platform and --project
# if --report-type is 'test-case-coverage'
if report_type == 'test-case-coverage':
# if report_type == 'test-case-coverage':
if report_type in ('test-case-coverage', 'milestones'):
if not project:
print("--project is required for the report selected")
if not platform:
Expand All @@ -63,7 +64,7 @@ def validate_project(platform, project, report_type):
def main():
args = parse_args(sys.argv[1:])
validate_project(args.platform, args.project, args.report_type)

if args.report_type == 'test-case-coverage':
h = TestRailClient()
h.data_pump(args.project.lower())
Expand All @@ -74,10 +75,15 @@ def main():
else:
num_days = ''
h.testrail_run_counts_update(args.project, num_days)
if args.report_type == 'milestones':
h = TestRailClient()
h.test_rail_milestones('59')
'''
if args.report_type == 'issue-regression':
h = GithubClient()
h.github_issue_regression(args.project)
h = GithubClient()
if args.report_type == 'jira-qa-requests':
h = JiraClient()
h.jira_qa_requests()
Expand All @@ -87,7 +93,7 @@ def main():
if args.report_type == 'bugzilla-qe-verify':
h = BugzillaClient()
h.bugzilla_qe_verify()

'''

if __name__ == '__main__':
main()
7 changes: 7 additions & 0 deletions lib/testrail_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __send_request(self, method, uri, data):
while True:
response = requests.get(f"{url}&limit={limit}&offset={offset}", headers=headers)
data = response.json()
print(data)

# Check if 'cases' key exists in the response
if 'cases' in data:
Expand All @@ -92,6 +93,12 @@ def __send_request(self, method, uri, data):
# Break if fewer items are returned than the limit, indicating the last page
if len(data['cases']) < limit:
break
if 'milestones' in data:
all_items.extend(data['milestones'])

# Break if fewer items are returned than the limit, indicating the last page
if len(data['milestones']) < limit:
break
else:
all_items = data
break # If 'cases' key is not present, exit the loop
Expand Down
47 changes: 39 additions & 8 deletions testrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import pandas as pd

from lib.testrail_conn import APIClient
'''
from database import (
Database,
Projects,
TestSuites,
ReportTestCaseCoverage,
# ReportTestRunCounts
)

'''
from utils.datetime_utils import DatetimeUtils as dt


Expand All @@ -21,12 +22,17 @@ def __init__(self):
try:
TESTRAIL_HOST = os.environ['TESTRAIL_HOST']
self.client = APIClient(TESTRAIL_HOST)
self.client.user = os.environ['TESTRAIL_USERNAME']
self.client.user = os.environ['TESTRAIL_USERNAME']
self.client.password = os.environ['TESTRAIL_PASSWORD']
except KeyError:
print("ERROR: Missing testrail env var")
sys.exit(1)

# API: Milestones
# https://mozilla.testrail.io/index.php?/api/v2/get_milestones/59
def milestones(self, project_id):
return self.client.send_get('get_milestones/{0}'.format(project_id))

# API: Projects
def projects(self):
return self.client.send_get('get_projects')
Expand Down Expand Up @@ -81,8 +87,8 @@ class TestRailClient(TestRail):

def __init__(self):
super().__init__()
self.db = DatabaseTestRail()

#self.db = DatabaseTestRail()
'''
def data_pump(self, project='all', suite='all'):
# call database for 'all' values
# convert inputs to a list so we can easily
Expand Down Expand Up @@ -157,7 +163,7 @@ def testrail_coverage_update(self, projects_id,
# Insert data in 'totals' array into DB
self.db.report_test_coverage_insert(projects_id, payload)

def testrail_run_counts_update(self, project, num_days):
start_date = dt.start_date(num_days)
Expand All @@ -181,7 +187,30 @@ def testrail_run_counts_update(self, project, num_days):
# Insert data in 'totals' array into DB
self.db.report_test_runs_insert(projects_id, totals)

'''
def test_rail_milestones(self, project_id):
payload = self.milestones('59')

df = pd.json_normalize(payload)

selected_columns = {
"id": "id",
"project_id": "project_id",
"name": "name",
"started_on": "started_on",
"is_completed": "is_completed",
"description": "description",
"completed_on": "completed_on",
"url": "url"
}
# Select specific columns
df_selected = df[selected_columns.keys()]
df_selected['started_on'] = df_selected['started_on'].apply(dt.convert_epoch_to_datetime) # noqa

df_selected.to_csv('output.csv', index=False)
print(df_selected)

'''
class DatabaseTestRail(Database):
def __init__(self):
Expand Down Expand Up @@ -294,7 +323,7 @@ def report_test_runs_insert(self, project_id, payload):
if t['testrail_completed_on']:
created_on = dt.convert_epoch_to_datetime(t['testrail_created_on']) # noqa
completed_on = dt.convert_epoch_to_datetime(t['testrail_completed_on']) # noqa
'''
report = ReportTestRunCounts(
projects_id=project_id,
testrail_run_id=t['testrail_run_id'],
Expand All @@ -304,6 +333,8 @@ def report_test_runs_insert(self, project_id, payload):
test_case_blocked_count=t['blocked_count'],
testrail_created_on=created_on,
testrail_completed_on=completed_on)
'''
# self.session.add(report)
self.session.commit()
'''
3 changes: 2 additions & 1 deletion utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
'issue-regression',
'jira-qa-requests',
'jira-qa-needed',
'bugzilla-qe-verify'
'bugzilla-qe-verify',
'milestones'
]

# JQL query All QA Requests since 2022 filter_id: 13856
Expand Down

0 comments on commit a5d16a8

Please sign in to comment.