-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjira.py
123 lines (104 loc) · 4.48 KB
/
jira.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python
"""
jira.py - Phenny Seen Module
Copyright 2008, Sean B. Palmer, inamidst.com
Licensed under the Eiffel Forum License 2.
http://inamidst.com/phenny/
"""
import xmlrpclib
import time
import re
from os_projectbot.shorten import shorten
#import modules.activecollab
recent_tickets = {}
min_age = 60 * 5
def get_status(self):
server = xmlrpclib.ServerProxy(self.config.jira_baseurl)
print self.config.jira_baseurl
try:
# self.jira = {}
auth = server.jira1.login(self.config.jira_username, self.config.jira_password)
server_statuses = server.jira1.getStatuses(auth)
print server_statuses
jira_statuses = {}
for status in server_statuses:
if self.config.jira_mappings['status'].has_key(status['name']):
jira_statuses[status['id']] = self.config.jira_mappings['status'][status['name']]
else:
jira_statuses[status['id']] = status['name']
self.jira_statuses = jira_statuses
server_priorities = server.jira1.getPriorities(auth)
jira_priorities = {}
for priority in server_priorities:
if self.config.jira_mappings['priority'].has_key(priority['name']):
jira_priorities[priority['id']] = self.config.jira_mappings['priority'][priority['name']]
else:
jira_priorities[priority['id']] = priority['name']
self.jira_priorities = jira_priorities
info = server.jira1.getServerInfo(auth)
self.jira_baseurl = info['baseUrl']
except xmlrpclib.Error, v:
print "XMLRPC ERROR: ", v
def _ticket_lookup(self, ticket):
server = xmlrpclib.ServerProxy(self.config.jira_baseurl)
print self.config.jira_baseurl
try:
auth = server.jira1.login(self.config.jira_username, self.config.jira_password)
info = server.jira1.getIssue(auth, ticket)
print info
return info
except xmlrpclib.Error, v:
print "XMLRPC ERROR:", v
return None
def ticket_lookup(self, ticket):
"""docstring for ticket_lookup"""
info = _ticket_lookup(self, ticket)
if info:
self.say( "%s: Summary: %s" % (info['key'], info['summary']))
if info.has_key('assignee'):
self.say( "%s: Assigned To: %s" % (info['key'], info['assignee']))
else:
self.say( "%s: Assigned To: Unassigned" % (info['key']))
data = (info["key"], self.jira_priorities[info['priority']], self.jira_statuses[info['status']], self.jira_baseurl, info["key"])
self.say( "%s: Priority: %s, Status: %s, %s/browse/%s" % data)
def f_jira(phenny, input):
"""JIRA stuff"""
if not input.sender in phenny.config.jira_channels and not input.owner:
return
for ticket in phenny.jira_re.findall(input.bytes):
if ticket not in recent_tickets or recent_tickets[ticket] < time.time() - min_age:
recent_tickets[ticket] = time.time()
ticket_lookup(phenny, ticket)
f_jira.priority = 'low'
def f_jiratoac(phenny, input):
"""docstring for f_jiratoac"""
ticket = input.group(2)
info = _ticket_lookup(phenny, ticket)
#if info:
# project = modules.activecollab.current_project(phenny, input.sender)
# if project:
# summary = '(%s) %s' % (ticket, info['summary'])
# js = modules.activecollab.create_ticket(phenny, project, summary)
# phenny.say('Created ticket %s-%s: %s' % (project, js['id'], js['permalink']))
f_jiratoac.commands = [ 'jiratoac' ]
f_jiratoac.priority = 'medium'
def f_search_confluence(self, input):
print "Wiki search", input
query = input.group(1)
if not input.sender in self.config.jira_channels and not input.owner:
return
server = xmlrpclib.ServerProxy(self.config.confluence_baseurl)
rpc = server.confluence1
auth = rpc.login(self.config.confluence_username, self.config.confluence_password)
results = rpc.search(auth, query, self.config.confluence_searchresults)
self.say ("%s results found. Note: Results limited to %s" % (len(results), self.config.confluence_searchresults))
for page in results[:self.config.confluence_searchresults]:
self.say ('"%s": %s' % (page["title"], shorten(page["url"])))
f_search_confluence.rule = r'^\!wiki (.*)'
f_search_confluence.priority = "medium"
f_search_confluence.thread = True
def setup(self):
get_status(self)
re_str = r'((?:' + '|'.join(self.config.jira_projects) + ')-(?:\d+))'
self.jira_re = re.compile(re_str)
f_jira.rule = r'.*' + re_str