GRM-20: fix: enforce GRM-N: conventional on master commits and PR titles
This commit is contained in:
@@ -82,11 +82,25 @@ class TestMain:
|
||||
with patch("scripts.validate_commit_msg.get_branch", return_value="GRM-19"):
|
||||
main(["validate_commit_msg.py", msg_path])
|
||||
|
||||
def test_accepts_anything_on_master(self) -> None:
|
||||
def test_accepts_valid_master_commit(self) -> None:
|
||||
msg_path = self._write_msg("GRM-19: feat: add feature")
|
||||
with patch("scripts.validate_commit_msg.get_branch", return_value="master"):
|
||||
main(["validate_commit_msg.py", msg_path])
|
||||
|
||||
def test_rejects_master_without_task_id(self) -> None:
|
||||
msg_path = self._write_msg("feat: add feature")
|
||||
with patch("scripts.validate_commit_msg.get_branch", return_value="master"):
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
main(["validate_commit_msg.py", msg_path])
|
||||
assert exc.value.code == 1
|
||||
|
||||
def test_rejects_master_with_non_conventional_after_task_id(self) -> None:
|
||||
msg_path = self._write_msg("GRM-19: random message")
|
||||
with patch("scripts.validate_commit_msg.get_branch", return_value="master"):
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
main(["validate_commit_msg.py", msg_path])
|
||||
assert exc.value.code == 1
|
||||
|
||||
def test_rejects_non_conventional_on_feature_branch(self) -> None:
|
||||
msg_path = self._write_msg("random message")
|
||||
with patch("scripts.validate_commit_msg.get_branch", return_value="feature"):
|
||||
@@ -106,6 +120,12 @@ class TestMain:
|
||||
|
||||
|
||||
def test_main_module_block() -> None:
|
||||
import tempfile
|
||||
|
||||
with tempfile.NamedTemporaryFile(mode="w", delete=False) as f:
|
||||
f.write("GRM-1: feat: test")
|
||||
msg_path = f.name
|
||||
|
||||
with patch("scripts.validate_commit_msg.get_branch", return_value="master"):
|
||||
import scripts.validate_commit_msg as vcm
|
||||
|
||||
@@ -115,4 +135,6 @@ def test_main_module_block() -> None:
|
||||
source = source.replace('if __name__ == "__main__":\n main()\n', "")
|
||||
namespace = dict(vcm.__dict__)
|
||||
exec(compile(source, vcm.__file__, "exec"), namespace)
|
||||
namespace["main"](["validate_commit_msg.py", "/dev/null"])
|
||||
namespace["main"](["validate_commit_msg.py", msg_path])
|
||||
|
||||
os.unlink(msg_path)
|
||||
|
||||
Reference in New Issue
Block a user