-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
53 lines (40 loc) · 1.86 KB
/
main.py
File metadata and controls
53 lines (40 loc) · 1.86 KB
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
import logging
import os
from jirabuddy.bot import SlackBot
from jirabuddy.clients import GitLabClient
from jirabuddy.clients import JiraClient
from jirabuddy.common import enum, FreeTextParser, Configuration
APP_NAME = "colo"
# This is disgusting, but the easiest way to allow dynamic plugins without messing with impotlib
# Will fix this later.
def init_slackbot_plugins(config):
exec(open(config.bot.plugins_path).read())
def main():
config = enum("config", nest=True, **Configuration(APP_NAME).parse())
ftxtp = FreeTextParser()
ftxtp.ignore("on", "for", "to", "in")
slackbot = SlackBot(config.slack.token,
debug=bool(int(os.environ.get("DEBUG", 0))),
plugins_cache_path=config.bot.plugins_cache_path)
if "jira" in config.enum_names:
jira_client = JiraClient(config.jira.server,
config.jira.username,
config.jira.password,
default_project=config.jira.default_project)
slackbot.register("jira", jira_client)
ftxtp.register("jira_project", jira_client.Projects.get)
ftxtp.register("jira_component", jira_client.Components.get)
ftxtp.register("jira_ticket_type", jira_client.TicketTypes.get)
ftxtp.register("jira_priority", jira_client.Priorities.get)
ftxtp.register("jira_fix_version", jira_client.FixVersions.get)
if "gitlab" in config.enum_names and config.gitlab.server:
gitlab_client = GitLabClient(config.gitlab.server,
config.gitlab.token)
slackbot.register("gitlab", gitlab_client)
ftxtp.register("slack_user", slackbot.find_user)
slackbot.register("text_parser", ftxtp)
init_slackbot_plugins(config)
logging.info("Starting!")
slackbot.run()
if __name__ == "__main__":
main()