2
2
import json
3
3
from urlparse import urljoin
4
4
from .. import config
5
- from ..base import BasePlugin
5
+ from ..base import BasePlugin , DummyLine
6
6
from ..decorators import listens_to_all , listens_to_mentions
7
7
8
8
9
9
10
10
class Config (config .BaseConfig ):
11
- jira_link = config .Field (help_text = "Jira Link, eg: 'https://tickets.metabrainz.org'" )
11
+ jira_url = config .Field (help_text = "Jira Link, eg: 'https://tickets.metabrainz.org'" )
12
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
+ bot_name = config .Field (help_text = "Name of your bot, eg: BrainzBot" )
13
14
14
15
class Plugin (BasePlugin ):
15
16
"""
@@ -21,13 +22,6 @@ class Plugin(BasePlugin):
21
22
"""
22
23
config_class = Config
23
24
24
- def __init__ (self , * args , ** kwargs ):
25
- """Initializes plugin and fetches projects list""
26
-
27
- super(Plugin, self).__init__(self, *args, **kwargs)
28
- update_projects(self, None)
29
-
30
-
31
25
@listens_to_all (ur'(?:.*)\b(?P<project>\w+)-(?P<issue>\d+)\b(?:.*)' )
32
26
def issue_lookup (self , line , project , issue ):
33
27
"""Lookup a specified jira issue
@@ -38,35 +32,35 @@ def issue_lookup(self, line, project, issue):
38
32
Can you please checkup on PROJECT-123
39
33
"""
40
34
41
- api_url = urljoin(self.config['jira_link '], self.config['rest_api_suffix'])
35
+ api_url = urljoin (self .config ['jira_url ' ], self .config ['rest_api_suffix' ])
42
36
projects = json .loads (self .retrieve ('projects' ))
43
- if project.upper() in projects:
44
-
37
+ if project .upper () in projects and line .user != self .config ['bot_name' ]:
45
38
issue_url = urljoin (api_url ,"issue/{}-{}" .format (project .upper (),(issue )))
46
39
response = requests .get (issue_url )
47
40
if response .status_code == 200 :
48
41
response_text = json .loads (response .text )
49
42
name = response_text ['key' ]
50
43
desc = response_text ['fields' ]['summary' ]
51
- return_url = urljoin(self.config['jira_link '],"projects/{}/issues/{}".format(project,name))
44
+ return_url = urljoin (self .config ['jira_url ' ],"projects/{}/issues/{}" .format (project ,name ))
52
45
return "{}: {}\n {}" .format (name ,desc ,return_url )
53
46
else :
54
47
return "Th' servers be not reachable matey, give a go' again later"
55
48
56
- @listens_to_mentions(ur'UPDATE :JIRA')
49
+ @listens_to_mentions (ur'(.*)\bUPDATE :JIRA' )
57
50
def update_projects (self , line ):
58
- """ Updates projects list
51
+ """Updates projects list on mentioning the bot with the command
59
52
60
53
Usage:
61
54
Ping the botbot with the command:
62
55
UPDATE:JIRA
63
56
"""
64
-
65
- api_url = urljoin(self.config['jira_link'], self.config['rest_api_suffix'])
57
+ api_url = urljoin (self .config ['jira_url' ], self .config ['rest_api_suffix' ])
66
58
project_url = urljoin (api_url , 'project' )
67
59
response = requests .get (project_url )
68
60
if response .status_code == 200 :
69
61
projects = [project ['key' ] for project in json .loads (response .text )]
70
62
self .store ('projects' , json .dumps (projects ))
71
63
return "Successfully updated projects list"
72
64
return "Could not update projects list"
65
+
66
+
0 commit comments