Skip to content

Commit eacbd26

Browse files
committed
more args added
1 parent d7fd713 commit eacbd26

File tree

1 file changed

+32
-10
lines changed

1 file changed

+32
-10
lines changed

abr-testing/abr_testing/automation/jira_tool.py

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import json
66
import webbrowser
77
import argparse
8-
from typing import Dict, List, Tuple, Any
8+
from typing import List, Tuple
99
from abr_testing.data_collection import read_robot_logs, abr_google_drive, get_run_logs
1010

1111

@@ -84,7 +84,6 @@ class JiraTicket:
8484

8585
def __init__(self, url: str, api_token: str, email: str) -> None:
8686
"""Connect to jira."""
87-
8887
self.url = url
8988
self.api_token = api_token
9089
self.email = email
@@ -94,7 +93,7 @@ def __init__(self, url: str, api_token: str, email: str) -> None:
9493
"Content-Type": "application/json",
9594
}
9695

97-
def issues_on_board(self, board_id) -> List[str]:
96+
def issues_on_board(self, board_id: str) -> List[str]:
9897
"""Print Issues on board."""
9998
response = requests.get(
10099
f"{self.url}/rest/agile/1.0/board/{board_id}/issue",
@@ -113,7 +112,7 @@ def issues_on_board(self, board_id) -> List[str]:
113112
issue_ids.append(issue_id)
114113
return issue_ids
115114

116-
def open_issue(self, issue_key) -> None:
115+
def open_issue(self, issue_key: str) -> None:
117116
"""Open issue on web browser."""
118117
url = f"{self.url}/browse/{issue_key}"
119118
webbrowser.open(url)
@@ -174,7 +173,7 @@ def create_ticket(
174173
print(f"JSON decoding error occurred. Response content: {response_str}")
175174
return issue_url, issue_key
176175

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:
178177
"""Adds attachments to ticket."""
179178
# TODO: Ensure that file is actually uploaded.
180179
file = {"file": open(attachment_path, "rb")}
@@ -209,18 +208,39 @@ def post_attachment_to_ticket(self, issue_id: str, attachment_path: str):
209208
nargs=1,
210209
help="IP address of robot as string.",
211210
)
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+
)
212233
args = parser.parse_args()
213234
storage_directory = args.storage_directory[0]
214235
ip = args.robot_ip[0]
215236
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]
219240

220241
ticket = JiraTicket(url, api_token, email)
221242
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.
224244
(
225245
summary,
226246
robot,
@@ -229,6 +249,8 @@ def post_attachment_to_ticket(self, issue_id: str, attachment_path: str):
229249
whole_description_str,
230250
saved_file_path,
231251
) = 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.
232254
project_key = "RABR"
233255
parent_key = project_key + "-" + robot[-1]
234256
issue_url, issue_key = ticket.create_ticket(

0 commit comments

Comments
 (0)