Patchwork [1,of,3] releasenotes: improve parsing around bullet points

login
register
mail settings
Submitter Rishabh Madan
Date June 11, 2017, 7:35 p.m.
Message ID <d2ab3803faab51e7998b.1497209706@bunty>
Download mbox | patch
Permalink /patch/21334/
State Superseded
Headers show

Comments

Rishabh Madan - June 11, 2017, 7:35 p.m.
# HG changeset patch
# User Rishabh Madan <rishabhmadan96@gmail.com>
# Date 1497208620 -7200
#      Sun Jun 11 21:17:00 2017 +0200
# Node ID d2ab3803faab51e7998bb57a15e6d6daca90cf42
# Parent  5154239fff11aacb065f4de8081884bfba691eed
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.
Pulkit Goyal - June 13, 2017, 12:16 a.m.
On Mon, Jun 12, 2017 at 1:05 AM, Rishabh Madan <rishabhmadan96@gmail.com> wrote:
> # HG changeset patch
> # User Rishabh Madan <rishabhmadan96@gmail.com>
> # Date 1497208620 -7200
> #      Sun Jun 11 21:17:00 2017 +0200
> # Node ID d2ab3803faab51e7998bb57a15e6d6daca90cf42
> # Parent  5154239fff11aacb065f4de8081884bfba691eed
> 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.

This patch can't be applied, please rebase it on the top of repo when
you send a V2 incorporating suggestions from others if any.
I strongly recommend you to run all the tests always before you send
patches or atleast test-check-*.t

Patch

diff -r 5154239fff11 -r d2ab3803faab hgext/releasenotes.py
--- a/hgext/releasenotes.py	Sun Jun 04 00:16:45 2017 +0200
+++ b/hgext/releasenotes.py	Sun Jun 11 21:17:00 2017 +0200
@@ -186,6 +186,43 @@ 
 
     blocks = minirst.parse(text)[0]
 
+    def gatherbullets(offset):
+        bullet_points = []
+
+        for i in range(offset + 1, len(blocks)):
+            block = blocks[i]
+
+            if block['type'] == 'margin':
+                continue
+            elif block['type'] == 'section':
+                break
+            elif block['type'] == 'bullet':
+                if block['indent'] != 0:
+                    raise error.Abort(_('indented bullet lists not supported'))
+
+                lines = [[l[1:].strip() for l in block['lines']]]
+               
+                if i < len(blocks)-1:
+                    i+=1
+                    block = blocks[i]
+                    if block['type']=='paragraph':
+                        lines.append(block['lines'])
+
+                    while block['type']!='bullet' and i < len(blocks)-1:
+                        if block['type'] == 'section':
+                            break
+                        i+=1
+                        block=blocks[i]
+                        if block['type']=='paragraph':
+                            lines.append(block['lines'])
+                bullet_points.append(lines)
+                continue
+            elif block['type'] != 'paragraph':
+                raise error.Abort(_('unexpected block type in release notes: '
+                                    '%s') % block['type'])
+
+        return bullet_points
+
     def gatherparagraphs(offset):
         paragraphs = []
 
@@ -229,17 +266,19 @@ 
                                   title)
 
             currentsection = name
-            paragraphs = gatherparagraphs(i)
-            if paragraphs:
-                notes.addnontitleditem(currentsection, paragraphs)
+            bullet_points = gatherbullets(i)
+            if bullet_points:
+                for para in bullet_points:
+                    notes.addnontitleditem(currentsection, para)
 
         # Sub-section.
         elif block['underline'] == '-':
-            paragraphs = gatherparagraphs(i)
-
             if title == BULLET_SECTION:
-                notes.addnontitleditem(currentsection, paragraphs)
+                bullet_points = gatherbullets(i)
+                for para in bullet_points:
+                    notes.addnontitleditem(currentsection, para)
             else:
+                paragraphs = gatherparagraphs(i)
                 notes.addtitleditem(currentsection, title, paragraphs)
         else:
             raise error.Abort(_('unsupported section type for %s') % title)