Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 24be2bd

Browse files
committed
feat(cz_check): cz check can read commit message from pipe
#200
1 parent b207e6d commit 24be2bd

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

‎commitizen/cli.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import logging
3+
import os
34
import sys
45
from functools import partial
56

@@ -267,7 +268,11 @@ def main():
267268

268269
# This is for the command required constraint in 2.0
269270
try:
270-
args = parser.parse_args()
271+
if sys.argv[1] == "check" and not os.isatty(0):
272+
messages = sys.stdin.read()
273+
args = parser.parse_args(["check", "--message", messages])
274+
else:
275+
args = parser.parse_args()
271276
except TypeError:
272277
raise NoCommandFoundError()
273278

‎tests/commands/test_check_command.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from io import StringIO
23
from typing import List
34

45
import pytest
@@ -245,3 +246,23 @@ def test_check_command_with_invalid_message(config, mocker):
245246
with pytest.raises(InvalidCommitMessageError):
246247
check_cmd()
247248
error_mock.assert_called_once()
249+
250+
251+
def test_check_command_with_pipe_message(mocker, capsys):
252+
testargs = ["cz", "check"]
253+
mocker.patch.object(sys, "argv", testargs)
254+
mocker.patch("sys.stdin", StringIO("fix(scope): some commit message"))
255+
256+
cli.main()
257+
out, _ = capsys.readouterr()
258+
assert "Commit validation: successful!" in out
259+
260+
261+
def test_check_command_with_pipe_message_and_failed(mocker):
262+
testargs = ["cz", "check"]
263+
mocker.patch.object(sys, "argv", testargs)
264+
mocker.patch("sys.stdin", StringIO("bad commit message"))
265+
266+
with pytest.raises(InvalidCommitMessageError) as excinfo:
267+
cli.main()
268+
assert "commit validation: failed!" in str(excinfo.value)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /