1
1
import os
2
2
import re
3
3
import tempfile
4
+ from pathlib import Path
4
5
5
6
import pytest
6
7
7
8
from commitizen import cmd , defaults
8
9
from commitizen .config import BaseConfig
9
10
11
+ SIGNER = "GitHub Action"
12
+ SIGNER_MAIL = "action@github.com"
13
+
14
+
15
+ @pytest .fixture (autouse = True )
16
+ def git_sandbox (monkeypatch : pytest .MonkeyPatch , tmp_path : Path ):
17
+ """Ensure git commands are executed without the current user settings"""
18
+ monkeypatch .setenv ("GIT_CONFIG_GLOBAL" , str (tmp_path / "gitconfig" ))
19
+ cmd .run (f"git config --global user.name { SIGNER } " )
20
+ cmd .run (f"git config --global user.email { SIGNER_MAIL } " )
21
+
10
22
11
23
@pytest .fixture (scope = "function" )
12
24
def tmp_git_project (tmpdir ):
@@ -36,9 +48,6 @@ def _get_gpg_keyid(signer_mail):
36
48
37
49
@pytest .fixture (scope = "function" )
38
50
def tmp_commitizen_project_with_gpg (tmp_commitizen_project ):
39
- signer = "GitHub Action"
40
- signer_mail = "action@github.com"
41
-
42
51
# create a temporary GPGHOME to store a temporary keyring.
43
52
# Home path must be less than 104 characters
44
53
gpg_home = tempfile .TemporaryDirectory (suffix = "_cz" )
@@ -47,17 +56,15 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project):
47
56
48
57
# create a key (a keyring will be generated within GPUPGHOME)
49
58
c = cmd .run (
50
- f"gpg --batch --yes --debug-quick-random --passphrase '' --quick-gen-key '{ signer } { signer_mail } '"
59
+ f"gpg --batch --yes --debug-quick-random --passphrase '' --quick-gen-key '{ SIGNER } { SIGNER_MAIL } '"
51
60
)
52
61
if c .return_code != 0 :
53
62
raise Exception (f"gpg keygen failed with err: '{ c .err } '" )
54
- key_id = _get_gpg_keyid (signer_mail )
63
+ key_id = _get_gpg_keyid (SIGNER_MAIL )
55
64
assert key_id
56
65
57
- # configure git
66
+ # configure git to use gpg signing
58
67
cmd .run ("git config commit.gpgsign true" )
59
- cmd .run (f"git config user.name { signer } " )
60
- cmd .run (f"git config user.email { signer_mail } " )
61
68
cmd .run (f"git config user.signingkey { key_id } " )
62
69
63
70
yield tmp_commitizen_project
0 commit comments