Patchwork [2,of,2] releasenotes: add custom admonitions support for release notes

login
register
mail settings
Submitter Rishabh Madan
Date June 29, 2017, 10:57 p.m.
Message ID <9674e42ec8aac0f4f0d2.1498777046@bunty>
Download mbox | patch
Permalink /patch/21846/
State Superseded
Headers show

Comments

Rishabh Madan - June 29, 2017, 10:57 p.m.
# HG changeset patch
# User Rishabh Madan <rishabhmadan96@gmail.com>
# Date 1498776526 -7200
#      Fri Jun 30 00:48:46 2017 +0200
# Node ID 9674e42ec8aac0f4f0d237c6270b38ace21d5d52
# Parent  9f7c675413ffce1497c7db3ff1495e4050b151d6
releasenotes: add custom admonitions support for release notes

By default, the extension has default sections like fix, feature, perf etc.. This
patch allow user to add support for custom admonition. In order to add a custom
admonition, one needs to add a [customsections] config to .hgrc file. All the
custom directive with name specified under this tag will be usable by the extension.
Pulkit Goyal - June 30, 2017, 6:40 p.m.
On Fri, Jun 30, 2017 at 4:27 AM, Rishabh Madan <rishabhmadan96@gmail.com> wrote:
> # HG changeset patch
> # User Rishabh Madan <rishabhmadan96@gmail.com>
> # Date 1498776526 -7200
> #      Fri Jun 30 00:48:46 2017 +0200
> # Node ID 9674e42ec8aac0f4f0d237c6270b38ace21d5d52
> # Parent  9f7c675413ffce1497c7db3ff1495e4050b151d6
> releasenotes: add custom admonitions support for release notes
>
> By default, the extension has default sections like fix, feature, perf etc.. This
> patch allow user to add support for custom admonition. In order to add a custom
> admonition, one needs to add a [customsections] config to .hgrc file. All the
> custom directive with name specified under this tag will be usable by the extension.
>
> diff -r 9f7c675413ff -r 9674e42ec8aa hgext/releasenotes.py
> --- a/hgext/releasenotes.py     Thu Jun 29 23:30:03 2017 +0200
> +++ b/hgext/releasenotes.py     Fri Jun 30 00:48:46 2017 +0200
> @@ -112,8 +112,12 @@
>
>  class releasenotessections(object):
>      def __init__(self, ui):
> -        # TODO support defining custom sections from config.
> -        self._sections = list(DEFAULT_SECTIONS)
> +        self.ui = ui
> +        CUSTOM_SECTIONS = ui.configitems('customsections')
> +        if CUSTOM_SECTIONS:
> +            self._sections = list(DEFAULT_SECTIONS) + list(CUSTOM_SECTIONS)
> +        else:
> +            self._sections = list(DEFAULT_SECTIONS)
>
>      def __iter__(self):
>          return iter(self._sections)
> diff -r 9f7c675413ff -r 9674e42ec8aa tests/test-releasenotes-formatting.t
> --- a/tests/test-releasenotes-formatting.t      Thu Jun 29 23:30:03 2017 +0200
> +++ b/tests/test-releasenotes-formatting.t      Fri Jun 30 00:48:46 2017 +0200
> @@ -324,3 +324,30 @@
>
>    * Short summary of fix 2
>
> +Using custom admonition in notes
> +
> +  $ cat >> $HGRCPATH << EOF
> +  > [extensions]
> +  > releasenotes=
> +  >
> +  > [customsections]
> +  > testsection=Name of Section
> +  > EOF

Can we name this more extension specific like [releasenotes.sections]
or something similar. Also the custom sections should override default
sections. For example, someone might like to expand api to be
something different or bc to something different.

Also, maybe we can support regexes in custom sections part. That's
just an idea and I am not sure if that will be much useful.
Yuya Nishihara - July 3, 2017, 1:17 p.m.
On Sat, 1 Jul 2017 00:10:50 +0530, Pulkit Goyal wrote:
> On Fri, Jun 30, 2017 at 4:27 AM, Rishabh Madan <rishabhmadan96@gmail.com> wrote:
> > # HG changeset patch
> > # User Rishabh Madan <rishabhmadan96@gmail.com>
> > # Date 1498776526 -7200
> > #      Fri Jun 30 00:48:46 2017 +0200
> > # Node ID 9674e42ec8aac0f4f0d237c6270b38ace21d5d52
> > # Parent  9f7c675413ffce1497c7db3ff1495e4050b151d6
> > releasenotes: add custom admonitions support for release notes
> >
> > By default, the extension has default sections like fix, feature, perf etc.. This
> > patch allow user to add support for custom admonition. In order to add a custom
> > admonition, one needs to add a [customsections] config to .hgrc file. All the
> > custom directive with name specified under this tag will be usable by the extension.
> >
> > diff -r 9f7c675413ff -r 9674e42ec8aa hgext/releasenotes.py
> > --- a/hgext/releasenotes.py     Thu Jun 29 23:30:03 2017 +0200
> > +++ b/hgext/releasenotes.py     Fri Jun 30 00:48:46 2017 +0200
> > @@ -112,8 +112,12 @@
> >
> >  class releasenotessections(object):
> >      def __init__(self, ui):
> > -        # TODO support defining custom sections from config.
> > -        self._sections = list(DEFAULT_SECTIONS)
> > +        self.ui = ui
> > +        CUSTOM_SECTIONS = ui.configitems('customsections')
> > +        if CUSTOM_SECTIONS:
> > +            self._sections = list(DEFAULT_SECTIONS) + list(CUSTOM_SECTIONS)
> > +        else:
> > +            self._sections = list(DEFAULT_SECTIONS)
> >
> >      def __iter__(self):
> >          return iter(self._sections)
> > diff -r 9f7c675413ff -r 9674e42ec8aa tests/test-releasenotes-formatting.t
> > --- a/tests/test-releasenotes-formatting.t      Thu Jun 29 23:30:03 2017 +0200
> > +++ b/tests/test-releasenotes-formatting.t      Fri Jun 30 00:48:46 2017 +0200
> > @@ -324,3 +324,30 @@
> >
> >    * Short summary of fix 2
> >
> > +Using custom admonition in notes
> > +
> > +  $ cat >> $HGRCPATH << EOF
> > +  > [extensions]
> > +  > releasenotes=
> > +  >
> > +  > [customsections]
> > +  > testsection=Name of Section
> > +  > EOF
> 
> Can we name this more extension specific like [releasenotes.sections]
> or something similar. Also the custom sections should override default
> sections. For example, someone might like to expand api to be
> something different or bc to something different.

Maybe this isn't a per-user thing, but tied with a repository (like .hgtag
or .hgeol) ?
Rishabh Madan - July 3, 2017, 1:32 p.m.
On Mon, Jul 3, 2017 at 3:17 PM, Yuya Nishihara <yuya@tcha.org> wrote:

> On Sat, 1 Jul 2017 00:10:50 +0530, Pulkit Goyal wrote:
> > On Fri, Jun 30, 2017 at 4:27 AM, Rishabh Madan <rishabhmadan96@gmail.com>
> wrote:
> > > # HG changeset patch
> > > # User Rishabh Madan <rishabhmadan96@gmail.com>
> > > # Date 1498776526 -7200
> > > #      Fri Jun 30 00:48:46 2017 +0200
> > > # Node ID 9674e42ec8aac0f4f0d237c6270b38ace21d5d52
> > > # Parent  9f7c675413ffce1497c7db3ff1495e4050b151d6
> > > releasenotes: add custom admonitions support for release notes
> > >
> > > By default, the extension has default sections like fix, feature, perf
> etc.. This
> > > patch allow user to add support for custom admonition. In order to add
> a custom
> > > admonition, one needs to add a [customsections] config to .hgrc file.
> All the
> > > custom directive with name specified under this tag will be usable by
> the extension.
> > >
> > > diff -r 9f7c675413ff -r 9674e42ec8aa hgext/releasenotes.py
> > > --- a/hgext/releasenotes.py     Thu Jun 29 23:30:03 2017 +0200
> > > +++ b/hgext/releasenotes.py     Fri Jun 30 00:48:46 2017 +0200
> > > @@ -112,8 +112,12 @@
> > >
> > >  class releasenotessections(object):
> > >      def __init__(self, ui):
> > > -        # TODO support defining custom sections from config.
> > > -        self._sections = list(DEFAULT_SECTIONS)
> > > +        self.ui = ui
> > > +        CUSTOM_SECTIONS = ui.configitems('customsections')
> > > +        if CUSTOM_SECTIONS:
> > > +            self._sections = list(DEFAULT_SECTIONS) +
> list(CUSTOM_SECTIONS)
> > > +        else:
> > > +            self._sections = list(DEFAULT_SECTIONS)
> > >
> > >      def __iter__(self):
> > >          return iter(self._sections)
> > > diff -r 9f7c675413ff -r 9674e42ec8aa tests/test-releasenotes-
> formatting.t
> > > --- a/tests/test-releasenotes-formatting.t      Thu Jun 29 23:30:03
> 2017 +0200
> > > +++ b/tests/test-releasenotes-formatting.t      Fri Jun 30 00:48:46
> 2017 +0200
> > > @@ -324,3 +324,30 @@
> > >
> > >    * Short summary of fix 2
> > >
> > > +Using custom admonition in notes
> > > +
> > > +  $ cat >> $HGRCPATH << EOF
> > > +  > [extensions]
> > > +  > releasenotes=
> > > +  >
> > > +  > [customsections]
> > > +  > testsection=Name of Section
> > > +  > EOF
> >
> > Can we name this more extension specific like [releasenotes.sections]
> > or something similar. Also the custom sections should override default
> > sections. For example, someone might like to expand api to be
> > something different or bc to something different.
>
> Maybe this isn't a per-user thing, but tied with a repository (like .hgtag
> or .hgeol) ?
>

Yeah you're right. This is something limited to the repository.
All the users contributing to it will probably need to have a common
understanding about the custom sections to be used in notes.
Pulkit Goyal - July 3, 2017, 5:42 p.m.
On Mon, Jul 3, 2017 at 11:06 PM, Kevin Bullock
<kbullock+mercurial@ringworld.org> wrote:
>> On Jul 3, 2017, at 08:17, Yuya Nishihara <yuya@tcha.org> wrote:
>>
>> On Sat, 1 Jul 2017 00:10:50 +0530, Pulkit Goyal wrote:
>>> On Fri, Jun 30, 2017 at 4:27 AM, Rishabh Madan <rishabhmadan96@gmail.com> wrote:
>>>> # HG changeset patch
>>>> # User Rishabh Madan <rishabhmadan96@gmail.com>
>>>> # Date 1498776526 -7200
>>>> #      Fri Jun 30 00:48:46 2017 +0200
>>>> # Node ID 9674e42ec8aac0f4f0d237c6270b38ace21d5d52
>>>> # Parent  9f7c675413ffce1497c7db3ff1495e4050b151d6
>>>> releasenotes: add custom admonitions support for release notes
>>>>
>
> [...]
>
>>> Can we name this more extension specific like [releasenotes.sections]
>>> or something similar. Also the custom sections should override default
>>> sections. For example, someone might like to expand api to be
>>> something different or bc to something different.
>>
>> Maybe this isn't a per-user thing, but tied with a repository (like .hgtag
>> or .hgeol) ?

Yeah I agree with you.

> Rishabh and I had discussed this a bit on IRC, and I noted that e.g. the keyword extension keeps custom keyword settings in the hgrc. So I'm not sure whether this should be per-repo or per-user, but my first instinct was the same as yours: that it should travel along with the repo.
>
> If it does land in config, then per-project settings could always be %include'd into the repo's .hg/hgrc.

Yeah that sounds good, I was thinking something along this only.
Yuya Nishihara - July 4, 2017, 1:15 p.m.
On Mon, 3 Jul 2017 12:36:23 -0500, Kevin Bullock wrote:
> > On Jul 3, 2017, at 08:17, Yuya Nishihara <yuya@tcha.org> wrote:
> > Maybe this isn't a per-user thing, but tied with a repository (like .hgtag
> > or .hgeol) ?
> 
> Rishabh and I had discussed this a bit on IRC, and I noted that e.g. the keyword extension keeps custom keyword settings in the hgrc. So I'm not sure whether this should be per-repo or per-user, but my first instinct was the same as yours: that it should travel along with the repo.
> 
> If it does land in config, then per-project settings could always be %include'd into the repo's .hg/hgrc.

I think %include-ing repo contents should be discouraged, which can do
anything dangerous, such as inserting alias.log=!sudo rm -Rf --no-preserve-root /.

Using config syntax sounds good.

Patch

diff -r 9f7c675413ff -r 9674e42ec8aa hgext/releasenotes.py
--- a/hgext/releasenotes.py	Thu Jun 29 23:30:03 2017 +0200
+++ b/hgext/releasenotes.py	Fri Jun 30 00:48:46 2017 +0200
@@ -112,8 +112,12 @@ 
 
 class releasenotessections(object):
     def __init__(self, ui):
-        # TODO support defining custom sections from config.
-        self._sections = list(DEFAULT_SECTIONS)
+        self.ui = ui
+        CUSTOM_SECTIONS = ui.configitems('customsections')
+        if CUSTOM_SECTIONS:
+            self._sections = list(DEFAULT_SECTIONS) + list(CUSTOM_SECTIONS)
+        else:
+            self._sections = list(DEFAULT_SECTIONS)
 
     def __iter__(self):
         return iter(self._sections)
diff -r 9f7c675413ff -r 9674e42ec8aa tests/test-releasenotes-formatting.t
--- a/tests/test-releasenotes-formatting.t	Thu Jun 29 23:30:03 2017 +0200
+++ b/tests/test-releasenotes-formatting.t	Fri Jun 30 00:48:46 2017 +0200
@@ -324,3 +324,30 @@ 
   
   * Short summary of fix 2
 
+Using custom admonition in notes
+
+  $ cat >> $HGRCPATH << EOF
+  > [extensions]
+  > releasenotes=
+  > 
+  > [customsections]
+  > testsection=Name of Section
+  > EOF
+
+  $ hg init custom-section
+  $ cd custom-section
+  $ touch a
+  $ hg -q commit -A -l - << EOF
+  > commit 1
+  > 
+  > .. testsection::
+  > 
+  >    First paragraph under this admonition.
+  > EOF
+
+  $ hg releasenotes -r . $TESTTMP/relnotes-custom-section
+  $ cat $TESTTMP/relnotes-custom-section
+  Name of Section
+  ===============
+  
+  * First paragraph under this admonition.