hgext: add --topic option to conduitstage command to speficy a topic to update (
bug 1353193). r?davidwalsh
MozReview-Commit-ID: 8SKdbqItGWL
--- a/hgext/conduit-client/client.py
+++ b/hgext/conduit-client/client.py
@@ -31,19 +31,20 @@ VERSION = '0.0.1'
testedwith = '4.0'
minimumhgversion = '4.0'
cmdtable = {}
command = cmdutil.command(cmdtable)
@command('conduitstage',
[('d', 'drafts', None,
_('Stage the current commit and its draft ancestors.')),
- ('r', 'rev', '', _('Specify the revision set to stage'))],
- _('[-d] [-r REV] remote_url'))
-def conduitstage(ui, repo, remote_url, rev=None, drafts=False):
+ ('r', 'rev', '', _('Specify the revision set to stage')),
+ ('t', 'topic', '', _('Specify the topic to update'))],
+ _('[-d] [-r REV] [-t TOPIC] remote_url'))
+def conduitstage(ui, repo, remote_url, drafts=False, rev=None, topic=None):
"""Stages a series of commits as a new Topic Iteration
Requests the remote repo server to create a new iteration on a topic using
a list of ids of the commits and the user's bugzilla api credentials.
Use http://localhost:77777 for the remote_url to test the happy path, this
is temporary until we setup integration tests with the server extension.
"""
bz_username = ui.config('bugzilla', 'username', None)
@@ -56,19 +57,19 @@ def conduitstage(ui, repo, remote_url, r
if not rev and not drafts:
raise util.Abort(
_('no revision specified and --drafts unset.'),
hint=_('use either the --rev flag or --drafts flag'))
revset = rev if rev else '.'
nodes = get_commits(ui, repo, revset, drafts)
- ids = [repo[node].hex() for node in nodes]
+ commit_ids = [repo[node].hex() for node in nodes]
- stage(ui, remote_url, bz_username, bz_apikey, ids)
+ stage(ui, remote_url, bz_username, bz_apikey, commit_ids, topic)
def get_commits(ui, repo, revset, include_drafts):
"""Creates a list of commit ids given a revision set.
Creates a list containing the full 40 character ids of the commits in
the given revset sorted by their order in the commit graph. If only one
commit is in the revset and include_drafts is true, returns a list of
all commit ids from the earliest non-public ancestor of the commit
@@ -139,17 +140,17 @@ def get_commits(ui, repo, revset, includ
ctx = repo[node]
if not ctx.files():
raise util.Abort(
_('cannot review empty commit %s') % ctx.hex()[:12],
hint=_('add files to or remove commit'))
return nodes
-def stage(ui, remote_url, bz_username, bz_apikey, commit_ids):
+def stage(ui, remote_url, bz_username, bz_apikey, commit_ids, topic):
"""Performs the request to stage the commits creating a new iteration."""
try:
out = conduitclient.stage(remote_url, bz_username, bz_apikey,
- commit_ids)
+ commit_ids, topic)
ui.status(_(out))
except Exception as e:
raise util.Abort(
_('Failed to publish changes to remote server: %s' % e.message))
--- a/hgext/conduit-client/tests/test-basics.t
+++ b/hgext/conduit-client/tests/test-basics.t
@@ -12,101 +12,108 @@ Requires a bugzilla username to be set
$ hg conduitstage -r 0 http://localhost:77777
abort: bugzilla username or apikey not present in .hgrc config
(make sure that a username and apikey are set in the bugzilla section of your .hgrc config)
[255]
Set bugzilla username
$ cat >> $HGRCPATH << EOF
> [bugzilla]
- > username = nobody@mozilla.org
+ > username = mozillian@example.com
> EOF
Requires a bugzilla apikey to be set
$ hg conduitstage -r 0 http://localhost:77777
abort: bugzilla username or apikey not present in .hgrc config
(make sure that a username and apikey are set in the bugzilla section of your .hgrc config)
[255]
Set bugzilla apikey
$ cat >> $HGRCPATH << EOF
> apikey = fakeapikey0
> EOF
The magic happy path works
$ hg conduitstage -r 0 http://localhost:77777
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
fe1507847927ea10fbd79bc4821fa4fb34ea1282
The argument order doesn't matter
$ hg conduitstage http://localhost:77777 -r 0
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
fe1507847927ea10fbd79bc4821fa4fb34ea1282
Add two new commits
$ echo 'foo1' > foo
$ hg -q commit -A -m '2nd commit'
$ echo 'foo2' > foo
$ hg -q commit -A -m '3rd commit'
Publishes only the given commit, no ancestors
$ hg conduitstage -r 2 http://localhost:77777
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
cb0b9488cd76939275b57aefa675a390c752fab2
Publishes the current commit if given '.'
$ hg conduitstage -r . http://localhost:77777
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
cb0b9488cd76939275b57aefa675a390c752fab2
Publishes the current commit and ancestors if -d is given, but -r is not
$ hg conduitstage -d http://localhost:77777
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
fe1507847927ea10fbd79bc4821fa4fb34ea1282
372194518d2b158d172f98ec436c85e73a3625e4
cb0b9488cd76939275b57aefa675a390c752fab2
Publishes the commit 1 and ancestors if -d is given and -r is 1
$ hg conduitstage -d -r 1 http://localhost:77777
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
fe1507847927ea10fbd79bc4821fa4fb34ea1282
372194518d2b158d172f98ec436c85e73a3625e4
Publishes the commits in the revision range, entire tree
$ hg conduitstage -r 0::2 http://localhost:77777
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
fe1507847927ea10fbd79bc4821fa4fb34ea1282
372194518d2b158d172f98ec436c85e73a3625e4
cb0b9488cd76939275b57aefa675a390c752fab2
Publishes the commits in the revision range, subset of tree
$ hg conduitstage -r 1::2 http://localhost:77777
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
372194518d2b158d172f98ec436c85e73a3625e4
cb0b9488cd76939275b57aefa675a390c752fab2
Publishes the commits in the correct order
$ hg conduitstage -r 2:1 http://localhost:77777
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
372194518d2b158d172f98ec436c85e73a3625e4
cb0b9488cd76939275b57aefa675a390c752fab2
Publishes the commits in the revision range using full ids
$ hg conduitstage -r fe1507847927::cb0b9488cd76 http://localhost:77777
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
fe1507847927ea10fbd79bc4821fa4fb34ea1282
372194518d2b158d172f98ec436c85e73a3625e4
cb0b9488cd76939275b57aefa675a390c752fab2
Publishes only non public commits
$ hg -q update 0
$ hg -q phase --public -r .
$ hg -q update 2
$ hg conduitstage -r 0::2 http://localhost:77777
- Publishing commits for nobody@mozilla.org:
+ Publishing commits for mozillian@example.com:
+ 372194518d2b158d172f98ec436c85e73a3625e4
+ cb0b9488cd76939275b57aefa675a390c752fab2
+
+Publishes to a given topic id
+ $ hg conduitstage -r 0::2 -t test_topic_123 http://localhost:77777
+ Publishing to specific topic: test_topic_123
+ Publishing commits for mozillian@example.com:
372194518d2b158d172f98ec436c85e73a3625e4
cb0b9488cd76939275b57aefa675a390c752fab2
Aborts if neither -r or -d is given
$ hg conduitstage http://localhost:77777
abort: no revision specified and --drafts unset.
(use either the --rev flag or --drafts flag)
[255]
--- a/pylib/conduitclient/conduitclient/__init__.py
+++ b/pylib/conduitclient/conduitclient/__init__.py
@@ -3,32 +3,36 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import requests
MAGIC_TEST_REMOTE_URL = 'http://localhost:77777'
REMOTE_STAGE_ENDPOINT = '/stage'
-def stage(remote_url, bz_username, bz_apikey, commit_ids):
+def stage(remote_url, bz_username, bz_apikey, commit_ids, topic=None):
"""Performs the request to stage the commits creating a new iteration.
Returns a string of output to give to the user, or will raise an
Exception, which may include those from requests.exceptions.
"""
stage_url = remote_url.strip('/') + REMOTE_STAGE_ENDPOINT
output = ''
# Magic URL until we have a better way to test integration with
# the server extension or otherwise can startup a mock server.
# All other URLS go through the full request, response cycle.
if remote_url == MAGIC_TEST_REMOTE_URL:
- output += ('Publishing commits for %s:\n') % bz_username
+ if topic:
+ output += ('Publishing to specific topic: %s\n' % topic)
+
+ output += ('Publishing commits for %s:\n' % bz_username)
for id in commit_ids:
output += '%s\n' % id
return output
else:
response = requests.post(stage_url,
data={'bugzilla_username': bz_username,
'bugzilla_api_key': bz_apikey,
- 'commit_ids': commit_ids},
+ 'commit_ids': commit_ids,
+ 'topic': topic},
timeout=10)
response.raise_for_status()
return response.json()['message']