1
1
"""Module for interacting with Jira tickets."""
2
2
import os
3
3
import logging
4
- from jira import JIRA
4
+ from atlassian import Jira
5
5
from google .cloud import secretmanager
6
6
from typing import Optional
7
7
11
11
"""The default Broad Jira server address"""
12
12
13
13
14
- class Jira :
14
+ class JiraUtil :
15
15
"""
16
16
A class to assist in interacting with JIRA tickets.
17
-
17
+
18
18
Provides functionality to help in updating tickets
19
19
(adding comments, updating ticket fields, and transitioning statuses). Also provides a way to query
20
20
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
36
36
"""@private"""
37
37
self .jira_api_key_secret_name = jira_api_key_secret_name
38
38
"""@private"""
39
- self .jira = self ._connect_to_jira ()
39
+ self .jira_connection = self ._connect_to_jira ()
40
40
"""@private"""
41
41
42
- def _connect_to_jira (self ) -> JIRA :
42
+ def _connect_to_jira (self ) -> Jira :
43
43
"""
44
44
Obtain credentials and establish the Jira connection.
45
45
@@ -60,7 +60,7 @@ def _connect_to_jira(self) -> JIRA:
60
60
name = f"projects/{ self .gcp_project_id } /secrets/{ self .jira_api_key_secret_name } /versions/latest"
61
61
token = client .access_secret_version (name = name ).payload .data .decode ("UTF-8" )
62
62
63
- return JIRA ( server = self .server , basic_auth = ( jira_user , token ) )
63
+ return Jira ( url = self .server , username = jira_user , password = token )
64
64
65
65
def update_ticket_fields (self , issue_key : str , field_update_dict : dict ) -> None :
66
66
"""
@@ -71,8 +71,7 @@ def update_ticket_fields(self, issue_key: str, field_update_dict: dict) -> None:
71
71
- field_update_dict (dict): The field values to update. Formatted with the field ID as the key,
72
72
and the updated value as the key's value.
73
73
"""
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 )
76
75
77
76
def add_comment (self , issue_key : str , comment : str ) -> None :
78
77
"""
@@ -82,7 +81,7 @@ def add_comment(self, issue_key: str, comment: str) -> None:
82
81
- issue_key (str): The issue key to update
83
82
- comment (str): The comment to add
84
83
"""
85
- self .jira . add_comment (issue_key , comment )
84
+ self .jira_connection . issue_add_comment (issue_key , comment )
86
85
87
86
def transition_ticket (self , issue_key : str , transition_id : int ) -> None :
88
87
"""
@@ -92,7 +91,7 @@ def transition_ticket(self, issue_key: str, transition_id: int) -> None:
92
91
- issue_key (str): The issue key to update
93
92
- transition_id (int): The status ID to transition the issue to
94
93
"""
95
- self .jira . transition_issue (issue_key , transition_id )
94
+ self .jira_connection . set_issue_status_by_transition_id (issue_key , transition_id )
96
95
97
96
def get_issues_by_criteria (
98
97
self ,
@@ -108,13 +107,22 @@ def get_issues_by_criteria(
108
107
- criteria (str): The criteria to search for. This should be formatted in a supported JIRA search filter
109
108
(i.e. `project = '{project}' AND sprint = '{sprint_name}' AND status = {status}`)
110
109
- 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
112
111
ticket (i.e. `["summary", "status", "assignee"]`)
113
112
114
113
**Returns:**
115
114
- list[dict]: The list of issues matching the criteria
116
115
"""
117
116
logging .info (f"Getting issues by criteria: { criteria } " )
117
+
118
+ payload = {
119
+ "jql" : criteria ,
120
+ "maxResults" : max_results
121
+ }
122
+
118
123
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 )
0 commit comments