Skip to content

Commit 579a86a

Browse files
authored
POD-2905: Upgrade Jira utilities to remove deprecated API calls (#79)
* upgrade jira - get issues method * upgrade jira - get issues method * upgrade jira - get issues method * update remainig methods, update version file * update documentation string * update requirements, update unit tests * remove unneeded test data
1 parent 8a0320f commit 579a86a

File tree

9 files changed

+101
-7821
lines changed

9 files changed

+101
-7821
lines changed

VERSION.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
11.7.0
2-
- Added delete_files_and_snapshots()
3-
- Modify SubmitAndMonitorMultipleJobs to collect job failures and report instead of exiting early
4-
- Added dry_run property to TDR
1+
12.0.0
2+
- Update Jira utilities to use new API endpoints and remove deprecated methods

ops_utils/jira_util.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Module for interacting with Jira tickets."""
22
import os
33
import logging
4-
from jira import JIRA
4+
from atlassian import Jira
55
from google.cloud import secretmanager
66
from typing import Optional
77

@@ -11,10 +11,10 @@
1111
"""The default Broad Jira server address"""
1212

1313

14-
class Jira:
14+
class JiraUtil:
1515
"""
1616
A class to assist in interacting with JIRA tickets.
17-
17+
1818
Provides functionality to help in updating tickets
1919
(adding comments, updating ticket fields, and transitioning statuses). Also provides a way to query
2020
existing JIRA tickets using certain filters. Assumes that an accessible JIRA API key is stored in
@@ -36,10 +36,10 @@ def __init__(self, server: str, gcp_project_id: str, jira_api_key_secret_name: s
3636
"""@private"""
3737
self.jira_api_key_secret_name = jira_api_key_secret_name
3838
"""@private"""
39-
self.jira = self._connect_to_jira()
39+
self.jira_connection = self._connect_to_jira()
4040
"""@private"""
4141

42-
def _connect_to_jira(self) -> JIRA:
42+
def _connect_to_jira(self) -> Jira:
4343
"""
4444
Obtain credentials and establish the Jira connection.
4545
@@ -60,7 +60,7 @@ def _connect_to_jira(self) -> JIRA:
6060
name = f"projects/{self.gcp_project_id}/secrets/{self.jira_api_key_secret_name}/versions/latest"
6161
token = client.access_secret_version(name=name).payload.data.decode("UTF-8")
6262

63-
return JIRA(server=self.server, basic_auth=(jira_user, token))
63+
return Jira(url=self.server, username=jira_user, password=token)
6464

6565
def update_ticket_fields(self, issue_key: str, field_update_dict: dict) -> None:
6666
"""
@@ -71,8 +71,7 @@ def update_ticket_fields(self, issue_key: str, field_update_dict: dict) -> None:
7171
- field_update_dict (dict): The field values to update. Formatted with the field ID as the key,
7272
and the updated value as the key's value.
7373
"""
74-
issue = self.jira.issue(issue_key)
75-
issue.update(fields=field_update_dict)
74+
self.jira_connection.issue_update(issue_key, field_update_dict)
7675

7776
def add_comment(self, issue_key: str, comment: str) -> None:
7877
"""
@@ -82,7 +81,7 @@ def add_comment(self, issue_key: str, comment: str) -> None:
8281
- issue_key (str): The issue key to update
8382
- comment (str): The comment to add
8483
"""
85-
self.jira.add_comment(issue_key, comment)
84+
self.jira_connection.issue_add_comment(issue_key, comment)
8685

8786
def transition_ticket(self, issue_key: str, transition_id: int) -> None:
8887
"""
@@ -92,7 +91,7 @@ def transition_ticket(self, issue_key: str, transition_id: int) -> None:
9291
- issue_key (str): The issue key to update
9392
- transition_id (int): The status ID to transition the issue to
9493
"""
95-
self.jira.transition_issue(issue_key, transition_id)
94+
self.jira_connection.set_issue_status_by_transition_id(issue_key, transition_id)
9695

9796
def get_issues_by_criteria(
9897
self,
@@ -108,13 +107,22 @@ def get_issues_by_criteria(
108107
- criteria (str): The criteria to search for. This should be formatted in a supported JIRA search filter
109108
(i.e. `project = '{project}' AND sprint = '{sprint_name}' AND status = {status}`)
110109
- max_results (int): The maximum number of results to return. Defaults to 200.
111-
- fields (list[string], optional): The fields to include in the return for each
110+
- fields (list[string], optional): A list of the fields to include in the return for each
112111
ticket (i.e. `["summary", "status", "assignee"]`)
113112
114113
**Returns:**
115114
- list[dict]: The list of issues matching the criteria
116115
"""
117116
logging.info(f"Getting issues by criteria: {criteria}")
117+
118+
payload = {
119+
"jql": criteria,
120+
"maxResults": max_results
121+
}
122+
118123
if fields:
119-
return self.jira.search_issues(criteria, fields=fields, maxResults=max_results, expand=expand_info)
120-
return self.jira.search_issues(criteria, maxResults=max_results, expand=expand_info)
124+
payload["fields"] = fields
125+
if expand_info:
126+
payload["expand"] = expand_info
127+
128+
return self.jira_connection.post("rest/api/3/search/jql", data=payload)

ops_utils/tests/data/jira_util/add_comment_to_ticket.yaml

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)