Index: my_activity.py |
diff --git a/my_activity.py b/my_activity.py |
index 8468772cf978f41bdc275cdbf935e781b260e203..444851b3f9f9716ca533c758675a6495b0447de2 100755 |
--- a/my_activity.py |
+++ b/my_activity.py |
@@ -42,6 +42,9 @@ import gerrit_util |
import rietveld |
from third_party import upload |
+import auth |
+from third_party import httplib2 |
+ |
try: |
from dateutil.relativedelta import relativedelta # pylint: disable=F0401 |
except ImportError: |
@@ -461,107 +464,51 @@ class MyActivity(object): |
}) |
return ret |
- def google_code_issue_search(self, instance): |
- time_format = '%Y-%m-%dT%T' |
- # See http://code.google.com/p/support/wiki/IssueTrackerAPI |
- # q=<owner>@chromium.org does a full text search for <owner>@chromium.org. |
- # This will accept the issue if owner is the owner or in the cc list. Might |
- # have some false positives, though. |
- |
- # Don't filter normally on modified_before because it can filter out things |
- # that were modified in the time period and then modified again after it. |
- gcode_url = ('https://code.google.com/feeds/issues/p/%s/issues/full' % |
- instance['name']) |
- |
- gcode_data = urllib.urlencode({ |
- 'alt': 'json', |
- 'max-results': '100000', |
- 'q': '%s' % self.user, |
- 'published-max': self.modified_before.strftime(time_format), |
- 'updated-min': self.modified_after.strftime(time_format), |
- }) |
- |
- opener = urllib2.build_opener() |
- if self.google_code_auth_token: |
- opener.addheaders = [('Authorization', 'GoogleLogin auth=%s' % |
- self.google_code_auth_token)] |
- gcode_json = None |
- try: |
- gcode_get = opener.open(gcode_url + '?' + gcode_data) |
- gcode_json = json.load(gcode_get) |
- gcode_get.close() |
- except urllib2.HTTPError, _: |
- print 'Unable to access ' + instance['name'] + ' issue tracker.' |
- |
- if not gcode_json or 'entry' not in gcode_json['feed']: |
- return [] |
- |
- issues = gcode_json['feed']['entry'] |
- issues = map(partial(self.process_google_code_issue, instance), issues) |
- issues = filter(self.filter_issue, issues) |
- issues = sorted(issues, key=lambda i: i['modified'], reverse=True) |
- return issues |
- |
- def process_google_code_issue(self, project, issue): |
- ret = {} |
- ret['created'] = datetime_from_google_code(issue['published']['$t']) |
- ret['modified'] = datetime_from_google_code(issue['updated']['$t']) |
- |
- ret['owner'] = '' |
- if 'issues$owner' in issue: |
- ret['owner'] = issue['issues$owner']['issues$username']['$t'] |
- ret['author'] = issue['author'][0]['name']['$t'] |
- |
- if 'shorturl' in project: |
- issue_id = issue['id']['$t'] |
- issue_id = issue_id[issue_id.rfind('/') + 1:] |
- ret['url'] = 'http://%s/%d' % (project['shorturl'], int(issue_id)) |
- else: |
- issue_url = issue['link'][1] |
- if issue_url['rel'] != 'alternate': |
- raise RuntimeError |
- ret['url'] = issue_url['href'] |
- ret['header'] = issue['title']['$t'] |
- |
- ret['replies'] = self.get_google_code_issue_replies(issue) |
- return ret |
- |
- def get_google_code_issue_replies(self, issue): |
- """Get all the comments on the issue.""" |
- replies_url = issue['link'][0] |
- if replies_url['rel'] != 'replies': |
- raise RuntimeError |
- |
- replies_data = urllib.urlencode({ |
- 'alt': 'json', |
- 'fields': 'entry(published,author,content)', |
+ def project_hosting_issue_search(self, instance): |
+ auth_config = auth.extract_auth_config_from_options(self.options) |
+ authenticator = auth.get_authenticator_for_host( |
+ "https://code.google.com", auth_config) |
Vadim Sh.
2015/06/11 01:37:32
just "code.google.com" here should work too
seanmccullough
2015/06/11 02:05:22
Done.
|
+ http = authenticator.authorize(httplib2.Http()) |
+ url = "https://www.googleapis.com/projecthosting/v2/projects/%s/issues" % ( |
+ instance["name"]) |
+ epoch = datetime.utcfromtimestamp(0) |
+ user_str = '%s@chromium.org' % self.user |
+ |
+ query_data = urllib.urlencode({ |
+ 'maxResults': 10000, |
+ 'q': '%s' % user_str, |
Vadim Sh.
2015/06/11 01:37:31
'q': user_str
seanmccullough
2015/06/11 02:05:22
Done.
|
+ 'publishedMax': '%d' % (self.modified_before - epoch).total_seconds(), |
+ 'updatedMin': '%d' % (self.modified_after - epoch).total_seconds(), |
}) |
- |
- opener = urllib2.build_opener() |
- opener.addheaders = [('Authorization', 'GoogleLogin auth=%s' % |
- self.google_code_auth_token)] |
- try: |
- replies_get = opener.open(replies_url['href'] + '?' + replies_data) |
- except urllib2.HTTPError, _: |
+ url = url + '?' + query_data |
+ _, body = http.request(url) |
Vadim Sh.
2015/06/11 01:37:31
this thing will raise auth.AuthenticationError if
seanmccullough
2015/06/11 02:05:22
Done.
|
+ content = json.loads(body) |
+ if not content: |
+ print "Unable to parse %s response from projecthosting." % ( |
+ instance["name"]) |
return [] |
- replies_json = json.load(replies_get) |
- replies_get.close() |
- return self.process_google_code_issue_replies(replies_json) |
+ issues = [] |
+ if 'items' in content: |
+ items = content['items'] |
+ for item in items: |
+ issue = { |
+ "header": item["title"], |
+ "created": item["published"], |
+ "modified": item["updated"], |
+ "author": item["author"]["name"], |
+ "url": "https://code.google.com/p/%s/issues/detail?id=%s" % ( |
+ instance["name"], item["id"]), |
+ "comments": [] |
+ } |
+ if 'owner' in item: |
+ issue['owner'] = item['owner']['name'] |
+ else: |
+ issue['owner'] = 'None' |
+ if issue['owner'] == user_str or issue['author'] == user_str: |
+ issues.append(issue) |
- @staticmethod |
- def process_google_code_issue_replies(replies): |
- if 'entry' not in replies['feed']: |
- return [] |
- |
- ret = [] |
- for entry in replies['feed']['entry']: |
- e = {} |
- e['created'] = datetime_from_google_code(entry['published']['$t']) |
- e['content'] = entry['content']['$t'] |
- e['author'] = entry['author'][0]['name']['$t'] |
- ret.append(e) |
- return ret |
+ return issues |
def print_heading(self, heading): |
@@ -682,7 +629,7 @@ class MyActivity(object): |
def get_issues(self): |
for project in google_code_projects: |
- self.issues += self.google_code_issue_search(project) |
+ self.issues += self.project_hosting_issue_search(project) |
def print_issues(self): |
if self.issues: |