github: let backend drive the requests
This commit is contained in:
parent
c696cfa086
commit
d91dc46a87
2 changed files with 115 additions and 71 deletions
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.tools.value import Value, ValueBackendPassword
|
||||
from weboob.capabilities.bugtracker import ICapBugTracker, Issue
|
||||
from weboob.capabilities.bugtracker import ICapBugTracker, Issue, Project, User, Version, Status, Update, Attachment
|
||||
|
||||
from .browser import GithubBrowser
|
||||
|
||||
|
|
@ -28,6 +28,10 @@ from .browser import GithubBrowser
|
|||
__all__ = ['GithubBackend']
|
||||
|
||||
|
||||
STATUSES = {'open': Status('open', u'Open', Status.VALUE_NEW),
|
||||
'closed': Status('closed', u'closed', Status.VALUE_RESOLVED)}
|
||||
# TODO tentatively parse github "labels"?
|
||||
|
||||
class GithubBackend(BaseBackend, ICapBugTracker):
|
||||
NAME = 'github'
|
||||
DESCRIPTION = u'GitHub issues tracking'
|
||||
|
|
@ -49,10 +53,20 @@ class GithubBackend(BaseBackend, ICapBugTracker):
|
|||
return self.create_browser(username, password)
|
||||
|
||||
def get_project(self, _id):
|
||||
return self.browser.get_project(_id)
|
||||
d = self.browser.get_project(_id)
|
||||
|
||||
project = Project(_id, d['name'])
|
||||
project.members = list(self._iter_members(project.id))
|
||||
project.statuses = list(STATUSES.values())
|
||||
project.categories = []
|
||||
project.versions = list(self._iter_versions(project.id))
|
||||
|
||||
return project
|
||||
|
||||
def get_issue(self, _id):
|
||||
return self.browser.get_issue(_id)
|
||||
project_id, issue_number = _id.rsplit('/', 1)
|
||||
project = self.get_project(project_id)
|
||||
return self._make_issue(self.browser.get_issue(project_id, issue_number), project)
|
||||
|
||||
def iter_issues(self, query):
|
||||
if ((query.assignee, query.author, query.status, query.title) ==
|
||||
|
|
@ -61,12 +75,14 @@ class GithubBackend(BaseBackend, ICapBugTracker):
|
|||
else:
|
||||
it = self.browser.iter_issues(query)
|
||||
|
||||
for issue in it:
|
||||
project = self.get_project(query.project)
|
||||
for d in it:
|
||||
issue = self._make_issue(d, project)
|
||||
yield issue
|
||||
|
||||
def create_issue(self, project_id):
|
||||
issue = Issue(0)
|
||||
issue.project = self.browser.get_project(project_id)
|
||||
issue.project = self.get_project(project_id)
|
||||
return issue
|
||||
|
||||
def post_issue(self, issue):
|
||||
|
|
@ -79,3 +95,61 @@ class GithubBackend(BaseBackend, ICapBugTracker):
|
|||
|
||||
# iter_projects, remove_issue are impossible
|
||||
|
||||
def _iter_members(self, project_id):
|
||||
for d in self.browser.iter_members(project_id):
|
||||
yield User(d['id'], d['name'])
|
||||
|
||||
def _iter_versions(self, project_id):
|
||||
for d in self.browser.iter_milestones(project_id):
|
||||
yield Version(d['id'], d['name'])
|
||||
|
||||
def _make_issue(self, d, project):
|
||||
_id = '%s/%s' % (project.id, d['number'])
|
||||
issue = Issue(_id)
|
||||
issue.project = project
|
||||
issue.title = d['title']
|
||||
issue.body = d['body']
|
||||
issue.creation = d['creation']
|
||||
issue.updated = d['updated']
|
||||
issue.author = project.find_user(d['author'], None)
|
||||
if not issue.author:
|
||||
# may duplicate users
|
||||
issue.author = User(d['author'], d['author'])
|
||||
issue.status = STATUSES[d['status']]
|
||||
|
||||
if d['assignee']:
|
||||
issue.assignee = project.find_user(d['assignee'], None)
|
||||
else:
|
||||
issue.assignee = None
|
||||
|
||||
if d['version']:
|
||||
issue.version = project.find_version(d['version'], None)
|
||||
else:
|
||||
issue.version = None
|
||||
|
||||
issue.category = None
|
||||
|
||||
issue.attachments = [self._make_attachment(dattach) for dattach in d['attachments']]
|
||||
|
||||
issue.history = []
|
||||
issue.history += [self._make_comment(dcomment, project) for dcomment in d['comments']]
|
||||
|
||||
return issue
|
||||
|
||||
def _make_attachment(self, d):
|
||||
a = Attachment(d['url'])
|
||||
a.url = d['url']
|
||||
a.filename = d['filename']
|
||||
return a
|
||||
|
||||
def _make_comment(self, d, project):
|
||||
u = Update(d['id'])
|
||||
u.message = d['message']
|
||||
u.author = project.find_user(d['author'], None)
|
||||
if not u.author:
|
||||
# may duplicate users
|
||||
u.author = User(d['author'], d['author'])
|
||||
u.date = d['date']
|
||||
u.changes = []
|
||||
u.attachments = [self._make_attachment(dattach) for dattach in d['attachments']]
|
||||
return u
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue