Skip to content

Commit

Permalink
Support for megaplan.ru
Browse files Browse the repository at this point in the history
Requires python-megaplan to work; if not installed, megaplan won't be
supported.
  • Loading branch information
umonkey committed Dec 10, 2012
1 parent c39eda9 commit 392b8c9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bugwarrior/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ def get_owner(self, issue):
}


try:
from mplan import MegaplanService
SERVICES['megaplan'] = MegaplanService
except ImportError:
pass


def aggregate_issues(conf):
""" Return all issues from every target.
Expand Down
60 changes: 60 additions & 0 deletions bugwarrior/services/mplan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
from twiggy import log

from bugwarrior.services import IssueService
from bugwarrior.config import die

import datetime
import urllib2
import json

import megaplan


class MegaplanService(IssueService):
def __init__(self, *args, **kw):
super(MegaplanService, self).__init__(*args, **kw)

self.hostname = self.config.get(self.target, 'hostname')
_login = self.config.get(self.target, 'login')
_password = self.config.get(self.target, 'password')

self.client = megaplan.Client(self.hostname)
self.client.authenticate(_login, _password)

self.project_name = self.hostname
if self.config.has_option(self.target, "project_name"):
self.project_name = self.config.get(self.target, "project_name")

@classmethod
def validate_config(cls, config, target):
for k in ('login', 'password', 'hostname'):
if not config.has_option(target, k):
die("[%s] has no '%s'" % (target, k))

IssueService.validate_config(config, target)

def get_issue_id(self, issue):
if issue["Id"] > 1000000:
return issue["Id"] - 1000000
return issue["Id"]

def get_issue_title(self, issue):
parts = issue["Name"].split("|")
return parts[-1].strip()

def get_issue_url(self, issue):
return "https://%s/%s/card/" % (self.hostname, issue["Id"])

def issues(self):
issues = self.client.get_actual_tasks()
log.debug(" Found {0} total.", len(issues))

return [dict(
description=self.description(
self.get_issue_title(issue),
self.get_issue_url(issue),
self.get_issue_id(issue), cls="issue",
),
project=self.project_name,
priority=self.default_priority,
) for issue in issues]

0 comments on commit 392b8c9

Please sign in to comment.