Skip to content

Commit 655efb1

Browse files
authored
Merge pull request #630 from commitizen-tools/fix-cz-yaml-format
Generate .cz.yaml that comply yamllint
2 parents ae22794 + 0c807f3 commit 655efb1

File tree

9 files changed

+23
-12
lines changed

9 files changed

+23
-12
lines changed

.github/workflows/bumpversion.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: "Bump version and create changelog with commitizen"
1313
steps:
1414
- name: Check out
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v3
1616
with:
1717
fetch-depth: 0
1818
token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'

.github/workflows/docspublish.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ jobs:
99
publish-documentation:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
1313
with:
1414
token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
1515
fetch-depth: 0
1616
- name: Set up Python
17-
uses: actions/setup-python@v1
17+
uses: actions/setup-python@v4
1818
with:
1919
python-version: '3.x'
2020
- name: Install dependencies

.github/workflows/homebrewpublish.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
if: ${{ github.event.workflow_run.conclusion == 'success' }}
1313
steps:
1414
- name: Checkout
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v3
1616
- name: Set up Python
17-
uses: actions/setup-python@v1
17+
uses: actions/setup-python@v4
1818
with:
1919
python-version: '3.x'
2020
- name: Install dependencies

.github/workflows/pythonpackage.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ jobs:
1010
platform: [ubuntu-20.04, macos-latest, windows-latest]
1111
runs-on: ${{ matrix.platform }}
1212
steps:
13-
- uses: actions/checkout@v2
13+
- uses: actions/checkout@v3
1414
with:
1515
fetch-depth: 0
1616
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v2
17+
uses: actions/setup-python@v4
1818
with:
1919
python-version: ${{ matrix.python-version }}
2020
- name: Install dependencies

.github/workflows/pythonpublish.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ jobs:
99
deploy:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
1313
with:
1414
token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
1515
fetch-depth: 0
1616
- name: Set up Python
17-
uses: actions/setup-python@v1
17+
uses: actions/setup-python@v4
1818
with:
1919
python-version: '3.x'
2020
- name: Install dependencies

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@ repos:
3535
name: linter and test
3636
language: system
3737
pass_filenames: false
38+
stage: push
3839
entry: ./scripts/test
3940
types: [python]

commitizen/config/yaml_config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]):
1717

1818
def init_empty_config_content(self):
1919
with smart_open(self.path, "a") as json_file:
20-
yaml.dump({"commitizen": {}}, json_file)
20+
yaml.dump({"commitizen": {}}, json_file, explicit_start=True)
2121

2222
def _parse_setting(self, data: Union[bytes, str]) -> None:
2323
"""We expect to have a section in cz.yaml looking like
@@ -44,6 +44,6 @@ def set_key(self, key, value):
4444

4545
parser["commitizen"][key] = value
4646
with smart_open(self.path, "w") as yaml_file:
47-
yaml.dump(parser, yaml_file)
47+
yaml.dump(parser, yaml_file, explicit_start=True)
4848

4949
return self

scripts/test

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ ${PREFIX}isort --check-only commitizen tests
1010
${PREFIX}flake8 commitizen/ tests/
1111
${PREFIX}mypy commitizen/ tests/
1212
${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415 --match-dir='"${REGEX}"'
13-
${PREFIX}commitizen check --rev-range origin/master..
13+
${PREFIX}commitizen -nr 3 check --rev-range origin/master..

tests/test_conf.py

+10
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,13 @@ def test_init_empty_config_content(self, tmpdir):
160160

161161
with open(path, "r") as json_file:
162162
assert json.load(json_file) == {"commitizen": {}}
163+
164+
165+
class TestYamlConfig:
166+
def test_init_empty_config_content(self, tmpdir):
167+
path = tmpdir.mkdir("commitizen").join(".cz.yaml")
168+
yaml_config = config.YAMLConfig(data="{}", path=path)
169+
yaml_config.init_empty_config_content()
170+
171+
with open(path, "r") as yaml_file:
172+
assert yaml.safe_load(yaml_file) == {"commitizen": {}}

0 commit comments

Comments
 (0)