@@ -120,6 +120,48 @@ async def put_request(self, endpoint, payload):
120
120
logger .error ("Resource not found: %s" % self .url + endpoint )
121
121
return False
122
122
123
+ async def create_ticket (self , summary , description , labels = None ):
124
+ """Create a Jira ticket."""
125
+ if labels is None :
126
+ labels = []
127
+ endpoint = "/issue/"
128
+ logger .debug ("POST new ticket" )
129
+ short_summary = summary .split ("\r " )
130
+ title = f"{ short_summary [0 ]} "
131
+
132
+ data = {
133
+ "fields" : {
134
+ "project" : {"key" : self .ticket_queue },
135
+ "issuetype" : {"name" : "Task" },
136
+ "summary" : title ,
137
+ "description" : description ,
138
+ }
139
+ }
140
+ if labels :
141
+ data ["fields" ].update ({"labels" : labels })
142
+
143
+ response = await self .post_request (endpoint , data )
144
+ return response
145
+
146
+ async def create_subtask (self , parent_ticket , cloud , description , type_of_subtask ):
147
+ """Create a Jira subtask for a specified parent ticket."""
148
+ endpoint = "/issue/"
149
+ logger .debug ("POST new subtask" )
150
+ title = f"{ cloud } { type_of_subtask } "
151
+
152
+ data = {
153
+ "fields" : {
154
+ "project" : {"key" : self .ticket_queue },
155
+ "issuetype" : {"id" : "5" },
156
+ "parent" : {"key" : f"{ self .ticket_queue } -{ parent_ticket } " },
157
+ "summary" : title ,
158
+ "labels" : [type_of_subtask .upper ()],
159
+ "description" : description ,
160
+ }
161
+ }
162
+ response = await self .post_request (endpoint , data )
163
+ return response
164
+
123
165
async def add_watcher (self , ticket , watcher ):
124
166
issue_id = "%s-%s" % (Config ["ticket_queue" ], ticket )
125
167
endpoint = "/issue/%s/watchers" % issue_id
@@ -203,6 +245,19 @@ async def get_watchers(self, ticket):
203
245
return None
204
246
return result
205
247
248
+ async def get_user_by_email (self , email ):
249
+ """Find a Jira user by email."""
250
+ endpoint = f"/user/search?username={ email } "
251
+ logger .debug ("GET user: %s" % endpoint )
252
+ result = await self .get_request (endpoint )
253
+ if not result :
254
+ logger .error ("User not found" )
255
+ return None
256
+ for user in result :
257
+ if user .get ("emailAddress" ) == email :
258
+ return user
259
+ return None
260
+
206
261
async def get_all_pending_tickets (self ):
207
262
transition_id = await self .get_transition_id ("In Progress" )
208
263
query = {"status" : transition_id }
@@ -246,3 +301,17 @@ async def search_tickets(self, query=None):
246
301
logger .error ("Failed to get pending tickets" )
247
302
return None
248
303
return result
304
+
305
+ async def get_field_allowed_values (self , field_id , ticket_id = 1 ):
306
+ """Get list of allowed values from JIRA API for a specified field."""
307
+ endpoint = f"/issue/{ self .ticket_queue } -{ ticket_id } /editmeta"
308
+ result = await self .get_request (endpoint )
309
+ if not result :
310
+ logger .error ("Failed to get allowed values" )
311
+ return None
312
+ try :
313
+ result = result ["fields" ][f"customfield_{ field_id } " ]["allowedValues" ]
314
+ result = [entry ["value" ] for entry in result if not entry ["value" ].startswith ("One or more of the" )]
315
+ except (ValueError , AttributeError ):
316
+ logger .error ("Failed to get allowed values" )
317
+ return result
0 commit comments