Skip to content
This repository was archived by the owner on Nov 26, 2018. It is now read-only.

Commit 8456ebc

Browse files
committed
Add support for JIRA
1 parent 6c96051 commit 8456ebc

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

botbot_plugins/plugins/jira.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import requests
2+
import json
3+
from urlparse import urljoin
4+
from .. import config
5+
from ..base import BasePlugin
6+
from ..decorators import listens_to_all, listens_to_mentions
7+
8+
9+
10+
class Config(config.BaseConfig):
11+
jira_link = config.Field(help_text="Jira Link, eg: 'https://tickets.metabrainz.org'", default="https://tickets.metabrainz.org")
12+
rest_api_suffix = config.Field(help_text="Suffix for the Jira REST API, eg: 'rest/api/2/project'", default="rest/api/2/project")
13+
14+
class Plugin(BasePlugin):
15+
"""
16+
Jira issue lookup
17+
18+
Returns the description of a Jira Issue
19+
20+
jira:{{projectname}}-{{issuenumber}}
21+
"""
22+
config_class = Config
23+
24+
@listens_to_all(ur'(?:.*)\b(?P<project>\w+)-(?P<issue>\d+)\b(?:.*)')
25+
def issue_lookup(self, line, project, issue):
26+
"""Lookup a specified jira issue
27+
28+
Usage:
29+
Just mention the issue by its {{ISSUENAME}}
30+
Eg:
31+
Can you please checkup on PROJECT-123
32+
"""
33+
34+
api_url = urljoin(self.config['jira_link'], self.config['rest_api_suffix'])
35+
projects = json.loads(self.retrieve('projects'))
36+
if project.upper() in projects:
37+
38+
issue_url = urljoin(api_url,"issue/{}-{}".format(project.upper(),(issue)))
39+
response = requests.get(issue_url)
40+
if response.status_code == 200:
41+
response_text = json.loads(response.text)
42+
name = response_text['key']
43+
desc = response_text['fields']['summary']
44+
return_url = urljoin(self.config['jira_link'],"projects/{}/issues/{}".format(project,name))
45+
return "{}: {}\n{}".format(name,desc,return_url)
46+
else:
47+
return "Th' servers be not reachable matey, give a go' again later"
48+
49+
@listens_to_mentions(ur'UPDATE:JIRA')
50+
def update_projects(self, line):
51+
"""Updates projects list
52+
53+
Usage:
54+
Ping the botbot with the command:
55+
UPDATE:JIRA
56+
"""
57+
58+
api_url = urljoin(self.config['jira_link'], self.config['rest_api_suffix'])
59+
project_url = urljoin(api_url, 'project')
60+
response = requests.get(project_url)
61+
if response.status_code == 200:
62+
projects = [project['key'] for project in json.loads(response.text)]
63+
self.store('projects', json.dumps(projects))
64+
return "Successfully updated projects list"
65+
return "Could not update projects list"
66+
67+
68+
69+

0 commit comments

Comments
 (0)