Chromium Code Reviews| Index: my_activity.py |
| diff --git a/my_activity.py b/my_activity.py |
| index 16d3f7dba4770c620b381233818d5651d2bc88e8..15f4534c2d86a76cd28229a3f72495da6333bda5 100755 |
| --- a/my_activity.py |
| +++ b/my_activity.py |
| @@ -116,13 +116,11 @@ rietveld_instances = [ |
| gerrit_instances = [ |
| { |
| - 'url': 'gerrit.chromium.org', |
| - 'port': 29418, |
| + 'url': 'chromium-review.googlesource.com', |
| 'shorturl': 'crosreview.com', |
| }, |
| { |
| - 'url': 'gerrit-int.chromium.org', |
| - 'port': 29419, |
| + 'url': 'chrome-internal-review.googlesource.com', |
| 'shorturl': 'crosreview.com/i', |
| }, |
| ] |
| @@ -239,6 +237,10 @@ def get_yes_or_no(msg): |
| return False |
| +def datetime_from_gerrit(date_string): |
| + return datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S.%f000') |
| + |
| + |
| def datetime_from_rietveld(date_string): |
| return datetime.strptime(date_string, '%Y-%m-%d %H:%M:%S.%f') |
| @@ -380,20 +382,24 @@ class MyActivity(object): |
| max_age = datetime.today() - self.modified_after |
| max_age = max_age.days * 24 * 3600 + max_age.seconds |
| - # See https://review.openstack.org/Documentation/cmd-query.html |
| + # See https://gerrit-review.googlesource.com/Documentation/rest-api.html |
| # Gerrit doesn't allow filtering by created time, only modified time. |
| user_filter = 'owner:%s' % owner if owner else 'reviewer:%s' % reviewer |
| - gquery_cmd = ['ssh', '-p', str(instance['port']), instance['url'], |
| - 'gerrit', 'query', |
| - '--format', 'JSON', |
| - '--comments', |
| - '--', |
| - '-age:%ss' % str(max_age), |
| - user_filter] |
| - [stdout, _] = subprocess.Popen(gquery_cmd, stdout=subprocess.PIPE, |
| - stderr=subprocess.PIPE).communicate() |
| - issues = str(stdout).split('\n')[:-2] |
| - issues = map(json.loads, issues) |
| + args = 'q=-age:%ss+%s&o=LABELS&o=MESSAGES' % (str(max_age), user_filter) |
|
cjhopman
2013/09/09 21:50:05
use urllib.urlencode to encode parameters if possi
deymo
2013/09/09 22:09:41
Done.
|
| + rest_url = 'https://%s/changes/?%s' % (instance['url'], args) |
| + |
| + req = urllib2.Request(rest_url, headers={'Accept': 'text/plain'}) |
| + try: |
| + response = urllib2.urlopen(req) |
| + stdout = response.read() |
| + except urllib2.HTTPError, e: |
| + print "Looking up %r: %s" % (rest_url, e) |
| + return [] |
| + open('zaraza', 'w').write(stdout) |
|
cjhopman
2013/09/09 21:50:05
?
deymo
2013/09/09 22:09:41
aaagr... I forgot to remove that debug line. Sorry
|
| + # Check that the returned JSON starts with the right marker. |
| + if stdout[0:5] != ")]}'\n": |
| + return [] |
| + issues = json.loads(stdout[5:]) |
| # TODO(cjhopman): should we filter abandoned changes? |
| issues = [self.process_gerrit_issue(instance, issue) for issue in issues] |
| @@ -404,17 +410,17 @@ class MyActivity(object): |
| def process_gerrit_issue(self, instance, issue): |
| ret = {} |
| - ret['review_url'] = issue['url'] |
| + ret['review_url'] = 'http://%s/%s' % (instance['url'], issue['_number']) |
| if 'shorturl' in instance: |
| ret['review_url'] = 'http://%s/%s' % (instance['shorturl'], |
| - issue['number']) |
| + issue['_number']) |
| ret['header'] = issue['subject'] |
| ret['owner'] = issue['owner']['email'] |
| ret['author'] = ret['owner'] |
| - ret['created'] = datetime.fromtimestamp(issue['createdOn']) |
| - ret['modified'] = datetime.fromtimestamp(issue['lastUpdated']) |
| - if 'comments' in issue: |
| - ret['replies'] = self.process_gerrit_issue_replies(issue['comments']) |
| + ret['created'] = datetime_from_gerrit(issue['created']) |
| + ret['modified'] = datetime_from_gerrit(issue['updated']) |
| + if 'messages' in issue: |
| + ret['replies'] = self.process_gerrit_issue_replies(issue['messages']) |
| else: |
| ret['replies'] = [] |
| ret['reviewers'] = set() |
| @@ -426,12 +432,12 @@ class MyActivity(object): |
| @staticmethod |
| def process_gerrit_issue_replies(replies): |
| ret = [] |
| - replies = filter(lambda r: 'email' in r['reviewer'], replies) |
| + replies = filter(lambda r: 'email' in r['author'], replies) |
| for reply in replies: |
| r = {} |
| - r['author'] = reply['reviewer']['email'] |
| - r['created'] = datetime.fromtimestamp(reply['timestamp']) |
| - r['content'] = '' |
| + r['author'] = reply['author']['email'] |
| + r['created'] = datetime_from_gerrit(reply['date']) |
| + r['content'] = reply['message'] |
| ret.append(r) |
| return ret |