Partially implement buildstatus and importtry commands dev
authorGregory Szorc <gps@mozilla.com>
Sun, 21 Jul 2013 15:32:09 -0700
branchdev
changeset 6 4d42074f926e1a5eefb933f5d4f02856c5f3a6a1
parent 5 2f22bb1317c2b62a257edd1d5de381e63f8b8902
push id1
push usergszorc@mozilla.com
push dateSun, 21 Jul 2013 22:40:54 +0000
Partially implement buildstatus and importtry commands
__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -146,8 +146,95 @@ def pushtree(ui, repo, tree=None, rev=No
     from mozautomation.repository import resolve_trees_to_uris
 
     tree, uri = resolve_trees_to_uris([tree], write_access=True)[0]
 
     if not uri:
         raise util.Abort("Don't know about tree %s" % tree)
 
     return push(ui, repo, rev=rev, dest=uri)
+
+
+@command('importtry',
+    [('d', 'dest', 'tip', _('destination'), _('DEST'))],
+    _('hg importtry REV'))
+def importtry(ui, repo, rev=None, dest=None, **opts):
+    """Import patches from a try push into this repository.
+
+    A changeset from a try push is specified. The patches from this changeset
+    that don't chain up to the current tip's ancestors (excluding the
+    trychooser changeset itself) are imported into the current branch of this
+    repository.
+    """
+    if not rev:
+        raise util.Abort('Must specifiy a revision or changeset to import.')
+
+    from mozautomation.repository import resolve_trees_to_uris
+
+    tree, uri = resolve_trees_to_uris(['try'])[0]
+
+    peer = hg.peer(repo, {}, uri)
+    remote_head = peer.lookup(rev)
+    local_head = repo.lookup(dest)
+
+    tr = repo.transaction('importtry')
+
+    try:
+        result = repo.pull(peer, heads=[remote_head])
+        import pdb; pdb.set_trace()
+    finally:
+        tr.abort()
+
+@command('buildstatus',
+    [('t', 'tree', '', _('tree'), _('TREE'))],
+    _('hg buildstatus [-t TREE] REV'))
+def buildstatus(ui, repo, rev=None, tree=None, **opts):
+    """Show the build status of a revision.
+
+    This command looks up the build status of a particular revision in
+    Mozilla's automation infrastructure and shows results.
+
+    Because changesets may exist in multiple repositories, the user must
+    specify the tree whose build status to query.
+    """
+    if not tree:
+        raise util.Abort(_('You must specify a tree.'))
+
+    if not rev:
+        raise util.Abort(_('You must specify a revision to look up.'))
+
+    from mozautomation.buildstatus import BuildStatusClient
+    from mozautomation.repository import (
+        MercurialRepository,
+        resolve_trees_to_official,
+        resolve_trees_to_uris,
+    )
+
+    # A lot of this logic should probably live in an importable Python
+    # module...
+    tree, repo_url = resolve_trees_to_uris([tree])[0]
+
+    if not repo_url:
+        raise util.Abort("Don't know about tree %s" % tree)
+
+    official = resolve_trees_to_official([tree])[0]
+    node = repo[rev].hex()
+
+    r = MercurialRepository(repo_url)
+    push = r.push_info_for_changeset(node)
+
+    if not push:
+        raise util.Abort("Could not find push info for changeset %s" % node)
+
+    push_node = push.last_node
+
+    client = BuildStatusClient()
+    builds = client.revision_builds(official, push_node)
+
+    fm = ui.formatter('buildstatus', opts)
+
+    for job in sorted(builds.jobs):
+        label = 'buildstatus.%s' % job.result
+
+        fm.startitem()
+        fm.write('job', '%s\n', job.builder_name, label=label)
+
+    fm.end()