On 8/1/19 4:37 PM, Martin Liška wrote:
> That sounds good! People should write tests and as a bonus, they will
> have PRs filled in mklog ChangeLog. I'll work on that.

I'm doing that in the attached patch.

Ready for trunk?

Martin
>From 8be6ce17c3c236273338a430d80cfd79b2a67df4 Mon Sep 17 00:00:00 2001
From: Martin Liska <mli...@suse.cz>
Date: Thu, 1 Aug 2019 16:51:47 +0200
Subject: [PATCH] mklog: parse PR references from new test files

contrib/ChangeLog:

2019-08-01  Martin Liska  <mli...@suse.cz>

	* mklog: Parse PR references from new test files.
---
 contrib/mklog | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/contrib/mklog b/contrib/mklog
index 15558cfbfe3..7681e4b1300 100755
--- a/contrib/mklog
+++ b/contrib/mklog
@@ -40,6 +40,8 @@ from subprocess import Popen, PIPE
 
 me = os.path.basename(sys.argv[0])
 
+pr_regex = re.compile('\+\/(\/|\*)\s+(PR [^\/]+\/[0-9]+)')
+
 def error(msg):
   sys.stderr.write("%s: error: %s\n" % (me, msg))
   sys.exit(1)
@@ -314,7 +316,7 @@ def parse_patch(contents):
         if l != r:
           break
         comps.append(l)
-    
+
       if not comps:
         error("failed to extract common name for %s and %s" % (left, right))
 
@@ -353,6 +355,14 @@ def parse_patch(contents):
 
   return diffs
 
+
+def get_pr_from_testcase(line):
+    r = pr_regex.search(line)
+    if r != None:
+        return r.group(2)
+    else:
+        return None
+
 def main():
   name, email = read_user_info()
 
@@ -395,6 +405,7 @@ def main():
   # Generate template ChangeLog.
 
   logs = {}
+  prs = []
   for d in diffs:
     log_name = d.clname
 
@@ -410,6 +421,9 @@ def main():
       if hunk0.is_file_addition():
         if re.search(r'testsuite.*(?<!\.exp)$', d.filename):
           change_msg = ': New test.\n'
+          pr = get_pr_from_testcase(hunk0.lines[0])
+          if pr and pr not in prs:
+              prs.append(pr)
         else:
           change_msg = ": New file.\n"
       elif hunk0.is_file_removal():
@@ -449,13 +463,17 @@ def main():
 
   # Print log
   date = time.strftime('%Y-%m-%d')
+  bugmsg = ''
+  if len(prs):
+    bugmsg = '\n'.join(['\t' + pr for pr in prs]) + '\n'
+
   for log_name, msg in sorted(logs.items()):
     out.write("""\
 %s:
 
 %s  %s  <%s>
 
-%s\n""" % (log_name, date, name, email, msg))
+%s%s\n""" % (log_name, date, name, email, bugmsg, msg))
 
   if inline:
     # Append patch body
-- 
2.22.0

Reply via email to