Skip to content

Commit

Permalink
Also gather issues directly-assigned to a user, regardless of whether…
Browse files Browse the repository at this point in the history
… the originating repository is owned by the user.
  • Loading branch information
coddingtonbear committed Apr 9, 2014
1 parent 15f678e commit c62dbc0
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
40 changes: 31 additions & 9 deletions bugwarrior/services/github.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<owner>[^/]+)/(?P<project>[^/]+)/.*'
)
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('/')
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions bugwarrior/services/githubutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit c62dbc0

Please sign in to comment.