-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_engineer.py
73 lines (66 loc) · 3.04 KB
/
add_engineer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
""" This code is triggered when adding a new engineer """
import shared.custom_fields as custom_fields
import shared.globals
import shared.shared_sd as shared_sd
import linaro_shared
CAPABILITIES = [
"COMMENT",
"CREATE"
]
def comment(ticket_data):
""" Triggered when a comment is posted """
_, keyword = shared_sd.central_comment_handler(
[], ["help", "retry"])
if keyword == "help":
shared_sd.post_comment(("All bot commands must be internal comments and the first word/phrase in the comment.\r\n\r\n"
"Valid commands are:\r\n"
"* retry to ask the bot to process the request again after issues have been resolved."), False)
elif keyword == "retry":
print("add_engineer processing retry keyword & triggering create function")
create(ticket_data)
def create(ticket_data):
""" Triggered when the ticket is created """
cf_engineering_team = custom_fields.get("Engineering Team")
team = shared_sd.get_field(ticket_data, cf_engineering_team)
director = linaro_shared.get_director(team["value"])
if director is None:
shared_sd.post_comment(
f"[[email protected]] Couldn't find the director for team '{team}'",
False
)
elif director != shared.globals.REPORTER:
shared_sd.add_request_participant(director)
# Build the name from the fields
cf_firstname = custom_fields.get("First Name (migrated)")
cf_familyname = custom_fields.get("Family Name")
firstname = shared_sd.get_field(ticket_data, cf_firstname)
familyname = shared_sd.get_field(ticket_data, cf_familyname)
if firstname is None or firstname == "":
name = familyname
else:
name = f"{firstname} {familyname}"
# Add the name to the summary if we haven't already
summary = shared_sd.get_field(ticket_data, "summary")
if not summary.endswith(name):
shared_sd.set_summary(f"{summary}: {name}")
# If the ticket wasn't raised by the proposed manager, get them
# to approve it.
cf_approvers = custom_fields.get("Approvers")
cf_manager = custom_fields.get("Employee/Contractor")
manager_anonymised = shared_sd.get_field(ticket_data, cf_manager)
# That gets us the manager's account ID so now get their full details
# so that we have, and can compare, the email address.
print(f"Result of retrieving the proposed manager: {manager_anonymised}")
manager = shared_sd.find_account_from_id(manager_anonymised["accountId"])
if manager is not None and "emailAddress" in manager:
mgr_email = manager["emailAddress"]
if mgr_email != shared.globals.REPORTER:
shared_sd.post_comment(
"As you are not the proposed manager, they will be asked to "
"approve or decline your request.",
True
)
shared_sd.assign_approvers([mgr_email], cf_approvers)
shared_sd.transition_request_to("Needs approval")
else:
shared_sd.transition_request_to("In Progress")