Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Jira pipeline adding new issue types #49

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
- name: Set up Python environment
uses: actions/setup-python@v1
with:
python-version: "3.8"
python-version: "3.10.16"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed so that flake8 works

- name: flake8 Lint
uses: py-actions/flake8@v1
1 change: 1 addition & 0 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def main():
if args.report_type == 'jira-qa-requests':
h = JiraClient()
h.jira_qa_requests()
h.jira_qa_requests_new_issue_types()
if args.report_type == 'jira-qa-needed':
h = JiraClient()
h.jira_qa_needed()
Expand Down
4 changes: 4 additions & 0 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class ReportJiraQARequests(Base):
__table__ = Table('report_jira_qa_requests', Base.metadata, autoload=True) # noqa


class ReportJIraQARequestsNewIssueType(Base):
__table__ = Table('report_jira_qa_requests_new_issue_types', Base.metadata, autoload=True) # noqa


class ReportJiraQANeeded(Base):
__table__ = Table('report_jira_qa_needed', Base.metadata, autoload=True) # noqa

Expand Down
108 changes: 96 additions & 12 deletions jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,14 @@
from database import (
Database,
ReportJiraQARequests,
ReportJiraQANeeded
ReportJiraQANeeded,
ReportJIraQARequestsNewIssueType
)
from utils.datetime_utils import DatetimeUtils as dt
from utils.constants import FILTER_ID_ALL_REQUESTS_2022, MAX_RESULT
from utils.constants import FILTER_ID_ALL_REQUESTS_2022, FILTER_ID_NEW_ISSUE_TYPES, MAX_RESULT # noqa
from utils.constants import JQL_QUERY, STORY_POINTS, FIREFOX_RELEASE_TRAIN, ENGINEERING_TEAM, DEFAULT_COLUMNS, COLUMNS_ISSUE_TYPE, TESTED_TRAINS # noqa
from utils.constants import FILTER_ID_QA_NEEDED_iOS

# JQL query All QA Requests since 2022 filter_id: 13856
# Extra fields needed
STORY_POINTS = "customfield_10037"
FIREFOX_RELEASE_TRAIN = "customfield_10155"
ENGINEERING_TEAM = "customfield_10134"
DEFAULT_COLUMNS = "id,key,status,created,summary,labels,assignee,"

JQL_QUERY = 'jql=filter='


class Jira:

Expand All @@ -31,7 +24,6 @@ def __init__(self):
self.client = JiraAPIClient(JIRA_HOST)
self.client.user = os.environ['JIRA_USER']
self.client.password = os.environ['JIRA_PASSWORD']

except KeyError:
print("ERROR: Missing jira env var")
sys.exit(1)
Expand All @@ -45,6 +37,15 @@ def filters(self):

return self.client.get_search(query)

def filters_new_issue_type(self):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using a new filter to not to mess up with the info we have from Requests up until now. Starting this year, even though we still have Requests, there are Internal Tasks and Sub-Tasks, and for those, now we rely on labels to filter and group them. Requests from last year or earlier do not all have labels and filtering them has been difficult when using the new query.

query = JQL_QUERY + FILTER_ID_NEW_ISSUE_TYPES + '&fields=' \
+ DEFAULT_COLUMNS + COLUMNS_ISSUE_TYPE + ',' \
+ STORY_POINTS + ',' \
+ FIREFOX_RELEASE_TRAIN + ',' + TESTED_TRAINS + ',' \
+ ENGINEERING_TEAM + '&' + MAX_RESULT

return self.client.get_search(query)

def filter_qa_needed(self):
query = JQL_QUERY + FILTER_ID_QA_NEEDED_iOS + '&' + MAX_RESULT
return self.client.get_search(query)
Expand All @@ -67,6 +68,18 @@ def jira_qa_requests(self):

self.db.report_jira_qa_requests_insert(data_frame)

def jira_qa_requests_new_issue_types(self):
payload = self.filters_new_issue_type()
print("This is the payload returning from filter")
print(payload)

self.db.qa_requests_delete()

data_frame = self.db.report_jira_qa_requests__new_issue_types_payload(payload) # noqa
print(data_frame)

self.db.report_jira_qa_requests_insert_new_issue_types(data_frame)

def jira_qa_needed(self):
payload = self.filter_qa_needed()
data_frame = self.db.report_jira_qa_needed(payload)
Expand Down Expand Up @@ -132,6 +145,57 @@ def report_jira_qa_requests_payload(self, payload):

return df_selected

def report_jira_qa_requests__new_issue_types_payload(self, payload):
# Normalize the JSON data
self.session.query(ReportJIraQARequestsNewIssueType).delete()
df = pd.json_normalize(payload, sep='_')

# Check if 'jira_assignee_username' exists
# if not use 'alternative_assignee_emailAddress'
if 'fields_assignee_emailAddress' not in df.columns:
df['fields_assignee_emailAddress'] = df.get('fields_assignee', "None") # noqa
else:
df['fields_assignee_emailAddress'] = df['fields_assignee_emailAddress'].fillna("Not Assigned") # noqa

# Drop the alternative column if it exists
if 'fields_assignee' in df.columns:
df.drop(columns=['fields_assignee'], inplace=True)

# Select specific columns
selected_columns = {
'key': 'jira_key',
'fields_summary': 'jira_summary',
'fields_created': 'jira_created_at',
'fields_customfield_10155_value': 'jira_firefox_release_train',
'fields_customfield_10134_value': 'jira_engineering_team',
'fields_customfield_10037': 'jira_story_points',
'fields_status_name': 'jira_status',
'fields_assignee_emailAddress': 'jira_assignee_username',
'fields_labels': 'jira_labels',
'fields_customfield_11930': 'jira_tested_train',
'fields_issuetype_name': 'jira_issue_type',
'fields_parent_key': 'jira_parent_link'
}

# Select specific columns
df_selected = df[selected_columns.keys()]
print(df_selected)

# Rename columns
df_selected = df_selected.rename(columns=selected_columns)

df_selected['jira_created_at'] = df_selected['jira_created_at'].apply(dt.convert_to_utc) # noqa

# Join list of labels into a single string
df_selected['jira_labels'] = df_selected['jira_labels'].apply(lambda x: ','.join(x) if isinstance(x, list) else x) # noqa

# Convert NaN values to 0 and ensure the column is of type int
df_selected['jira_story_points'] = df_selected['jira_story_points'].fillna(0).astype(int) # noqa

df_selected = df_selected.where(pd.notnull(df_selected), None)

return df_selected

def report_jira_qa_requests_insert(self, payload):
print(payload)

Expand All @@ -149,6 +213,26 @@ def report_jira_qa_requests_insert(self, payload):
self.session.add(report)
self.session.commit()

def report_jira_qa_requests_insert_new_issue_types(self, payload):
print(payload)

for index, row in payload.iterrows():
print(row)
report = ReportJIraQARequestsNewIssueType(jira_key=row['jira_key'],
jira_created_at=row['jira_created_at'].date(), # noqa
jira_summary=row['jira_summary'], # noqa
jira_firefox_release_train=row['jira_firefox_release_train'], # noqa
jira_engineering_team=row['jira_engineering_team'], # noqa
jira_story_points=row['jira_story_points'], # noqa
jira_status=row['jira_status'], # noqa
jira_assignee_username=row['jira_assignee_username'], # noqa
jira_labels=row['jira_labels'], # noqa
jira_tested_train=row['jira_tested_train'], # noqa
jira_issue_type=row['jira_issue_type'], # noqa
jira_parent_link=row['jira_parent_link']) # noqa
self.session.add(report)
self.session.commit()

def report_jira_qa_needed(self, payload):
# Normalize the JSON data
df = pd.json_normalize(payload, sep='_')
Expand Down
13 changes: 13 additions & 0 deletions utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,22 @@
FILTER_ID_ALL_REQUESTS_2022 = "13856"
MAX_RESULT = "maxResults=100"

# JQL query Requests, Internal Task, Sub-Task filter_id: 14323
FILTER_ID_NEW_ISSUE_TYPES = "14323"

# JQL query All QA Needed iOS filter_id: 13789
FILTER_ID_QA_NEEDED_iOS = "13789"

# JQL Extra fields needed
JQL_QUERY = 'jql=filter='
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving here all these constant values


STORY_POINTS = "customfield_10037"
FIREFOX_RELEASE_TRAIN = "customfield_10155"
ENGINEERING_TEAM = "customfield_10134"
DEFAULT_COLUMNS = "id,key,status,created,summary,labels,assignee"
COLUMNS_ISSUE_TYPE = ",issuetype,parent"
TESTED_TRAINS = "customfield_11930"

# Bugzilla queries
BUGZILLA_URL = "bugzilla.mozilla.org"
PRODUCTS = ["Fenix", "Focus", "GeckoView"]
Expand Down
Loading