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

Commit 67df507

Browse files
committed
Fix recursive loop
1 parent 28c9f3a commit 67df507

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

botbot_plugins/plugins/jira.py

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import json
33
from urlparse import urljoin
44
from .. import config
5-
from ..base import BasePlugin
5+
from ..base import BasePlugin, DummyLine
66
from ..decorators import listens_to_all, listens_to_mentions
77

88

99

1010
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'")
1212
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")
1314

1415
class Plugin(BasePlugin):
1516
"""
@@ -21,13 +22,6 @@ class Plugin(BasePlugin):
2122
"""
2223
config_class = Config
2324

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-
3125
@listens_to_all(ur'(?:.*)\b(?P<project>\w+)-(?P<issue>\d+)\b(?:.*)')
3226
def issue_lookup(self, line, project, issue):
3327
"""Lookup a specified jira issue
@@ -38,35 +32,35 @@ def issue_lookup(self, line, project, issue):
3832
Can you please checkup on PROJECT-123
3933
"""
4034

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'])
4236
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']:
4538
issue_url = urljoin(api_url,"issue/{}-{}".format(project.upper(),(issue)))
4639
response = requests.get(issue_url)
4740
if response.status_code == 200:
4841
response_text = json.loads(response.text)
4942
name = response_text['key']
5043
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))
5245
return "{}: {}\n{}".format(name,desc,return_url)
5346
else:
5447
return "Th' servers be not reachable matey, give a go' again later"
5548

56-
@listens_to_mentions(ur'UPDATE:JIRA')
49+
@listens_to_mentions(ur'(.*)\bUPDATE:JIRA')
5750
def update_projects(self, line):
58-
"""Updates projects list
51+
"""Updates projects list on mentioning the bot with the command
5952
6053
Usage:
6154
Ping the botbot with the command:
6255
UPDATE:JIRA
6356
"""
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'])
6658
project_url = urljoin(api_url, 'project')
6759
response = requests.get(project_url)
6860
if response.status_code == 200:
6961
projects = [project['key'] for project in json.loads(response.text)]
7062
self.store('projects', json.dumps(projects))
7163
return "Successfully updated projects list"
7264
return "Could not update projects list"
65+
66+

0 commit comments

Comments
 (0)