diff hgext/releasenotes.py @ 33012:5814db57941c

releasenotes: improve parsing around bullet points Earlier, on parsing the bullet points from existing release notes the bullet points after the first one weren't written correctly to the notes file. This patch makes changes to parsereleasenotesfromfile() function that introduces a new bullet_points data structure that tracks the bullets and associated subparagraph. It also makes necessary changes to the tests related to merging of bullets.
author Rishabh Madan <rishabhmadan96@gmail.com>
date Fri, 23 Jun 2017 17:15:53 +0200
parents 91e355a0408b
children 9a944e908ecf
line wrap: on
line diff
--- a/hgext/releasenotes.py	Tue Jun 20 17:18:20 2017 -0700
+++ b/hgext/releasenotes.py	Fri Jun 23 17:15:53 2017 +0200
@@ -185,8 +185,8 @@
 
     blocks = minirst.parse(text)[0]
 
-    def gatherparagraphs(offset):
-        paragraphs = []
+    def gatherparagraphsbullets(offset, title=False):
+        notefragment = []
 
         for i in range(offset + 1, len(blocks)):
             block = blocks[i]
@@ -198,17 +198,27 @@
             elif block['type'] == 'bullet':
                 if block['indent'] != 0:
                     raise error.Abort(_('indented bullet lists not supported'))
+                if title:
+                    lines = [l[1:].strip() for l in block['lines']]
+                    notefragment.append(lines)
+                    continue
+                else:
+                    lines = [[l[1:].strip() for l in block['lines']]]
 
-                lines = [l[1:].strip() for l in block['lines']]
-                paragraphs.append(lines)
-                continue
+                    for block in blocks[i + 1:]:
+                        if block['type'] in ('bullet', 'section'):
+                            break
+                        if block['type'] == 'paragraph':
+                            lines.append(block['lines'])
+                    notefragment.append(lines)
+                    continue
             elif block['type'] != 'paragraph':
                 raise error.Abort(_('unexpected block type in release notes: '
                                     '%s') % block['type'])
+            if title:
+                notefragment.append(block['lines'])
 
-            paragraphs.append(block['lines'])
-
-        return paragraphs
+        return notefragment
 
     currentsection = None
     for i, block in enumerate(blocks):
@@ -226,16 +236,18 @@
                                   title)
 
             currentsection = name
-            paragraphs = gatherparagraphs(i)
-            if paragraphs:
-                notes.addnontitleditem(currentsection, paragraphs)
+            bullet_points = gatherparagraphsbullets(i)
+            if bullet_points:
+                for para in bullet_points:
+                    notes.addnontitleditem(currentsection, para)
 
         elif block['underline'] == '-':  # sub-section
-            paragraphs = gatherparagraphs(i)
-
             if title == BULLET_SECTION:
-                notes.addnontitleditem(currentsection, paragraphs)
+                bullet_points = gatherparagraphsbullets(i)
+                for para in bullet_points:
+                    notes.addnontitleditem(currentsection, para)
             else:
+                paragraphs = gatherparagraphsbullets(i, True)
                 notes.addtitleditem(currentsection, title, paragraphs)
         else:
             raise error.Abort(_('unsupported section type for %s') % title)