XZise has uploaded a new change for review.

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

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 tools/commit-message-validator.py
1 file changed, 6 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/integration/jenkins 
refs/changes/40/243140/1

diff --git a/tools/commit-message-validator.py 
b/tools/commit-message-validator.py
index 609518e..c8a532a 100755
--- a/tools/commit-message-validator.py
+++ b/tools/commit-message-validator.py
@@ -80,10 +80,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)
 
@@ -123,7 +121,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)
@@ -149,14 +147,11 @@
 
 def main():
     """Validate the current HEAD commit message."""
-    commit = subprocess.check_output('git log --pretty=raw -1', shell=True)
+    commit = subprocess.check_output(['git', 'log', '--format=%B', 
'--no-color',
+                                      '-n1'])
     commit = commit.decode(locale.getpreferredencoding())
-    lines = commit.splitlines()
-
-    # Discard until the first blank line
-    line = lines.pop(0)
-    while line:
-        line = lines.pop(0)
+    # 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: newchange
Gerrit-Change-Id: I7724c6c75ed100ef11082e95f4f48ef3f5d91d6a
Gerrit-PatchSet: 1
Gerrit-Project: integration/jenkins
Gerrit-Branch: master
Gerrit-Owner: XZise <commodorefabia...@gmx.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to