Skip to content

Commit

Permalink
feat: utility for showing system information
Browse files Browse the repository at this point in the history
command to show system info output for bug reports

Issue #426
  • Loading branch information
sarsharma authored and Lee-W committed Sep 27, 2021
1 parent ca31452 commit 609cacd
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
9 changes: 8 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ If applicable, add screenshots to help explain your problem.

## Environment
<!--
For older commitizen versions, please include the
output of the following commands manually:
cz version
python --version
python3 -c "import platform; print(platform.system())"
-->

Add output of the following command to include the following
- commitizen version:
- python version:
- operating system:
```bash
cz version --report
```

6 changes: 6 additions & 0 deletions commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion commitizen/commands/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import platform
import sys

from commitizen import out
from commitizen.__version__ import __version__
from commitizen.config import BaseConfig
Expand All @@ -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}")
Expand Down
42 changes: 36 additions & 6 deletions tests/commands/test_version_command.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 609cacd

Please sign in to comment.