mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 12:22:50 -05:00
lint: Call lint_commit_msg from test_runner
Allowing to call the check from the test_runner allows for consistent error messages. Also, manually setting the commit range is no longer needed.
This commit is contained in:
parent
fa99728b0c
commit
faf8fc5487
2 changed files with 41 additions and 52 deletions
|
@ -1,52 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
#
|
||||
# Copyright (c) 2020-2022 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
#
|
||||
# Linter to check that commit messages have a new line before the body
|
||||
# or no body at all
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
from subprocess import check_output
|
||||
|
||||
|
||||
def parse_args():
|
||||
"""Parse command line arguments."""
|
||||
parser = argparse.ArgumentParser(
|
||||
description="""
|
||||
Linter to check that commit messages have a new line before
|
||||
the body or no body at all.
|
||||
""",
|
||||
epilog=f"""
|
||||
You can manually set the commit-range with the COMMIT_RANGE
|
||||
environment variable (e.g. "COMMIT_RANGE='HEAD~n..HEAD'
|
||||
{sys.argv[0]}") for the last 'n' commits.
|
||||
""")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
parse_args()
|
||||
exit_code = 0
|
||||
|
||||
assert os.getenv("COMMIT_RANGE") # E.g. COMMIT_RANGE='HEAD~n..HEAD'
|
||||
commit_range = os.getenv("COMMIT_RANGE")
|
||||
|
||||
commit_hashes = check_output(["git", "-c", "log.showSignature=false", "log", commit_range, "--format=%H"], text=True, encoding="utf8").splitlines()
|
||||
|
||||
for hash in commit_hashes:
|
||||
commit_info = check_output(["git", "-c", "log.showSignature=false", "log", "--format=%B", "-n", "1", hash], text=True, encoding="utf8").splitlines()
|
||||
if len(commit_info) >= 2:
|
||||
if commit_info[1]:
|
||||
print(f"The subject line of commit hash {hash} is followed by a non-empty line. Subject lines should always be followed by a blank line.")
|
||||
exit_code = 1
|
||||
|
||||
sys.exit(exit_code)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
|
@ -73,6 +73,11 @@ fn get_linter_list() -> Vec<&'static Linter> {
|
|||
name: "scripted_diff",
|
||||
lint_fn: lint_scripted_diff
|
||||
},
|
||||
&Linter {
|
||||
description: "Check that commit messages have a new line before the body or no body at all.",
|
||||
name: "commit_msg",
|
||||
lint_fn: lint_commit_msg
|
||||
},
|
||||
&Linter {
|
||||
description: "Check that tabs are not used as whitespace",
|
||||
name: "tabs_whitespace",
|
||||
|
@ -243,6 +248,42 @@ fn lint_scripted_diff() -> LintResult {
|
|||
}
|
||||
}
|
||||
|
||||
fn lint_commit_msg() -> LintResult {
|
||||
let mut good = true;
|
||||
let commit_hashes = check_output(git().args(&[
|
||||
"-c",
|
||||
"log.showSignature=false",
|
||||
"log",
|
||||
&commit_range(),
|
||||
"--format=%H",
|
||||
]))?;
|
||||
for hash in commit_hashes.lines() {
|
||||
let commit_info = check_output(git().args([
|
||||
"-c",
|
||||
"log.showSignature=false",
|
||||
"log",
|
||||
"--format=%B",
|
||||
"-n",
|
||||
"1",
|
||||
hash,
|
||||
]))?;
|
||||
if let Some(line) = commit_info.lines().nth(1) {
|
||||
if !line.is_empty() {
|
||||
println!(
|
||||
"The subject line of commit hash {} is followed by a non-empty line. Subject lines should always be followed by a blank line.",
|
||||
hash
|
||||
);
|
||||
good = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if good {
|
||||
Ok(())
|
||||
} else {
|
||||
Err("".to_string())
|
||||
}
|
||||
}
|
||||
|
||||
fn lint_py_lint() -> LintResult {
|
||||
let bin_name = "ruff";
|
||||
let checks = format!(
|
||||
|
|
Loading…
Add table
Reference in a new issue