Skip to content

Commit 4a94c56

Browse files
authored
Merge pull request #34 from mozilla-mobile/irios-add-jira
Adding Jira to collect data
2 parents b97bfc4 + 38d69be commit 4a94c56

File tree

5 files changed

+116
-4
lines changed

5 files changed

+116
-4
lines changed

.github/workflows/staging-push.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ jobs:
4242
echo "TESTRAIL_HOST=${{ secrets.TESTRAIL_HOST_TEST }}" >> $GITHUB_ENV
4343
echo "TESTRAIL_USERNAME=${{ secrets.TESTRAIL_USERNAME }}" >> $GITHUB_ENV
4444
echo "TESTRAIL_PASSWORD=${{ secrets.TESTRAIL_PASSWORD }}" >> $GITHUB_ENV
45+
echo "JIRA_HOST=${{ secrets.JIRA_HOST }}" >> $GITHUB_ENV
46+
echo "JIRA_USER=${{ secrets.JIRA_USER }}" >> $GITHUB_ENV
47+
echo "JIRA_PASSWORD=${{ secrets.JIRA_PASSWORD }}" >> $GITHUB_ENV
4548
echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
4649
4750
#- name: Update DB - test runs
4851
# run: python ./__main__.py --report-type test-run-counts --project fenix --start-date 2021-08-15 --end-date 2021-10-01
4952

50-
- name: Update DB - test coverage
51-
#run: python ./__main__.py --report-type test-case-coverage --project ALL
52-
run: python ./__main__.py --report-type test-case-coverage --project fenix
53+
- name: Jira query
54+
run: python ./__main__.py --report-type jira-qa-requests
5355
- name: Set job log URL
5456
if: always()
5557
run: echo "JOB_LOG_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" >> $GITHUB_ENV

__main__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33

44
from github import GithubClient
5+
from jira import Jira
56
from testrail import TestRailClient
67
from utils.constants import PROJECTS_ABBREV, REPORT_TYPES
78

@@ -14,7 +15,7 @@ def parse_args(cmdln_args):
1415
parser.add_argument(
1516
"--project",
1617
help="Indicate project",
17-
required=True,
18+
required=False,
1819
choices=PROJECTS_ABBREV
1920
)
2021

@@ -52,6 +53,9 @@ def main():
5253
h = GithubClient()
5354
h.github_issue_regression(args.project)
5455
h = GithubClient()
56+
if args.report_type == 'jira-qa-requests':
57+
h = Jira()
58+
h.filters()
5559

5660

5761
if __name__ == '__main__':

jira.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
import sys
3+
4+
from lib.jira_conn import JiraAPIClient
5+
6+
7+
# JQL query All QA Requests since 2022 filter_id: 13856
8+
FILTER_ID_ALL_REQUESTS_2022 = "13856"
9+
# Fields needed
10+
STORY_POINTS = "customfield_10037"
11+
FIREFOX_RELEASE_TRAIN = "customfield_10155"
12+
ENGINEERING_TEAM = "customfield_10134"
13+
DEFAULT_COLUMNS = "id,key,status,created,summary,labels,assignee,"
14+
MAX_RESULT = "maxResults=100"
15+
16+
JQL_QUERY = 'jql=filter='
17+
18+
19+
class Jira:
20+
21+
def __init__(self):
22+
try:
23+
JIRA_HOST = os.environ['JIRA_HOST']
24+
self.client = JiraAPIClient(JIRA_HOST)
25+
self.client.user = os.environ['JIRA_USER']
26+
self.client.password = os.environ['JIRA_PASSWORD']
27+
28+
except KeyError:
29+
print("ERROR: Missing jira env var")
30+
sys.exit(1)
31+
32+
# API: Filters
33+
def filters(self):
34+
query = JQL_QUERY + FILTER_ID_ALL_REQUESTS_2022 + '&fields=' \
35+
+ DEFAULT_COLUMNS + STORY_POINTS + FIREFOX_RELEASE_TRAIN \
36+
+ ENGINEERING_TEAM + '&' + MAX_RESULT
37+
return self.client.get_search(query)

lib/jira_conn.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
"""Jira API binding for Python 3.x
3+
4+
Learn more:
5+
6+
https://docs.atlassian.com/software/jira/docs/api/REST/9.16.0/
7+
8+
Copyright Atlassian developer. See license.md for details.
9+
"""
10+
import requests
11+
12+
from requests.auth import HTTPBasicAuth
13+
14+
15+
class JiraAPIClient:
16+
def __init__(self, base_url):
17+
self.user = ''
18+
self.password = ''
19+
if not base_url.endswith('/'):
20+
base_url += '/'
21+
self.__url = base_url
22+
23+
def get_search(self, query):
24+
"""Issue a GET request (read) against the API.
25+
26+
Args:
27+
filter{id}: The API method to call including parameters,
28+
e.g. GET /rest/api/2/filter/{id}.
29+
30+
Returns:
31+
JSON representation of the search results.
32+
"""
33+
return self.__send_request('GET', query)
34+
35+
def __send_request(self, method, query):
36+
url = self.__url + '?' + query
37+
38+
# Store all results
39+
all_results = []
40+
41+
headers = {"Content-Type": "application/json"}
42+
43+
# Pagination variables
44+
start_at = 0
45+
max_results = 100
46+
total = 1 # Initial value greater than start_at to enter the loop
47+
48+
while start_at < total:
49+
# Send GET request
50+
response = requests.get(
51+
url,
52+
headers=headers,
53+
auth=HTTPBasicAuth(self.user, self.password))
54+
55+
if response.status_code == 200:
56+
data = response.json()
57+
all_results.extend(data['issues'])
58+
total = data['total'] # Update total based on the response
59+
start_at += max_results # Move to the next page
60+
else:
61+
print(f"Failed to fetch data: {response.status_code}")
62+
print(response.text)
63+
break
64+
65+
# Print the total number of issues retrieved
66+
print(f"Total issues retrieved: {len(all_results)}")
67+
print(data)
68+
return data

utils/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
'test-case-coverage',
1212
'test-run-counts',
1313
'issue-regression',
14+
'jira-qa-requests'
1415
]

0 commit comments

Comments
 (0)