From c62dbc0e27f3eafd3b2ed8c210cb5c42d68f0596 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Tue, 8 Apr 2014 19:43:32 -0700 Subject: [PATCH] Also gather issues directly-assigned to a user, regardless of whether the originating repository is owned by the user. --- bugwarrior/services/github.py | 40 +++++++++++++++++++++++------- bugwarrior/services/githubutils.py | 8 ++++++ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/bugwarrior/services/github.py b/bugwarrior/services/github.py index 9c0eb1686..473e6964b 100644 --- a/bugwarrior/services/github.py +++ b/bugwarrior/services/github.py @@ -1,5 +1,7 @@ -from jinja2 import Template +import re import six + +from jinja2 import Template from twiggy import log from bugwarrior.config import asbool, die, get_service_password @@ -152,12 +154,27 @@ def get_service_metadata(self): 'label_template': self.label_template, } - def _issues(self, tag): + def get_owned_repo_issues(self, tag): """ Grab all the issues """ - return [ - (tag, i) for i in - githubutils.get_issues(*tag.split('/'), auth=self.auth) - ] + issues = {} + for issue in githubutils.get_issues(*tag.split('/'), auth=self.auth): + issues[issue['url']] = (tag, issue) + return issues + + def get_directly_assigned_issues(self): + project_matcher = re.compile( + r'.*/repos/(?P[^/]+)/(?P[^/]+)/.*' + ) + issues = {} + for issue in githubutils.get_directly_assigned_issues(auth=self.auth): + match_dict = project_matcher.match(issue['url']).groupdict() + issues[issue['url']] = ( + '{owner}/{project}'.format( + **match_dict + ), + issue + ) + return issues def _comments(self, tag, number): user, repo = tag.split('/') @@ -213,11 +230,16 @@ def issues(self): all_repos = githubutils.get_repos(username=user, auth=self.auth) assert(type(all_repos) == list) - repos = filter(self.filter_repos_for_issues, all_repos) - issues = sum([self._issues(user + "/" + r['name']) for r in repos], []) + + issues = {} + for repo in repos: + issues.update( + self.get_owned_repo_issues(user + "/" + repo['name']) + ) + issues.update(self.get_directly_assigned_issues()) log.name(self.target).debug(" Found {0} total.", len(issues)) - issues = filter(self.include, issues) + issues = filter(self.include, issues.values()) log.name(self.target).debug(" Pruned down to {0}", len(issues)) # Next, get all the pull requests (and don't prune) diff --git a/bugwarrior/services/githubutils.py b/bugwarrior/services/githubutils.py index b0e688f4e..bd9c4b5f2 100644 --- a/bugwarrior/services/githubutils.py +++ b/bugwarrior/services/githubutils.py @@ -44,6 +44,14 @@ def get_issues(username, repo, auth): return _getter(url, auth) +def get_directly_assigned_issues(auth): + """ username and repo should be strings + auth should be a tuple of username and password. + """ + url = "https://api.github.com/user/issues?per_page=100" + return _getter(url, auth) + + def get_comments(username, repo, number, auth): tmpl = "https://api.github.com/repos/{username}/{repo}/issues/" + \ "{number}/comments?per_page=100"