Re: [PATCH] contrib: add check for use of admonitions and its validity

2017-08-07 Thread Augie Fackler
On Sat, Aug 05, 2017 at 10:36:46PM +0900, Yuya Nishihara wrote:
> On Sat, 05 Aug 2017 08:54:13 +0530, Rishabh Madan wrote:
> > # HG changeset patch
> > # User Rishabh Madan 
> > # Date 1501903168 -19800
> > #  Sat Aug 05 08:49:28 2017 +0530
> > # Node ID cc695f1458baf2c39ffdec4a1256a93fd659d62d
> > # Parent  609606d217659e0a6c1cf6f907b6512be5340e57
> > contrib: add check for use of admonitions and its validity
> >
> > While using releasenotes extension, we will be using admonitions in commit 
> > messages.
> > This check 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.
> >
> > diff -r 609606d21765 -r cc695f1458ba contrib/check-commit
> > --- a/contrib/check-commit  Thu Jul 20 01:30:41 2017 -0700
> > +++ b/contrib/check-commit  Sat Aug 05 08:49:28 2017 +0530
> > @@ -21,9 +21,16 @@
> >  import re
> >  import sys
> >
> > +from mercurial import (
> > +config,
> > +hg,
> > +ui as uimod,
> > +)
>
> check-commit seems to try not depending on mercurial modules. Maybe it's 
> easier
> to implement the check function as a command of the releasenotes extension?

Good idea! I like that.

>
> >  if __name__ == "__main__":
> >  exitcode = 0
> >  node = os.environ.get("HG_NODE")
> > -
> >  if node:
> >  commit = readcommit(node)
> > -exitcode = checkcommit(commit)
> > +exitcode = checkcommit(commit, node)
> >  elif sys.argv[1:]:
> >  for node in sys.argv[1:]:
> >  exitcode |= checkcommit(readcommit(node), node)
>
> test-check-commit.t feeds patches to stdin, in which case, no node value
> is available.
> ___
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH] contrib: add check for use of admonitions and its validity

2017-08-05 Thread Yuya Nishihara
On Sat, 05 Aug 2017 08:54:13 +0530, Rishabh Madan wrote:
> # HG changeset patch
> # User Rishabh Madan 
> # Date 1501903168 -19800
> #  Sat Aug 05 08:49:28 2017 +0530
> # Node ID cc695f1458baf2c39ffdec4a1256a93fd659d62d
> # Parent  609606d217659e0a6c1cf6f907b6512be5340e57
> contrib: add check for use of admonitions and its validity
> 
> While using releasenotes extension, we will be using admonitions in commit 
> messages.
> This check 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.
> 
> diff -r 609606d21765 -r cc695f1458ba contrib/check-commit
> --- a/contrib/check-commitThu Jul 20 01:30:41 2017 -0700
> +++ b/contrib/check-commitSat Aug 05 08:49:28 2017 +0530
> @@ -21,9 +21,16 @@
>  import re
>  import sys
>  
> +from mercurial import (
> +config,
> +hg,
> +ui as uimod,
> +)

check-commit seems to try not depending on mercurial modules. Maybe it's easier
to implement the check function as a command of the releasenotes extension?

>  if __name__ == "__main__":
>  exitcode = 0
>  node = os.environ.get("HG_NODE")
> -
>  if node:
>  commit = readcommit(node)
> -exitcode = checkcommit(commit)
> +exitcode = checkcommit(commit, node)
>  elif sys.argv[1:]:
>  for node in sys.argv[1:]:
>  exitcode |= checkcommit(readcommit(node), node)

test-check-commit.t feeds patches to stdin, in which case, no node value
is available.
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH] contrib: add check for use of admonitions and its validity

2017-08-04 Thread Rishabh Madan
# HG changeset patch
# User Rishabh Madan 
# Date 1501903168 -19800
#  Sat Aug 05 08:49:28 2017 +0530
# Node ID cc695f1458baf2c39ffdec4a1256a93fd659d62d
# Parent  609606d217659e0a6c1cf6f907b6512be5340e57
contrib: add check for use of admonitions and its validity

While using releasenotes extension, we will be using admonitions in commit 
messages.
This check 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.

diff -r 609606d21765 -r cc695f1458ba contrib/check-commit
--- a/contrib/check-commit  Thu Jul 20 01:30:41 2017 -0700
+++ b/contrib/check-commit  Sat Aug 05 08:49:28 2017 +0530
@@ -21,9 +21,16 @@
 import re
 import sys
 
+from mercurial import (
+config,
+hg,
+ui as uimod,
+)
+
 commitheader = r"^(?:# [^\n]*\n)*"
 afterheader = commitheader + r"(?!#)"
 beforepatch = afterheader + r"(?!\n(?!@@))"
+admonitioncheck = r"\.\. ([a-zA-Z0-9_]+)::"
 
 errors = [
 (beforepatch + r".*[(]bc[)]", "(BC) needs to be uppercase"),
@@ -59,6 +66,7 @@
 exitcode = 0
 printed = node is None
 hits = []
+exitcode = checkadmonition(commit, node)
 signtag = (afterheader +
   r'Added (tag [^ ]+|signature) for changeset [a-f0-9]{12}')
 if re.search(signtag, commit):
@@ -95,13 +103,38 @@
 def readcommit(node):
 return os.popen("hg export %s" % node).read()
 
+def getcustomadmonitions(node):
+repo = hg.repository(uimod.ui(), '.')
+ctx = repo[node]
+p = config.config()
+
+def read(f, sections=None, remap=None):
+if f in ctx:
+data = ctx[f].data()
+p.parse(f, data, sections, remap, read)
+
+if '.hgreleasenotes' in ctx:
+read('.hgreleasenotes')
+return p['sections'].keys()
+
+def checkadmonition(commit, node=None):
+admonitions = ["fix", "feature", "bc", "api", "perf"]
+x = re.search(admonitioncheck, commit)
+if x:
+if node:
+admonitions += getcustomadmonitions(node)
+if x.group(1) in admonitions:
+return 0
+else:
+print("admonition: %s is invalid" % x.group(1))
+return 1
+
 if __name__ == "__main__":
 exitcode = 0
 node = os.environ.get("HG_NODE")
-
 if node:
 commit = readcommit(node)
-exitcode = checkcommit(commit)
+exitcode = checkcommit(commit, node)
 elif sys.argv[1:]:
 for node in sys.argv[1:]:
 exitcode |= checkcommit(readcommit(node), node)
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel