Skip to content

Commit

Permalink
Pull requests are in now too. Fixes #3.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Dec 17, 2011
1 parent 998a409 commit 028f4c1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 20 deletions.
11 changes: 9 additions & 2 deletions bugwarrior/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ def validate_config(cls, config, target):
# TODO -- general validation
pass

def description(self, title, url):
def description(self, title, url, number, cls="issue"):
cls_markup = {
'issue': 'Is',
'pull_request': 'PR',
}
# TODO -- get the '35' here from the config.
return "%s %s .. %s" % (MARKUP, title[:35], self.shorten(url))
return "%s%s#%i - %s .. %s" % (
MARKUP, cls_markup[cls], number,
title[:35], self.shorten(url)
)

def include(self, issue):
""" Return true if the issue in question should be included """
Expand Down
5 changes: 4 additions & 1 deletion bugwarrior/services/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def issues(self):
issues = filter(self.include, issues)

return [{
"description": self.description(issue['title'], issue['url']),
"description": self.description(
issue['title'], issue['url'],
issue['local_id'], cls="issue",
),
"project": tag.split('/')[1],
"priority": self.priorities.get(issue['priority'], 'M'),
} for tag, issue in issues]
34 changes: 27 additions & 7 deletions bugwarrior/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,48 @@ def __init__(self, *args, **kw):
self.ghc = github2.client.Github()

@rate_limit(limit_amount=60, limit_period=60)
def pull(self, tag):
def _issues(self, tag):
""" Grab all the issues """
return [(tag, i) for i in self.ghc.issues.list(tag)]

@rate_limit(limit_amount=60, limit_period=60)
def _reqs(self, tag):
""" Grab all the pull requests """
return [(tag, i) for i in self.ghc.pull_requests.list(tag)]

def get_owner(self, issue):
# Currently unimplemented for github-proper
# See validate_config(...) below.
return None

def issues(self):
user = self.config.get(self.target, 'username')
all_repos = self.ghc.repos.list(user)

# First get and prune all the real issues
has_issues = lambda repo: repo.has_issues and repo.open_issues > 0
repos = filter(has_issues, self.ghc.repos.list(user))

issues = sum([self.pull(user + "/" + r.name) for r in repos], [])

repos = filter(has_issues, all_repos)
issues = sum([self._issues(user + "/" + r.name) for r in repos], [])
issues = filter(self.include, issues)

# Next, get all the pull requests (and don't prune)
has_requests = lambda repo: repo.forks > 1
repos = filter(has_requests, all_repos)
requests = sum([self._reqs(user + "/" + r.name) for r in repos], [])

return [{
"description": self.description(issue.title, issue.html_url),
"description": self.description(
issue.title, issue.html_url,
issue.number, cls="issue"
),
"project": tag.split('/')[1],
} for tag, issue in issues] + [{
"description" : self.description(
request.title, request.html_url,
request.number, cls="pull_request"
),
"project": tag.split('/')[1],
} for tag, issue in issues]
} for tag, request in requests]


@classmethod
Expand Down
6 changes: 5 additions & 1 deletion bugwarrior/services/trac.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ def issues(self):
# Build a url for each issue
for i in range(len(issues)):
issues[i][1]['url'] = "%s/ticket/%i" % (base_url, tickets[i][0])
issues[i][1]['number'] = tickets[i][0]

issues = filter(self.include, issues)

return [{
"description": self.description(issue['summary'], issue['url']),
"description": self.description(
issue['summary'], issue['url'],
issue['number'], cls="issue",
),
"project": tag,
"priority": self.priorities.get(issue['priority'], 'M'),
} for tag, issue in issues]
16 changes: 8 additions & 8 deletions bugwarrior/util.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import time
from decorator import decorator


class rate_limit(object):
""" API Rate Throttling decorator """
def __init__(self, limit_amount, limit_period):
self.limit_amount = limit_amount
self.limit_period = limit_period
self.start = time.time()
self.counter = 0
rate_limit.start = time.time()
rate_limit.counter = 0

def __call__(self, func):
def _rate_limit(*args, **kw):
if time.time() - self.start > self.limit_period:
self.start, self.counter = time.time(), 0
if time.time() - rate_limit.start > self.limit_period:
rate_limit.start, rate_limit.counter = time.time(), 0

self.counter += 1
rate_limit.counter += 1

if self.counter == self.limit_amount - 1:
duration = self.limit_period - (time.time() - self.start) + 1
if rate_limit.counter == self.limit_amount - 1:
duration = self.limit_period - \
(time.time() - rate_limit.start) + 1
print "Expected to exceed API rate limit."
print "Sleeping for", duration, "seconds."
time.sleep(duration)
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
zip_safe=False,
install_requires=[
"bitlyapi",
"decorator",
"github2",
"offtrac",
"taskw>=0.1.6",
Expand Down

0 comments on commit 028f4c1

Please sign in to comment.