Skip to content

Commit

Permalink
Merge pull request #114 from coddingtonbear/gather_directly_assigned_…
Browse files Browse the repository at this point in the history
…issues

Also gather issues directly-assigned to a user, regardless of whether th...
  • Loading branch information
ralphbean committed Apr 9, 2014
2 parents 7a4dd8d + fe54aa0 commit 286e92a
Show file tree
Hide file tree
Showing 2 changed files with 43 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
12 changes: 12 additions & 0 deletions bugwarrior/services/githubutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ def get_issues(username, repo, auth):
return _getter(url, auth)


def get_directly_assigned_issues(auth):
""" Returns all issues assigned to authenticated user.
This will return all issues assigned to the authenticated user
regardless of whether the user owns the repositories in which the
issues exist.
"""
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 286e92a

Please sign in to comment.