[hgext] Add an "assign" command to set the patch_committer relation

authorDenis Laxalde <denis.laxalde@logilab.fr>
changeset36bb0fde105d
branchdefault
phasepublic
hiddenno
parent revision#5bed420e8c98 Added tag logilab-devtools-version-0.24.0, logilab-devtools-debian-version-0.24.0-1 for changeset 17078cc48fc0
child revision#95661d1adaaa [hgext/show-review] use ${base_url}/${eid} instead of ${cwuri}, #9e84f6f7eb27 [hgext] Allow show-review command to filter by committer login, #b9b62110d271 [hgext/show-review] use ${base_url}/${eid} instead of ${cwuri}
files modified by this revision
hgext/jpl/__init__.py
hgext/jpl/review.py
# HG changeset patch
# User Denis Laxalde <denis.laxalde@logilab.fr>
# Date 1426151886 -3600
# Thu Mar 12 10:18:06 2015 +0100
# Node ID 36bb0fde105d7f9ce6aad55227781f9e81616de7
# Parent 5bed420e8c98b098494c596239ff7a3b0624c69e
[hgext] Add an "assign" command to set the patch_committer relation

diff --git a/hgext/jpl/__init__.py b/hgext/jpl/__init__.py
@@ -54,11 +54,11 @@
1  except AttributeError:
2      enabled = demandimport._import is __import__
3  demandimport.disable()
4  from .jplproxy import build_proxy, RequestError
5  from .tasks import print_tasks
6 -from .review import ask_review, show_review, sudo_make_me_a_ticket
7 +from .review import ask_review, show_review, sudo_make_me_a_ticket, assign
8  if enabled:
9      demandimport.enable()
10 
11  cmdtable = {}
12  command = cmdutil.command(cmdtable)
@@ -297,10 +297,37 @@
13              ui.write("{0}".format(uri), label='jpl.cwuri')
14              ui.write("\t[{0}]".format(status), label='jpl.status.{0}'.format(status))
15              ui.write("\t{0}\n".format(victims), label='jpl.reviewers')
16              ui.write(pname.encode('utf-8') + '\n\n')
17 
18 +@command('^assign', [
19 +    ('r', 'rev', [], _('revision(s) indentifying patch(es) to be assigned to committer'), _('REV')),
20 +    ('c', 'committer', '', _('login of the committer in JPL forge'), _('LOGIN')),
21 +    ]  + cnxopts,
22 +    _('[OPTION]... [-r] REV... -c LOGIN'))
23 +def patch_assign(ui, repo, *changesets, **opts):
24 +    """Assign patches corresponding to specified revisions to a committer.
25 +
26 +    By default, the revision used is the parent of the working
27 +    directory: use -r/--rev to specify a different revision.
28 +    """
29 +    changesets += tuple(opts.get('rev', []))
30 +    if not changesets:
31 +        changesets = ('.')
32 +    revs = scmutil.revrange(repo, changesets)
33 +    if not revs:
34 +        raise util.Abort(_('no working directory: please specify a revision'))
35 +    ctxhexs = (node.short(repo.lookup(rev)) for rev in revs)
36 +
37 +    committer = opts.get('committer', None)
38 +    if not committer:
39 +        raise util.Abort(_('unspecified committer login (-c LOGIN)'))
40 +
41 +    with build_proxy(ui, opts) as client:
42 +        assign(client, ctxhexs, committer)
43 +        ui.write('OK\n')
44 +
45  @command('^make-ticket', [
46      ('r', 'rev', [], _('create a ticket for the given revision'), _('REV')),
47      ('d', 'done-in', '', _('new ticket should be marked as done in this version'), _('VERSION')),
48      ] + cnxopts,
49      _('[OPTION]... [-d VERSION] [-r] REV'))
diff --git a/hgext/jpl/review.py b/hgext/jpl/review.py
@@ -20,10 +20,24 @@
50      return client.rqlio([(
51          '''Any PN, URI, N, GROUP_CONCAT(L) GROUPBY PN,URI,N WHERE P patch_revision R, R changeset IN ({revs}),
52               P in_state S, S name N, P cwuri URI, P patch_name PN, P patch_reviewer U?, U login L
53          '''.format(revs=','.join('%r' % rev for rev in revs)), {}),])[0]
54 
55 +def assign(client, revs, committer):
56 +    """Assign patches corresponding to specified revisions to specified committer.
57 +    """
58 +    revstr = ','.join('%r'%rev for rev in revs)
59 +    if revstr.count(',') > 0:
60 +        revq = 'IN ({revs})'.format(revs=revstr)
61 +    else:
62 +        revq = revstr
63 +    query = '''SET P patch_committer U WHERE P patch_revision R,
64 +                                             R changeset {revq},
65 +                                             U login '{login}'
66 +            '''.format(revq=revq, login=committer)
67 +    return client.rqlio([(query, {})])[0]
68 +
69  def sudo_make_me_a_ticket(client, repo, rev, version):
70      query = '''INSERT Ticket T: T concerns PROJ, T title %%(title)s, T description %%(desc)s%s
71                 WHERE REV from_repository REPO, PROJ source_repository REPO, REV changeset %%(cs)s%s'''
72      if version:
73          query %= (', T done_in V', ', V num %(version)s, V version_of PROJ')