Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

fix(bump): fixed environment variables in bump hooks #675

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 1 commit into from
Feb 25, 2023
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
4 changes: 3 additions & 1 deletion commitizen/hooks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import os

from commitizen import cmd, out
from commitizen.exceptions import RunHookError

Expand All @@ -25,7 +27,7 @@ def run(hooks, _env_prefix="CZ_", **env):
def _format_env(prefix: str, env: dict[str, str]) -> dict[str, str]:
"""_format_env() prefixes all given environment variables with the given
prefix so it can be passed directly to cmd.run()."""
penv = dict()
penv = dict(os.environ)
for name, value in env.items():
name = prefix + name.upper()
value = str(value) if value is not None else ""
Expand Down
6 changes: 5 additions & 1 deletion tests/test_bump_hooks.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from unittest.mock import call

import pytest
Expand All @@ -17,7 +18,10 @@ def test_run(mocker: MockFixture):
hooks.run(bump_hooks)

cmd_run_mock.assert_has_calls(
[call("pre_bump_hook", env={}), call("pre_bump_hook_1", env={})]
[
call("pre_bump_hook", env=dict(os.environ)),
call("pre_bump_hook_1", env=dict(os.environ)),
]
)


Expand Down