Bug 1212942 - Add pushdate routes; r=garndt,jlund

This commit is contained in:
Mike Shal
2015-10-09 09:26:34 -04:00
parent fb4dc843c6
commit 7ae5d4a284
5 changed files with 69 additions and 0 deletions

View File

@@ -11,6 +11,8 @@ import os
import json
import copy
import sys
import time
from collections import namedtuple
from mach.decorators import (
CommandArgument,
@@ -203,6 +205,44 @@ def remove_caches_from_task(task):
except KeyError:
pass
def query_pushinfo(repository, revision):
"""Query the pushdate and pushid of a repository/revision.
This is intended to be used on hg.mozilla.org/mozilla-central and
similar. It may or may not work for other hg repositories.
"""
PushInfo = namedtuple('PushInfo', ['pushid', 'pushdate'])
try:
import urllib2
url = '%s/json-pushes?changeset=%s' % (repository, revision)
sys.stderr.write("Querying URL for pushdate: %s\n" % url)
contents = json.load(urllib2.urlopen(url))
# The contents should be something like:
# {
# "28537": {
# "changesets": [
# "1d0a914ae676cc5ed203cdc05c16d8e0c22af7e5",
# ],
# "date": 1428072488,
# "user": "user@mozilla.com"
# }
# }
#
# So we grab the first element ("28537" in this case) and then pull
# out the 'date' field.
pushid = contents.iterkeys().next()
pushdate = contents[pushid]['date']
return PushInfo(pushid, pushdate)
except Exception:
sys.stderr.write(
"Error querying pushinfo for repository '%s' revision '%s'\n" % (
repository, revision,
)
)
return None
@CommandProvider
class DecisionTask(object):
@Command('taskcluster-decision', category="ci",
@@ -333,6 +373,12 @@ class Graph(object):
cmdline_interactive = params.get('interactive', False)
# Default to current time if querying the head rev fails
pushdate = time.strftime('%Y%m%d%H%M%S', time.gmtime())
pushinfo = query_pushinfo(params['head_repository'], params['head_rev'])
if pushinfo:
pushdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(pushinfo.pushdate))
# Template parameters used when expanding the graph
parameters = dict(gaia_info().items() + {
'index': 'index',
@@ -344,6 +390,10 @@ class Graph(object):
'head_repository': params['head_repository'],
'head_ref': params['head_ref'] or params['head_rev'],
'head_rev': params['head_rev'],
'pushdate': pushdate,
'year': pushdate[0:4],
'month': pushdate[4:6],
'day': pushdate[6:8],
'owner': params['owner'],
'from_now': json_time_from_now,
'now': current_json_time(),