-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjira_ticket.py
78 lines (66 loc) · 2.09 KB
/
jira_ticket.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
74
75
76
77
78
"""
This utility cretae jira tickets from help form
"""
from jira.client import JIRA
import base64
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
from email.utils import formataddr
import smtplib
import urllib
def send_email():
subject = "New Ticket in DESRELEASE"
toemail = '[email protected]'
fromemail = '[email protected]'
s = smtplib.SMTP('smtp.ncsa.illinois.edu')
text = "https://opensource.ncsa.illinois.edu/jira/projects/DESRELEASE"
MP1 = MIMEText(text, 'plain')
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = formataddr((str(Header('DESRELEASE JIRA', 'utf-8')), fromemail))
msg['To'] = toemail
msg.attach(MP1)
s.sendmail(fromemail, toemail, msg.as_string())
s.quit()
def create_ticket(first, last, email, topics, subject, question):
f = open('.access', 'r')
A = f.readlines()
f.close()
my_string_u = base64.b64decode(A[0].strip()).decode().strip()
my_string_p = base64.b64decode(A[1].strip()).decode().strip()
"""
This function creates the ticket coming form the help form
"""
jira = JIRA(
server="https://opensource.ncsa.illinois.edu/jira/",
basic_auth=(my_string_u, my_string_p))
body = """
*ACTION ITEMS*
- Please ASSIGN this ticket if it is unassigned.
- PLEASE SEND AN EMAIL TO *%s* to reply to this ticket
- COPY the answer in the comments section and ideally further communication.
- PLEASE close this ticket when resolved
*Name*: %s %s
*Email*: %s
*Topics*:
%s
*Question*:
%s
""" % (email, first, last, email, topics, question)
issue = {
'project' : {'key': 'DESRELEASE'},
'issuetype': {'name': 'Task'},
'summary': 'Q: %s' % subject,
'description' : body,
#'reporter' : {'name': 'desdm-wufoo'},
}
temp = jira.create_issue(fields=issue)
try:
ticket = temp.key
valid = True
except:
ticket = ''
valid = False
return valid, ticket
#send_email()