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

Rishabh Madan rishabhmadan96 at gmail.com
Thu Jun 29 18:57:26 EDT 2017


# HG changeset patch
# User Rishabh Madan <rishabhmadan96 at 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
+
+  $ 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.


More information about the Mercurial-devel mailing list