Skip to content

fix: Ensure all checks pass without overwriting previous failures #213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions commit_check/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from commit_check import author
from commit_check.util import validate_config
from commit_check.error import error_handler
from . import CONFIG_FILE, DEFAULT_CONFIG, PASS, __version__
from . import CONFIG_FILE, DEFAULT_CONFIG, PASS, FAIL, __version__


def get_parser() -> argparse.ArgumentParser:
Expand Down Expand Up @@ -99,29 +99,30 @@ def main() -> int:
"""The main entrypoint of commit-check program."""
parser = get_parser()
args = parser.parse_args()
retval = PASS
check_results: list[int] = []

with error_handler():
config = validate_config(args.config) if validate_config(
args.config,
) else DEFAULT_CONFIG
checks = config['checks']
if args.message:
retval = commit.check_commit_msg(checks, args.commit_msg_file)
check_results.append(commit.check_commit_msg(checks, args.commit_msg_file))
if args.author_name:
retval = author.check_author(checks, "author_name")
check_results.append(author.check_author(checks, "author_name"))
if args.author_email:
retval = author.check_author(checks, "author_email")
check_results.append(author.check_author(checks, "author_email"))
if args.branch:
retval = branch.check_branch(checks)
check_results.append(branch.check_branch(checks))
if args.commit_signoff:
retval = commit.check_commit_signoff(checks)
check_results.append(commit.check_commit_signoff(checks))
if args.merge_base:
retval = branch.check_merge_base(checks)
check_results.append(branch.check_merge_base(checks))

if args.dry_run:
retval = PASS
return retval
return PASS

return PASS if all(val == PASS for val in check_results) else FAIL


if __name__ == '__main__':
Expand Down
64 changes: 63 additions & 1 deletion tests/main_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys
import pytest
from commit_check.main import main
from commit_check import DEFAULT_CONFIG
from commit_check import DEFAULT_CONFIG, PASS, FAIL

CMD = "commit-check"

Expand Down Expand Up @@ -115,3 +115,65 @@ def test_main_validate_config_ret_none(self, mocker):
main()
assert m_check_commit.call_count == 1
assert m_check_commit.call_args[0][0] == DEFAULT_CONFIG["checks"]

@pytest.mark.parametrize(
"argv, message_result, branch_result, author_name_result, author_email_result, commit_signoff_result, merge_base_result, final_result",
[
([CMD, "--message"], PASS, PASS, PASS, PASS, PASS, PASS, PASS),
([CMD, "--message"], FAIL, PASS, PASS, PASS, PASS, PASS, FAIL),
([CMD, "--message", "--commit-signoff"], FAIL, PASS, PASS, PASS, PASS, PASS, FAIL,),
([CMD, "--message", "--commit-signoff"], PASS, PASS, PASS, PASS, FAIL, PASS, FAIL,),
([CMD, "--message", "--author-name", "--author-email"], PASS, PASS, PASS, PASS, PASS, PASS, PASS,),
([CMD, "--message", "--author-name", "--author-email"], FAIL, PASS, PASS, PASS, PASS, PASS, FAIL,),
([CMD, "--message", "--author-name", "--author-email"], PASS, PASS, FAIL, PASS, PASS, PASS, FAIL,),
([CMD, "--message", "--author-name", "--author-email"], PASS, PASS, PASS, FAIL, PASS, PASS, FAIL,),
([CMD, "--message", "--author-name", "--author-email"], PASS, PASS, FAIL, FAIL, PASS, PASS, FAIL,),
([CMD, "--message", "--branch", "--author-name", "--author-email", "--commit-signoff", "--merge-base", ], PASS, PASS, PASS, PASS, PASS, PASS, PASS,),
([CMD, "--message", "--branch", "--author-name", "--author-email", "--commit-signoff", "--merge-base", ], FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, FAIL,),
([CMD, "--message", "--branch", "--author-name", "--author-email", "--commit-signoff", "--merge-base", ], FAIL, PASS, PASS, PASS, PASS, PASS, FAIL,),
([CMD, "--dry-run"], FAIL, FAIL, FAIL, FAIL, FAIL, FAIL, PASS),
],
)
def test_main_multiple_checks(
self,
mocker,
argv,
message_result,
branch_result,
author_name_result,
author_email_result,
commit_signoff_result,
merge_base_result,
final_result,
):
mocker.patch(
"commit_check.main.validate_config",
return_value={},
)

mocker.patch(
"commit_check.commit.check_commit_msg", return_value=message_result
)
mocker.patch(
"commit_check.commit.check_commit_signoff",
return_value=commit_signoff_result,
)

mocker.patch("commit_check.branch.check_branch", return_value=branch_result)
mocker.patch(
"commit_check.branch.check_merge_base", return_value=merge_base_result
)

# this is messy. why isn't this a private implementation detail with a
# public check_author_name and check_author email?
def author_side_effect(_, check_type: str) -> int: # type: ignore[return]
assert check_type in ("author_name", "author_email")
if check_type == "author_name":
return author_name_result
elif check_type == "author_email":
return author_email_result

mocker.patch("commit_check.author.check_author", side_effect=author_side_effect)

sys.argv = argv
assert main() == final_result
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy