From 609cacdb1580d540d26e3486ac59a858a1546fbc Mon Sep 17 00:00:00 2001 From: Sarthak Sharma Date: Mon, 27 Sep 2021 13:38:19 +0530 Subject: [PATCH] feat: utility for showing system information command to show system info output for bug reports Issue #426 --- .github/ISSUE_TEMPLATE/bug_report.md | 9 +++++- commitizen/cli.py | 6 ++++ commitizen/commands/version.py | 11 ++++++- tests/commands/test_version_command.py | 42 ++++++++++++++++++++++---- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index bfd26c9265..73d632fd13 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -28,11 +28,18 @@ If applicable, add screenshots to help explain your problem. ## Environment - +Add output of the following command to include the following - commitizen version: - python version: - operating system: +```bash +cz version --report +``` + diff --git a/commitizen/cli.py b/commitizen/cli.py index 2fb482094b..e1bad367e7 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -227,6 +227,12 @@ ), "func": commands.Version, "arguments": [ + { + "name": ["-r", "--report"], + "help": "get system information for reporting bugs", + "action": "store_true", + "exclusive_group": "group1", + }, { "name": ["-p", "--project"], "help": "get the version of the current project", diff --git a/commitizen/commands/version.py b/commitizen/commands/version.py index 143a0c7351..dc47e7aa0c 100644 --- a/commitizen/commands/version.py +++ b/commitizen/commands/version.py @@ -1,3 +1,6 @@ +import platform +import sys + from commitizen import out from commitizen.__version__ import __version__ from commitizen.config import BaseConfig @@ -9,9 +12,15 @@ class Version: def __init__(self, config: BaseConfig, *args): self.config: BaseConfig = config self.parameter = args[0] + self.operating_system = platform.system() + self.python_version = sys.version def __call__(self): - if self.parameter.get("project"): + if self.parameter.get("report"): + out.write(f"Commitizen Version: {__version__}") + out.write(f"Python Version: {self.python_version}") + out.write(f"Operating System: {self.operating_system}") + elif self.parameter.get("project"): version = self.config.settings["version"] if version: out.write(f"{version}") diff --git a/tests/commands/test_version_command.py b/tests/commands/test_version_command.py index 527c0b53f1..7e6ec3c851 100644 --- a/tests/commands/test_version_command.py +++ b/tests/commands/test_version_command.py @@ -1,42 +1,72 @@ +import platform +import sys + from commitizen import commands from commitizen.__version__ import __version__ def test_version_for_showing_project_version(config, capsys): # No version exist - commands.Version(config, {"project": True, "commitizen": False, "verbose": False})() + commands.Version( + config, + {"report": False, "project": True, "commitizen": False, "verbose": False}, + )() captured = capsys.readouterr() assert "No project information in this project." in captured.err config.settings["version"] = "v0.0.1" - commands.Version(config, {"project": True, "commitizen": False, "verbose": False})() + commands.Version( + config, + {"report": False, "project": True, "commitizen": False, "verbose": False}, + )() captured = capsys.readouterr() assert "v0.0.1" in captured.out def test_version_for_showing_commitizen_version(config, capsys): - commands.Version(config, {"project": False, "commitizen": True, "verbose": False})() + commands.Version( + config, + {"report": False, "project": False, "commitizen": True, "verbose": False}, + )() captured = capsys.readouterr() assert f"{__version__}" in captured.out # default showing commitizen version commands.Version( - config, {"project": False, "commitizen": False, "verbose": False} + config, + {"report": False, "project": False, "commitizen": False, "verbose": False}, )() captured = capsys.readouterr() assert f"{__version__}" in captured.out def test_version_for_showing_both_versions(config, capsys): - commands.Version(config, {"project": False, "commitizen": False, "verbose": True})() + commands.Version( + config, + {"report": False, "project": False, "commitizen": False, "verbose": True}, + )() captured = capsys.readouterr() assert f"Installed Commitizen Version: {__version__}" in captured.out assert "No project information in this project." in captured.err config.settings["version"] = "v0.0.1" - commands.Version(config, {"project": False, "commitizen": False, "verbose": True})() + commands.Version( + config, + {"report": False, "project": False, "commitizen": False, "verbose": True}, + )() captured = capsys.readouterr() expected_out = ( f"Installed Commitizen Version: {__version__}\n" f"Project Version: v0.0.1" ) assert expected_out in captured.out + + +def test_version_for_showing_commitizen_system_info(config, capsys): + commands.Version( + config, + {"report": True, "project": False, "commitizen": False, "verbose": False}, + )() + captured = capsys.readouterr() + assert f"Commitizen Version: {__version__}" in captured.out + assert f"Python Version: {sys.version}" in captured.out + assert f"Operating System: {platform.system()}" in captured.out