[hgext] make show-review able to display apycot test results (closes #291045)

authorDavid Douard <david.douard@logilab.fr>
changeset4faee6b99eda
branchdefault
phasepublic
hiddenno
parent revision#14ef7fa10b4e [hgext] add a new "start-test" command (closes #290804)
child revision#d63bb50841c7 [hgext] make-ticket: allow to specify the type of ticket (bug, task ot enhancement)
files modified by this revision
hgext/jpl/__init__.py
hgext/jpl/review.py
# HG changeset patch
# User David Douard <david.douard@logilab.fr>
# Date 1428920378 -7200
# Mon Apr 13 12:19:38 2015 +0200
# Node ID 4faee6b99eda0d99830516f79f0fc4862555312d
# Parent 14ef7fa10b4e8513400acbe62bc281421cf77b4e
[hgext] make show-review able to display apycot test results (closes #291045)

diff --git a/hgext/jpl/__init__.py b/hgext/jpl/__init__.py
@@ -255,13 +255,15 @@
1 
2      with build_proxy(ui, opts) as client:
3          ask_review(client, ctxhexs)
4          ui.write('OK\n')
5 
6 +
7  @command('^show-review', [
8      ('r', 'rev', [], _('show review status for the given revision(s)'), _('REV')),
9      ('c', 'committer', '', _('login of the committer in JPL forge'), _('LOGIN')),
10 +    ('T', 'test-results', False, _('show test results for each changeset'), ),
11      ]  + cnxopts,
12      _('[OPTION]... [-r] REV...'))
13  def showreview(ui, repo, *changesets, **opts):
14      """show review status for patches corresponding to specified revisions
15 
@@ -273,27 +275,40 @@
16      if not changesets:
17          changesets = ('.')
18      revs = scmutil.revrange(repo, changesets)
19      if not revs:
20          raise util.Abort(_('no working directory: please specify a revision'))
21 -    ctxhexs = (node.short(repo.lookup(rev)) for rev in revs)
22 +    ctxhexs = [node.short(repo.lookup(rev)) for rev in revs]
23 
24      committer = opts.get('committer', None)
25 
26      with build_proxy(ui, opts) as client:
27          rev = show_review(client, ctxhexs, committer)
28 -        _format_review_result(ui, rev)
29 +        if opts.get('test_results'):
30 +            rql = ('Any TCN, ST WHERE TE status ST, TE using_revision REV, '
31 +                   'REV changeset %(cset)s, '
32 +                   'TE using_config TC, TC name TCN')
33 +            queries = [(rql, dict(cset=cset)) for cset in ctxhexs]
34 +            test_results = dict(zip(ctxhexs, client.rqlio(queries)))
35 +        else:
36 +            test_results = None
37 +        _format_review_result(ui, rev, test_results)
38 
39 -def _format_review_result(ui, revs):
40 +        
41 +def _format_review_result(ui, revs, test_results=None):
42      """Display a formatted patch review list"""
43      for pname, eid, rid, status, victims in  rev:
44          uri = client.buildurl(str(eid))
45          ui.write("{0}".format(uri), label='jpl.cwuri')
46          ui.write(" {0}".format(rid))
47          ui.write("\t[{0}]".format(status), label='jpl.status.{0}'.format(status))
48          ui.write("\t{0}\n".format(victims), label='jpl.reviewers')
49          ui.write(pname.encode('utf-8') + '\n\n')
50 +        if test_results:
51 +            for tcn, st in test_results.get(rid, []):
52 +                ui.write('#{} {}: {}\n'.format(rid, tcn, st))
53 +
54 
55  @command('^backlog', [
56      ('c', 'committer', '', _('login of the committer in JPL forge'), _('LOGIN')),
57      ]  + cnxopts,
58      _('[OPTION]... -c LOGIN'))
@@ -335,10 +350,11 @@
59 
60      with build_proxy(ui, opts) as client:
61          assign(client, ctxhexs, committer)
62          ui.write('OK\n')
63 
64 +
65  @command('^make-ticket', [
66      ('r', 'rev', [], _('create a ticket for the given revision'), _('REV')),
67      ('d', 'done-in', '', _('new ticket should be marked as done in this version'), _('VERSION')),
68      ] + cnxopts,
69      _('[OPTION]... [-d VERSION] [-r] REV'))
@@ -353,11 +369,11 @@
70          raise util.Abort(_('no working directory: please specify a revision'))
71 
72      with build_proxy(ui, opts) as client:
73          for rev in revs:
74              ticket = sudo_make_me_a_ticket(client, repo, rev, opts.get('done_in', ''))
75 -            ui.write("{0} {1}\n".format(rev, ticket[0][0]))
76 +            ui.write("{0} {1}\n".format(rev, ticket[0][0] if ticket[0] else 'FAILED'))
77 
78 
79  @command('^start-test', [
80      ('r', 'rev', [], _('start apycot tests on the given revision(s)'), _('REV')),
81      ('l', 'label', 'quick python tests', _("the TestConfig's label to execute"), _('LABEL')),
diff --git a/hgext/jpl/review.py b/hgext/jpl/review.py
@@ -6,29 +6,41 @@
82  enc = sys.stdout.encoding or 'ascii'
83 
84  from cwclientlib import builders
85  from .jplproxy import build_proxy
86 
87 +
88  def ask_review(client, revs):
89      eids = client.rql(
90          '''Any P WHERE P patch_revision R, R changeset IN ({revs}),
91                         P in_state S, S name 'in-progress'
92          '''.format(revs=','.join('%r'%rev for rev in revs)))
93      queries = [builders.build_trinfo(eid[0], 'ask review') for eid in eids]
94      return client.rqlio(queries)
95 
96 +
97  def show_review(client, revs, committer=None):
98 -    query = '''Any PN, P, C, N, GROUP_CONCAT(L) GROUPBY PN,P,C,N WHERE
99 -                P patch_revision R, R changeset IN ({revs}), P in_state S,
100 -                S name N, P patch_name PN, P patch_reviewer U?,
101 -                U login L, R changeset C'''
102 +    query = '''\
103 +Any PN, P, CSET, N, GROUP_CONCAT(L), GROUP_CONCAT(CSET) GROUPBY PN,P,CET,N
104 +WHERE
105 +  P patch_revision R,
106 +  R changeset IN ({revs}),
107 +  R changeset CSET,
108 +  P in_state S,
109 +  S name N,
110 +  P cwuri URI,
111 +  P patch_name PN,
112 +  P patch_reviewer U?,
113 +  U login L
114 +'''
115      fmt = {'revs': ','.join('%r' % rev for rev in revs)}
116      if committer:
117          query += ', P patch_committer PC, PC login "{committer}"'
118          fmt['committer'] = committer
119      return client.rqlio([(query.format(**fmt), {})])[0]
120 
121 +
122  def assign(client, revs, committer):
123      """Assign patches corresponding to specified revisions to specified committer.
124      """
125      revstr = ','.join('%r'%rev for rev in revs)
126      if revstr.count(',') > 0:
@@ -39,10 +51,11 @@
127                                               R changeset {revq},
128                                               U login '{login}'
129              '''.format(revq=revq, login=committer)
130      return client.rqlio([(query, {})])[0]
131 
132 +
133  def sudo_make_me_a_ticket(client, repo, rev, version):
134      query = '''INSERT Ticket T: T concerns PROJ, T title %%(title)s, T description %%(desc)s%s
135                 WHERE REV from_repository REPO, PROJ source_repository REPO, REV changeset %%(cs)s%s'''
136      if version:
137          query %= (', T done_in V', ', V num %(version)s, V version_of PROJ')