5
5
import json
6
6
import webbrowser
7
7
import argparse
8
- from typing import Dict , List , Tuple , Any
8
+ from typing import List , Tuple
9
9
from abr_testing .data_collection import read_robot_logs , abr_google_drive , get_run_logs
10
10
11
11
@@ -84,7 +84,6 @@ class JiraTicket:
84
84
85
85
def __init__ (self , url : str , api_token : str , email : str ) -> None :
86
86
"""Connect to jira."""
87
-
88
87
self .url = url
89
88
self .api_token = api_token
90
89
self .email = email
@@ -94,7 +93,7 @@ def __init__(self, url: str, api_token: str, email: str) -> None:
94
93
"Content-Type" : "application/json" ,
95
94
}
96
95
97
- def issues_on_board (self , board_id ) -> List [str ]:
96
+ def issues_on_board (self , board_id : str ) -> List [str ]:
98
97
"""Print Issues on board."""
99
98
response = requests .get (
100
99
f"{ self .url } /rest/agile/1.0/board/{ board_id } /issue" ,
@@ -113,7 +112,7 @@ def issues_on_board(self, board_id) -> List[str]:
113
112
issue_ids .append (issue_id )
114
113
return issue_ids
115
114
116
- def open_issue (self , issue_key ) -> None :
115
+ def open_issue (self , issue_key : str ) -> None :
117
116
"""Open issue on web browser."""
118
117
url = f"{ self .url } /browse/{ issue_key } "
119
118
webbrowser .open (url )
@@ -174,7 +173,7 @@ def create_ticket(
174
173
print (f"JSON decoding error occurred. Response content: { response_str } " )
175
174
return issue_url , issue_key
176
175
177
- def post_attachment_to_ticket (self , issue_id : str , attachment_path : str ):
176
+ def post_attachment_to_ticket (self , issue_id : str , attachment_path : str ) -> None :
178
177
"""Adds attachments to ticket."""
179
178
# TODO: Ensure that file is actually uploaded.
180
179
file = {"file" : open (attachment_path , "rb" )}
@@ -209,18 +208,39 @@ def post_attachment_to_ticket(self, issue_id: str, attachment_path: str):
209
208
nargs = 1 ,
210
209
help = "IP address of robot as string." ,
211
210
)
211
+ parser .add_argument (
212
+ "jira_api_token" ,
213
+ metavar = "JIRA_API_TOKEN" ,
214
+ type = str ,
215
+ nargs = 1 ,
216
+ help = "JIRA API Token. Get from https://id.atlassian.com/manage-profile/security." ,
217
+ )
218
+ parser .add_argument (
219
+ "email" ,
220
+ metavar = "EMAIL" ,
221
+ type = str ,
222
+ nargs = 1 ,
223
+ help = "Email connected to JIRA account." ,
224
+ )
225
+ # TODO: improve help comment on jira board id.
226
+ parser .add_argument (
227
+ "board_id" ,
228
+ metavar = "BOARD_ID" ,
229
+ type = str ,
230
+ nargs = 1 ,
231
+ help = "JIRA Board ID. RABR is 217" ,
232
+ )
212
233
args = parser .parse_args ()
213
234
storage_directory = args .storage_directory [0 ]
214
235
ip = args .robot_ip [0 ]
215
236
url = "https://opentrons.atlassian.net"
216
- api_token = "ATATT3xFfGF0SZgHzGog6J_bTK3j6HFRnbUC-tE_gB5Sn_56d-NSdlRb5C-ywGxNgV4fHfSGbhgENlGKI1aSPc5dy8ql0EiVYW4dHifJhyKUueu5yq6BrL9Xcsfwz_p1W6xUmSsyecvZ0lGPFLb5sreqRg5kE3FRs6SqcKaQxH6_EGFGS0Obb5c=BA8756FE"
217
-
218
- board_id = "217"
237
+ api_token = args . jira_api_token [ 0 ]
238
+ email = args . email [ 0 ]
239
+ board_id = args . board_id [ 0 ]
219
240
220
241
ticket = JiraTicket (url , api_token , email )
221
242
error_runs = get_error_runs_from_robot (ip )
222
- one_run = error_runs [0 ]
223
- print (one_run )
243
+ one_run = error_runs [- 1 ] # Most recent run with error.
224
244
(
225
245
summary ,
226
246
robot ,
@@ -229,6 +249,8 @@ def post_attachment_to_ticket(self, issue_id: str, attachment_path: str):
229
249
whole_description_str ,
230
250
saved_file_path ,
231
251
) = get_error_info_from_robot (ip , one_run , storage_directory )
252
+ print (f"Making ticket for run: { one_run } on robot { robot } ." )
253
+ # TODO: make argument or see if I can get rid of with using board_id.
232
254
project_key = "RABR"
233
255
parent_key = project_key + "-" + robot [- 1 ]
234
256
issue_url , issue_key = ticket .create_ticket (
0 commit comments