comparison tests/test-bugzilla.t @ 28950:9e1c9f016b72

bugzilla: do not load style file if template is specified (BC) This prepares for the API change to support template aliases. I'm going to extract a factory function of templater that reads a map file: # original templater(mapfile, ..., cache, ...) # new templater.frommapfile(mapfile, ...) # read mapfile to build cache/map templater(..., cache, ...) # use specified cache (= map elements) This will make it clear to isolate stock styles (i.e. map files) from user aliases. Template aliases should be applied to command arguments and templates in hgrc, but not to map files. Otherwise, our stock styles and web templates could be modified unintentionally. This patch makes sure that either "tmpl" or "mapfile" is exclusively set. It's theoretically a behavior change, since you could put new keywords in template by defining them in a map file before: # mapfile foo = "{rev}" # hgrc [bugzilla] style = mapfile template = {foo} But the old behavior would be a bug because bugzilla.template is documented as "overrides style if specified". Also, common log-like templates and formatter doesn't allow using mapfile-keywords in a separate template. So I decided to make a BC. Since there was no test for the bugzilla extension, this adds new test that covers style/template output.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 04 Apr 2016 22:48:34 +0900
parents
children 22c53b3a390d
comparison
equal deleted inserted replaced
28949:9d3e280864fb 28950:9e1c9f016b72
1 mock bugzilla driver for testing template output:
2
3 $ cat <<EOF > bzmock.py
4 > from __future__ import absolute_import
5 > from mercurial import extensions
6 >
7 > def extsetup(ui):
8 > bugzilla = extensions.find('bugzilla')
9 > class bzmock(bugzilla.bzaccess):
10 > def __init__(self, ui):
11 > super(bzmock, self).__init__(ui)
12 > self._logfile = ui.config('bugzilla', 'mocklog')
13 > def updatebug(self, bugid, newstate, text, committer):
14 > with open(self._logfile, 'a') as f:
15 > f.write('update bugid=%r, newstate=%r, committer=%r\n'
16 > % (bugid, newstate, committer))
17 > f.write('----\n' + text + '\n----\n')
18 > def notify(self, bugs, committer):
19 > with open(self._logfile, 'a') as f:
20 > f.write('notify bugs=%r, committer=%r\n'
21 > % (bugs, committer))
22 > bugzilla.bugzilla._versions['mock'] = bzmock
23 > EOF
24
25 set up mock repository:
26
27 $ hg init mockremote
28 $ cat <<EOF > mockremote/.hg/hgrc
29 > [extensions]
30 > bugzilla =
31 > bzmock = $TESTTMP/bzmock.py
32 >
33 > [bugzilla]
34 > version = mock
35 > mocklog = $TESTTMP/bzmock.log
36 >
37 > [hooks]
38 > incoming.bugzilla = python:hgext.bugzilla.hook
39 >
40 > [web]
41 > baseurl=http://example.org/hg
42 >
43 > %include $TESTTMP/bzstyle.hgrc
44 > EOF
45
46 $ hg clone -q mockremote mocklocal
47
48 push with default template:
49
50 $ echo '[bugzilla]' > bzstyle.hgrc
51 $ echo foo > mocklocal/foo
52 $ hg ci -R mocklocal -Aqm 'Fixes bug 123'
53 $ hg -R mocklocal push -q
54 $ cat bzmock.log && rm bzmock.log
55 update bugid=123, newstate={}, committer='test'
56 ----
57 changeset 7875a8342c6f in repo $TESTTMP/mockremote refers to bug 123.
58 details:
59 Fixes bug 123
60 ----
61 notify bugs={123: {}}, committer='test'
62
63 push with style:
64
65 $ cat <<EOF > bzstyle.map
66 > changeset = "{node|short} refers to bug {bug}."
67 > EOF
68 $ echo "style = $TESTTMP/bzstyle.map" >> bzstyle.hgrc
69 $ echo foo >> mocklocal/foo
70 $ hg ci -R mocklocal -qm 'Fixes bug 456'
71 $ hg -R mocklocal push -q
72 $ cat bzmock.log && rm bzmock.log
73 update bugid=456, newstate={}, committer='test'
74 ----
75 2808b172464b refers to bug 456.
76 ----
77 notify bugs={456: {}}, committer='test'
78
79 push with template (overrides style):
80
81 $ cat <<EOF >> bzstyle.hgrc
82 > template = Changeset {node|short} in {root|basename}.
83 > {hgweb}/rev/{node|short}\n
84 > {desc}
85 > EOF
86 $ echo foo >> mocklocal/foo
87 $ hg ci -R mocklocal -qm 'Fixes bug 789'
88 $ hg -R mocklocal push -q
89 $ cat bzmock.log && rm bzmock.log
90 update bugid=789, newstate={}, committer='test'
91 ----
92 Changeset a770f3e409f2 in mockremote.
93 http://example.org/hg/rev/a770f3e409f2
94
95 Fixes bug 789
96 ----
97 notify bugs={789: {}}, committer='test'