D355: contrib: add check flag for use of admonitions and its validity

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

D355: contrib: add check flag for use of admonitions and its validity

dsp (David Soria Parra)
rishabhmadan96 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  While using releasenotes extension, we will be using admonitions in commit messages.
  The check (-c) flag will look for an admonition within the message. If it exists, it will
  verify if it is stated under default or custom admonition. The check fails if the
  admonition is not present in any of them.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D355

AFFECTED FILES
  hgext/releasenotes.py

CHANGE DETAILS

diff --git a/hgext/releasenotes.py b/hgext/releasenotes.py
--- a/hgext/releasenotes.py
+++ b/hgext/releasenotes.py
@@ -242,6 +242,29 @@
         read('.hgreleasenotes')
     return p['sections']
 
+def checkadmonitions(ui, repo, directives, revs):
+    """
+    Checks the commit messages for admonitions and their validity.
+
+    .. abcd::
+
+       First paragraph under this admonition
+
+    For this commit message, using `hg releasenotes -r . --check`
+    returns: Invalid admonition 'abcd' present in changeset 3ea92981e103
+
+    As admonition 'abcd' is neither present in default nor custom admonitions
+    """
+    for rev in revs:
+        ctx = repo[rev]
+        admonition = re.search(RE_DIRECTIVE, ctx.description())
+        if admonition:
+            if admonition.group(1) in directives:
+                continue
+            else:
+                ui.write(_("Invalid admonition \'%s\' present in changeset %s\
+\n") % (admonition.group(1), ctx.hex()[:12]))
+
 def parsenotesfromrevisions(repo, directives, revs):
     notes = parsedreleasenotes()
 
@@ -432,9 +455,11 @@
     return '\n'.join(lines)
 
 @command('releasenotes',
-    [('r', 'rev', '', _('revisions to process for release notes'), _('REV'))],
-    _('[-r REV] FILE'))
-def releasenotes(ui, repo, file_, rev=None):
+    [('r', 'rev', '', _('revisions to process for release notes'), _('REV')),
+    ('c', 'check', False, _('checks for validity of admonitions (if any)'),
+        _('REV'))],
+    _('hg releasenotes [-r REV] [-c] FILE'))
+def releasenotes(ui, repo, file_=None, **opts):
     """parse release notes from commit messages into an output file
 
     Given an output file and set of revisions, this command will parse commit
@@ -511,23 +536,28 @@
     release note after it has been added to the release notes file.
     """
     sections = releasenotessections(ui, repo)
+    rev = opts.get('rev')
 
     revs = scmutil.revrange(repo, [rev or 'not public()'])
-    incoming = parsenotesfromrevisions(repo, sections.names(), revs)
+    if opts.get('check'):
+        checkadmonitions(ui, repo, sections.names(), revs)
+
+    if not opts.get('check'):
+        incoming = parsenotesfromrevisions(repo, sections.names(), revs)
 
-    try:
-        with open(file_, 'rb') as fh:
-            notes = parsereleasenotesfile(sections, fh.read())
-    except IOError as e:
-        if e.errno != errno.ENOENT:
-            raise
+        try:
+            with open(file_, 'rb') as fh:
+                notes = parsereleasenotesfile(sections, fh.read())
+        except IOError as e:
+            if e.errno != errno.ENOENT:
+                raise
 
-        notes = parsedreleasenotes()
+            notes = parsedreleasenotes()
 
-    notes.merge(ui, incoming)
+        notes.merge(ui, incoming)
 
-    with open(file_, 'wb') as fh:
-        fh.write(serializenotes(sections, notes))
+        with open(file_, 'wb') as fh:
+            fh.write(serializenotes(sections, notes))
 
 @command('debugparsereleasenotes', norepo=True)
 def debugparsereleasenotes(ui, path, repo=None):



To: rishabhmadan96, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

D355: contrib: add check flag for use of admonitions and its validity

dsp (David Soria Parra)
pulkit added a comment.


  Can you add tests for this. Also the commit message starts with "contrib", which seems unrelated here, please correct that.

INLINE COMMENTS

> releasenotes.py:543
> +    if opts.get('check'):
> +        checkadmonitions(ui, repo, sections.names(), revs)
> +

You can do `return checkadmonitions(...)` and that will prevent the later spacing diff.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D355

To: rishabhmadan96, #hg-reviewers
Cc: pulkit, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

D355: contrib: add check flag for use of admonitions and its validity

dsp (David Soria Parra)
In reply to this post by dsp (David Soria Parra)
durin42 added a comment.


  is this the same thing as https://phab.mercurial-scm.org/D368? Should we close this one in favor of that one?

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D355

To: rishabhmadan96, #hg-reviewers, pulkit
Cc: durin42, pulkit, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

D355: contrib: add check flag for use of admonitions and its validity

dsp (David Soria Parra)
In reply to this post by dsp (David Soria Parra)
rishabhmadan96 abandoned this revision.
rishabhmadan96 marked an inline comment as done.
rishabhmadan96 added a comment.


  In https://phab.mercurial-scm.org/D355#6196, @durin42 wrote:
 
  > is this the same thing as https://phab.mercurial-scm.org/D368? Should we close this one in favor of that one?
 
 
  Yes. I'm abandoning this one.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D355

To: rishabhmadan96, #hg-reviewers, pulkit
Cc: durin42, pulkit, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Loading...