XZise has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/247047

Change subject: [FEAT] Report multiple errors on each line
......................................................................

[FEAT] Report multiple errors on each line

Instead of just reporting the first error it should report every error on each
line so that the user can fix them all at one instead of step by step.

Similar to the verification after `Bug:` it also verifies for similar sounding
names if they follow the same style guide.

Change-Id: Id27070a5db98959523fba15c65964c2384c8a79b
---
M tests/test_commit-message-validator/check_message_errors.out
M tools/commit-message-validator.py
2 files changed, 26 insertions(+), 28 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/integration/jenkins 
refs/changes/47/247047/1

diff --git a/tests/test_commit-message-validator/check_message_errors.out 
b/tests/test_commit-message-validator/check_message_errors.out
index 1fa40bd..43d414d 100644
--- a/tests/test_commit-message-validator/check_message_errors.out
+++ b/tests/test_commit-message-validator/check_message_errors.out
@@ -2,10 +2,12 @@
 Line 2: Second line should be empty
 Line 3: Line should be <=100 characters
 Line 4: Use 'Bug: ' not 'Fixes:'
+Line 4: Expected one space after 'Bug:'
 Line 5: Use 'Bug: ' not 'Closes:'
+Line 5: Expected one space after 'Bug:'
 Line 6: Use 'Bug: ' not 'Task:'
 Line 7: Expected 'Bug:' not 'BUG:'
-Line 8: Each Bug: should list exactly one task
+Line 7: Expected one space after 'Bug:'
 Line 8: Expected blank line before Bug:
 Line 9: Unexpected blank line after Bug:
 Line 12: Unexpected blank line after Bug:
diff --git a/tools/commit-message-validator.py 
b/tools/commit-message-validator.py
index 44e3a28..c0f4ba9 100755
--- a/tools/commit-message-validator.py
+++ b/tools/commit-message-validator.py
@@ -13,7 +13,7 @@
 import subprocess
 
 
-def line_has_errors(lineno, line):
+def line_errors(lineno, line):
     """Check a commit message line to see if it has errors.
 
     Checks:
@@ -28,43 +28,40 @@
     rline = lineno + 1
 
     # First line <=80
-    if lineno == 0 and len(line) > 80:
-        return "Line %d: First line should be <=80 characters" % rline
+    if lineno == 0:
+        if len(line) > 80:
+            yield "First line should be <=80 characters"
 
     # Second line blank
-    if lineno == 1 and line:
-        return "Line %d: Second line should be empty" % rline
+    elif lineno == 1:
+        if line:
+            yield "Second line should be empty"
 
     # No line >100
-    if len(line) > 100:
-        return "Line %d: Line should be <=100 characters" % rline
+    elif len(line) > 100:
+        yield "Line should be <=100 characters"
 
-    m = re.match(r'^(bug:)(.)', line, re.IGNORECASE)
+    m = re.match(r'^(bug|closes|fixes|task):(\W)*(.*)', line, re.IGNORECASE)
     if m:
-        if m.group(1) != 'Bug:':
-            return "Line %d: Expected 'Bug:' not '%s'" % (rline, m.group(1))
+        if lineno == 0:
+            yield "Do not define bug in the header"
+
+        if m.group(1).lower() == 'bug':
+            if m.group(1) != 'Bug':
+                yield "Expected 'Bug:' not '%s:'" % m.group(1)
+        else:
+            # No "Task: ", "Fixes: ", "Closes: " lines
+            yield "Use 'Bug: ' not '%s:'" % m.group(1)
 
         if m.group(2) != ' ':
-            return "Line %d: Expected space after 'Bug:'" % rline
-
-        # Exactly one task id on each Bug: line
-        m = re.match(r'^Bug: \w+$', line)
-        if not m:
-            return "Line %d: Each Bug: should list exactly one task" % rline
-
-    # No "Task: ", "Fixes: ", "Closes: " lines
-    m = re.match(r'^(closes|fixes|task):', line, re.IGNORECASE)
-    if m:
-        return "Line %d: Use 'Bug: ' not '%s'" % (rline, m.group(0))
-
-    return False
+            yield "Expected one space after 'Bug:'"
 
 
 def check_message(lines):
     """Check a commit message to see if it has errors.
 
     Checks:
-    - All lines ok as checked by line_has_errors()
+    - All lines ok as checked by line_errors()
     - For any "^Bug: " line, next line is not blank
     - For any "^Bug: " line, prior line is another Bug: line or empty
     - Exactly one "Change-Id: " line per commit
@@ -80,9 +77,8 @@
     last_bug = False
     for lineno, line in enumerate(lines):
         rline = lineno + 1
-        e = line_has_errors(lineno, line)
-        if e:
-            errors.append(e)
+        errors.extend('Line {0}: {1}'.format(rline, e)
+                      for e in line_errors(lineno, line))
 
         # For any "Bug: " line, next line is not blank
         if last_bug == last_lineno:

-- 
To view, visit https://gerrit.wikimedia.org/r/247047
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id27070a5db98959523fba15c65964c2384c8a79b
Gerrit-PatchSet: 1
Gerrit-Project: integration/jenkins
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to