[PATCH] releasenotes: add custom admonitions support for release notes
Rishabh Madan
rishabhmadan96 at gmail.com
Fri Jul 7 13:15:56 EDT 2017
Sorry, I forgot to put the v2 flag.
ᐧ
On Fri, Jul 7, 2017 at 7:13 PM, Rishabh Madan <rishabhmadan96 at gmail.com>
wrote:
> # HG changeset patch
> # User Rishabh Madan <rishabhmadan96 at gmail.com>
> # Date 1499447586 -7200
> # Fri Jul 07 19:13:06 2017 +0200
> # Node ID 766932e4c2768577173f1bfaa10e919b9df739ec
> # Parent e714159860fd0872ae0555bb07546aa7e9f700e0
> 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 have a .hgadmonitions file inside the repository.
> All the
> custom directive with name specified under the tag [releasenotes.sections]
> will be
> usable by the extension. One important thing to keep in mind is if there
> exists any
> custom admonitions then they will override the default ones.
>
> diff -r e714159860fd -r 766932e4c276 hgext/releasenotes.py
> --- a/hgext/releasenotes.py Fri Jul 07 08:33:10 2017 +0200
> +++ b/hgext/releasenotes.py Fri Jul 07 19:13:06 2017 +0200
> @@ -20,6 +20,7 @@
>
> from mercurial.i18n import _
> from mercurial import (
> + config,
> error,
> minirst,
> registrar,
> @@ -111,9 +112,12 @@
> self.addnontitleditem(section, paragraphs)
>
> class releasenotessections(object):
> - def __init__(self, ui):
> - # TODO support defining custom sections from config.
> - self._sections = list(DEFAULT_SECTIONS)
> + def __init__(self, repo, revs, ui):
> + custom_sections = self.getcustomadmonitions(repo, revs, ui)
> + if custom_sections:
> + self._sections = custom_sections
> + else:
> + self._sections = list(DEFAULT_SECTIONS) + custom_sections
>
> def __iter__(self):
> return iter(self._sections)
> @@ -128,6 +132,38 @@
>
> return None
>
> + def getcustomadmonitions(self, repo, revs, ui):
> + custom_sections = list()
> + for rev in revs:
> + ctx = repo[rev]
> + p = config.config()
> + repo = ctx.repo()
> +
> + def read(f, sections=None, remap=None):
> + if f in ctx:
> + try:
> + data = ctx[f].data()
> +
> + except IOError as err:
> + if err.errno != errno.ENOENT:
> + raise
> + ui.warn(_("warning: .hgadmonitions file \'%s\' not
> found\n") %
> + repo.pathto(f))
> + return
> + p.parse(f, data, sections, remap, read)
> + sectiondict = p.__getitem__(sections)
> + sectionlist = list()
> + for key, value in sectiondict.iteritems():
> + temp = (key, value)
> + sectionlist.append(temp)
> + else:
> + raise error.Abort(_(".hgadmonitions file \'%s\' not
> found") %
> + repo.pathto(f))
> + return sectionlist
> + if '.hgadmonitions' in ctx:
> + custom_sections = read('.hgadmonitions',
> 'releasenotes.sections')
> + return custom_sections
> +
> def parsenotesfromrevisions(repo, directives, revs):
> notes = parsedreleasenotes()
>
> @@ -396,9 +432,9 @@
> that file. A particular use case for this is to tweak the wording of a
> release note after it has been added to the release notes file.
> """
> - sections = releasenotessections(ui)
> + revs = scmutil.revrange(repo, [rev or 'not public()'])
>
> - revs = scmutil.revrange(repo, [rev or 'not public()'])
> + sections = releasenotessections(repo, revs, ui)
> incoming = parsenotesfromrevisions(repo, sections.names(), revs)
>
> try:
> @@ -411,7 +447,7 @@
> notes = parsedreleasenotes()
>
> notes.merge(ui, incoming)
> -
> + print(incoming)
> with open(file_, 'wb') as fh:
> fh.write(serializenotes(sections, notes))
>
>
--
Rishabh Madan
Second Year Undergraduate student
Indian Institute of Technology, Kharagpur
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170707/9ff6d624/attachment.html>
More information about the Mercurial-devel
mailing list