jenkins-bot has submitted this change and it was merged.

Change subject: [IMPROV] Don't use shell argument
......................................................................


[IMPROV] Don't use shell argument

The `shell` argument in `subprocess.check_output` should be used very
carefully. But this is not necessary if we already split the arguments. This
now also uses a custom log format which will only print the commit message not
indented.

This also fixes various issues that it didn't detect lines which start with
"Change-Id" or "Bug" because it didn't consider the indentation.

Change-Id: I7724c6c75ed100ef11082e95f4f48ef3f5d91d6a
---
M tests/test_commit-message-validator/check_message_errors.msg
M tests/test_commit-message-validator/check_message_errors.out
M tools/commit-message-validator.py
3 files changed, 9 insertions(+), 12 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, but someone else must approve
  JanZerebecki: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/test_commit-message-validator/check_message_errors.msg 
b/tests/test_commit-message-validator/check_message_errors.msg
index ac0fc3c..1905eae 100644
--- a/tests/test_commit-message-validator/check_message_errors.msg
+++ b/tests/test_commit-message-validator/check_message_errors.msg
@@ -11,5 +11,6 @@
 Bug: T12
 
 Change-Id: I1234567890abcdef123456
+Change-Id: I1234567890abcdef123457
 Foo bar
 (cherry picked from commit 7ad8cc24d0672111cff5beddcfc9d778a1a3478e)
diff --git a/tests/test_commit-message-validator/check_message_errors.out 
b/tests/test_commit-message-validator/check_message_errors.out
index d2611ec..1fa40bd 100644
--- a/tests/test_commit-message-validator/check_message_errors.out
+++ b/tests/test_commit-message-validator/check_message_errors.out
@@ -10,4 +10,5 @@
 Line 9: Unexpected blank line after Bug:
 Line 12: Unexpected blank line after Bug:
 Line 12: Unexpected line between Bug: and Change-Id:
-Line 14: Unexpected line after Change-Id
+Line 13: Extra Change-Id found, next at 14
+Line 15: Unexpected line after Change-Id
diff --git a/tools/commit-message-validator.py 
b/tools/commit-message-validator.py
index 633a0bb..44e3a28 100755
--- a/tools/commit-message-validator.py
+++ b/tools/commit-message-validator.py
@@ -79,10 +79,8 @@
     changeid_line = False
     last_bug = False
     for lineno, line in enumerate(lines):
-        # Strip leading spaces to remove `git log` indenting
-        stripped = line.lstrip()
         rline = lineno + 1
-        e = line_has_errors(lineno, stripped)
+        e = line_has_errors(lineno, line)
         if e:
             errors.append(e)
 
@@ -122,7 +120,7 @@
             changeid_line = rline
 
         last_lineno = rline
-        last_line = stripped
+        last_line = line
 
     if last_lineno < 2:
         errors.append("Line %d: Expected at least 3 lines" % last_lineno)
@@ -148,13 +146,10 @@
 
 def main():
     """Validate the current HEAD commit message."""
-    commit = subprocess.check_output('git log --pretty=raw -1', shell=True)
-    lines = commit.splitlines()
-
-    # Discard until the first blank line
-    line = lines.pop(0)
-    while line:
-        line = lines.pop(0)
+    commit = subprocess.check_output(
+        ['git', 'log', '--format=%B', '--no-color', '-n1'])
+    # last line is always an empty line
+    lines = commit.splitlines()[:-1]
 
     return check_message(lines)
 

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7724c6c75ed100ef11082e95f4f48ef3f5d91d6a
Gerrit-PatchSet: 4
Gerrit-Project: integration/jenkins
Gerrit-Branch: master
Gerrit-Owner: XZise <[email protected]>
Gerrit-Reviewer: BryanDavis <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: JanZerebecki <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to