jenkins-bot has submitted this change and it was merged.
Change subject: Add script to test already merged commits in a repository
......................................................................
Add script to test already merged commits in a repository
The sample_repository.py script iterates through the specified git
repository's merged commits, and validates their commit message, and
outputs failure messages.
For easy usage, you can run the script through tox:
tox -e sample /path/to/git/repo [count]
Change-Id: Ib02c4c58d316e5fdfe26d4a09c8cff90f409a208
---
M commit_message_validator/__init__.py
A commit_message_validator/tests/sample_repository.py
M tox.ini
3 files changed, 59 insertions(+), 3 deletions(-)
Approvals:
Legoktm: Looks good to me, approved
jenkins-bot: Verified
diff --git a/commit_message_validator/__init__.py
b/commit_message_validator/__init__.py
index df6fb8e..45a0ade 100644
--- a/commit_message_validator/__init__.py
+++ b/commit_message_validator/__init__.py
@@ -251,18 +251,18 @@
return subprocess.check_output(args).decode()
-def main():
+def main(commit_id='HEAD'):
"""Validate the current HEAD commit message."""
# First, we need to check if HEAD is a merge commit
# We do this by telling if it has multiple parents
parents = check_output(
- ['git', 'log', '--format=%P', 'HEAD', '-n1']
+ ['git', 'log', '--format=%P', commit_id, '-n1']
).strip().split(' ')
if len(parents) > 1:
# Use the right-most parent
commit_id = parents[-1]
else:
- commit_id = 'HEAD'
+ commit_id = commit_id
commit = check_output(
['git', 'log', '--format=%B', '--no-color', commit_id, '-n1'])
diff --git a/commit_message_validator/tests/sample_repository.py
b/commit_message_validator/tests/sample_repository.py
new file mode 100644
index 0000000..c786265
--- /dev/null
+++ b/commit_message_validator/tests/sample_repository.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+
+"""
+Runs through the provided git repo and samples the commit
+messages to see whether they would pass the commit message
+validator.
+"""
+
+import os
+import sys
+
+import commit_message_validator as cmv
+
+if sys.version_info[0] > 2:
+ from io import StringIO
+else:
+ from StringIO import StringIO
+
+
+def main():
+ if len(sys.argv) < 2:
+ print("Usage: tox -e sample /path/to/git/repo [count]")
+ sys.exit(1)
+ repo = sys.argv[1]
+ if len(sys.argv) == 3:
+ num = sys.argv[2]
+ else:
+ num = '10'
+ os.chdir(repo)
+ sha1s = cmv.check_output(['git', 'log', '--format=%H', '--no-merges', '-n'
+ num]).splitlines()
+ good = 0
+ bad = 0
+ for sha1 in sha1s:
+ saved_stdout = sys.stdout
+ try:
+ out = StringIO()
+ sys.stdout = out
+ exit_code = cmv.main(sha1)
+ if exit_code != 0:
+ saved_stdout.write('Fail: ' + sha1 + '\n')
+ saved_stdout.write(out.getvalue() + '\n')
+ bad += 1
+ else:
+ saved_stdout.write('Pass: ' + sha1 + '\n')
+ good += 1
+ finally:
+ sys.stdout = saved_stdout
+ bad_percent = '{:.2%}'.format(bad/(bad+good))
+ print('commit-message-validator identified that %s commits failed
validation.' % bad_percent)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/tox.ini b/tox.ini
index 1fa0f8f..b13d0d1 100644
--- a/tox.ini
+++ b/tox.ini
@@ -19,6 +19,9 @@
deps = nose
six
+[testenv:sample]
+commands = python commit_message_validator/tests/sample_repository.py {posargs}
+
[flake8]
exclude = .tox
max_line_length = 120
--
To view, visit https://gerrit.wikimedia.org/r/304583
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ib02c4c58d316e5fdfe26d4a09c8cff90f409a208
Gerrit-PatchSet: 3
Gerrit-Project: integration/commit-message-validator
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Paladox <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits