--- a/testing/mozharness/mozharness/base/vcs/mercurial.py
+++ b/testing/mozharness/mozharness/base/vcs/mercurial.py
@@ -8,24 +8,26 @@
Largely copied/ported from
https://hg.mozilla.org/build/tools/file/cf265ea8fb5e/lib/python/util/hg.py .
"""
import os
import re
import subprocess
+from collections import namedtuple
from urlparse import urlsplit
import sys
sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.dirname(sys.path[0]))))
from mozharness.base.errors import HgErrorList, VCSException
from mozharness.base.log import LogMixin
from mozharness.base.script import ScriptMixin
+from mozharness.base.transfer import TransferMixin
HG_OPTIONS = ['--config', 'ui.merge=internal:merge']
# MercurialVCS {{{1
# TODO Make the remaining functions more mozharness-friendly.
# TODO Add the various tag functionality that are currently in
# build/tools/scripts to MercurialVCS -- generic tagging logic belongs here.
REVISION, BRANCH = 0, 1
@@ -45,17 +47,17 @@ def make_hg_url(hg_host, repo_path, prot
return repo
else:
return '/'.join([p.strip('/') for p in [repo, 'rev', revision]])
else:
assert revision
return '/'.join([p.strip('/') for p in [repo, 'raw-file', revision, filename]])
-class MercurialVCS(ScriptMixin, LogMixin, object):
+class MercurialVCS(ScriptMixin, LogMixin, TransferMixin):
# For the most part, scripts import mercurial, update,
# hgtool uses mercurial, share, out
# tag-release.py imports
# apply_and_push, update, get_revision, out, BRANCH, REVISION,
# get_branches, cleanOutgoingRevs
def __init__(self, log_obj=None, config=None, vcs_config=None,
script_obj=None):
@@ -527,12 +529,47 @@ class MercurialVCS(ScriptMixin, LogMixin
# TODO retry
self.info("Wiping outgoing local changes from %s to %s." % (reponame, remote))
outgoingRevs = self.out(src=reponame, remote=remote,
ssh_username=username, ssh_key=sshKey)
for r in reversed(outgoingRevs):
self.run_command(self.hg + ['strip', '-n', r[REVISION]],
cwd=reponame, error_list=HgErrorList)
+ def query_pushinfo(self, 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:
+ url = '%s/json-pushes?changeset=%s' % (repository, revision)
+ self.info('Pushdate URL is: %s' % url)
+ contents = self.retry(self.load_json_from_url, args=(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()
+ self.info('Pushid is: %s' % pushid)
+ pushdate = contents[pushid]['date']
+ self.info('Pushdate is: %s' % pushdate)
+ return PushInfo(pushid, pushdate)
+
+ except Exception:
+ self.exception("Failed to get push info from hg.mozilla.org")
+ raise
+
# __main__ {{{1
if __name__ == '__main__':
pass