Skip to content

Generate .cz.yaml that comply yamllint #630

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 4 commits into from
Jan 23, 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
2 changes: 1 addition & 1 deletion .github/workflows/bumpversion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: "Bump version and create changelog with commitizen"
steps:
- name: Check out
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0
token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docspublish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
publish-documentation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/homebrewpublish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ jobs:
platform: [ubuntu-20.04, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pythonpublish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
token: '${{ secrets.PERSONAL_ACCESS_TOKEN }}'
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ repos:
name: linter and test
language: system
pass_filenames: false
stage: push
entry: ./scripts/test
types: [python]
4 changes: 2 additions & 2 deletions commitizen/config/yaml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]):

def init_empty_config_content(self):
with smart_open(self.path, "a") as json_file:
yaml.dump({"commitizen": {}}, json_file)
yaml.dump({"commitizen": {}}, json_file, explicit_start=True)

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

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

return self
2 changes: 1 addition & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ ${PREFIX}isort --check-only commitizen tests
${PREFIX}flake8 commitizen/ tests/
${PREFIX}mypy commitizen/ tests/
${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415 --match-dir='"${REGEX}"'
${PREFIX}commitizen check --rev-range origin/master..
${PREFIX}commitizen -nr 3 check --rev-range origin/master..
10 changes: 10 additions & 0 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,13 @@ def test_init_empty_config_content(self, tmpdir):

with open(path, "r") as json_file:
assert json.load(json_file) == {"commitizen": {}}


class TestYamlConfig:
def test_init_empty_config_content(self, tmpdir):
path = tmpdir.mkdir("commitizen").join(".cz.yaml")
yaml_config = config.YAMLConfig(data="{}", path=path)
yaml_config.init_empty_config_content()

with open(path, "r") as yaml_file:
assert yaml.safe_load(yaml_file) == {"commitizen": {}}