8000 remove trailing space in keep_a_changelog and other minor improvement by Lee-W · Pull Request #190 · commitizen-tools/commitizen · GitHub
[go: up one dir, main page]

Skip to content

remove trailing space in keep_a_changelog and other minor improvement #190

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 8 commits into from
May 23, 2020
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
12 changes: 11 additions & 1 deletion .github/workflows/pythonpackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ jobs:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
Expand All @@ -27,6 +29,14 @@ jobs:
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
./scripts/test
- name: Check commit
run: |
poetry run python -m commitizen check --rev-range ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} || \
if [ $$? == 3 ] ; then
exit 0;
else
exit 1;
fi
- name: Upload coverage to Codecov
if: runner.os == 'Linux'
uses: codecov/codecov-action@v1.0.3
Expand Down
7 changes: 3 additions & 4 deletions commitizen/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def find_increment(


def prerelease_generator(current_version: str, prerelease: Optional[str] = None) -> str:
"""
"""Generate prerelease

X.YaN # Alpha release
X.YbN # Beta release
X.YrcN # Release Candidate
Expand Down Expand Up @@ -137,7 +138,7 @@ def update_version_in_files(
So for example, your tag could look like `v1.0.0` while your version in
the package like `1.0.0`.
"""
# TODO: sepearte check step and write step
# TODO: separate check step and write step
for location in files:
filepath, *regexes = location.split(":", maxsplit=1)
regex = regexes[0] if regexes else None
Expand Down Expand Up @@ -179,13 +180,11 @@ def create_tag(version: Union[Version, str], tag_format: Optional[str] = None):
That's why this function exists.

Example:

| tag | version (PEP 0440) |
| --- | ------- |
| v0.9.0 | 0.9.0 |
| ver1.0.0 | 1.0.0 |
| ver1.0.0.a0 | 1.0.0a0 |

"""
if isinstance(version, str):
version = Version(version)
Expand Down
14 changes: 6 additions & 8 deletions commitizen/changelog.py
< 8000 td class="blob-num blob-num-addition empty-cell">
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
# DESIGN
"""Design

## Metadata CHANGELOG.md

Expand Down Expand Up @@ -62,7 +61,6 @@ def transform_change_type(change_type: str) -> str:


def get_commit_tag(commit: GitCommit, tags: List[GitTag]) -> Optional[GitTag]:
""""""
return next((tag for tag in tags if tag.rev == commit.rev), None)


Expand Down Expand Up @@ -211,13 +209,13 @@ def incremental_build(new_content: str, lines: List, metadata: Dict) -> List:
The metadata holds information enough to remove the old unreleased and
where to place the new content

Arguments:
lines -- the lines from the changelog
new_content -- this should be placed somewhere in the lines
metadata -- information about the changelog
Args:
lines: The lines from the changelog
new_content: This should be placed somewhere in the lines
metadata: Information about the changelog

Returns:
List -- updated lines
Updated lines
"""
unreleased_start = metadata.get("unreleased_start")
unreleased_end = metadata.get("unreleased_end")
Expand Down
6 changes: 2 additions & 4 deletions commitizen/changelog_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""
# DESIGN
"""CHNAGLOG PARSER DESIGN

## Parse CHANGELOG.md

Expand Down Expand Up @@ -36,8 +35,7 @@


def find_version_blocks(filepath: str) -> Generator:
"""
version block: contains all the information about a version.
"""Find version block (version block: contains all the information about a version.)

E.g:
```
Expand Down
2 changes: 1 addition & 1 deletion commitizen/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
{
"name": "--bump-message",
"help": (
"template used to create the release commmit, "
"template used to create the release commit, "
"useful when working with CI"
),
},
Expand Down
2 changes: 1 addition & 1 deletion commitizen/commands/bump.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def __call__(self): # noqa: C901
self.config.set_key("version", new_version.public)
c = git.commit(message, args=self._get_commit_args())
if c.err:
out.error('git.commit errror: "{}"'.format(c.err.strip()))
out.error('git.commit error: "{}"'.format(c.err.strip()))
raise SystemExit(COMMIT_FAILED)
c = git.tag(new_tag_version)
if c.err:
Expand Down
21 changes: 7 additions & 14 deletions commitizen/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ class Check:
"""Check if the current commit msg matches the commitizen format."""

def __init__(self, config: BaseConfig, arguments: Dict[str, str], cwd=os.getcwd()):
"""Init method.

Parameters
----------
config : BaseConfig
the config object required for the command to perform its action
arguments : dict
the arguments object that contains all
the flags provided by the user
"""Initial check command.

Args:
config: The config object required for the command to perform its action
arguments: All the flags provided by the user
cwd: Current work directory
"""
self.commit_msg_file: Optional[str] = arguments.get("commit_msg_file")
self.rev_range: Optional[str] = arguments.get("rev_range")
Expand All @@ -44,11 +40,8 @@ def _valid_command_argument(self):
def __call__(self):
"""Validate if commit messages follows the conventional pattern.

Raises
------
SystemExit
if the commit provided not follows the conventional pattern

Raises:
SystemExit: if the commit provided not follows the conventional pattern
"""
commit_msgs = self._get_commit_messages()
if not commit_msgs:
Expand Down
2 changes: 1 addition & 1 deletion commitizen/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def load_global_conf() -> Optional[IniConfig]:
if not global_cfg.exists():
return None

# global conf doesnt make sense with commitizen bump
# global conf doesn't make sense with commitizen bump
# so I'm deprecating it and won't test it
message = (
"Global conf will be deprecated in next major version. "
Expand Down
2 changes: 1 addition & 1 deletion commitizen/cz/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def schema(self) -> Optional[str]:
raise NotImplementedError("Not Implemented yet")

def schema_pattern(self) -> Optional[str]:
"""Regex matching the schema used for message validation"""
"""Regex matching the schema used for message validation."""
raise NotImplementedError("Not Implemented yet")

def info(self) -> Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion commitizen/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def commiter_factory(config: BaseConfig) -> BaseCommitizen:
_cz = registry[name](config)
except KeyError:
msg_error = (
"The commiter has not been found in the system.\n\n"
"The committer has not been found in the system.\n\n"
f"Try running 'pip install {name}'\n"
)
out.error(msg_error)
Expand Down
6 changes: 2 additions & 4 deletions commitizen/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def get_commits(
delimiter: str = "----------commit-delimiter----------",
args: str = "",
) -> List[GitCommit]:
"""
Get the commits betweeen start and end
"""
"""Get the commits between start and end."""
git_log_cmd = f"git log --pretty={log_format}{delimiter} {args}"

if start:
Expand Down Expand Up @@ -133,7 +131,7 @@ def find_git_project_root() -> Optional[Path]:


def is_staging_clean() -> bool:
"""Check if staing is clean"""
"""Check if staing is clean."""
c = cmd.run("git diff --no-ext-diff --name-only")
c_cached = cmd.run("git diff --no-ext-diff --cached --name-only")
return not (bool(c.out) or bool(c_cached.out))
2 changes: 1 addition & 1 deletion commitizen/templates/keep_a_changelog_template.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% for entry in tree %}

## {{ entry.version }} {% if entry.date %}({{ entry.date }}){% endif %}
## {{ entry.version }}{% if entry.date %} ({{ entry.date }}){% endif %}

{% for change_key, changes in entry.changes.items() %}

Expand Down
1 change: 1 addition & 0 deletions docs/tutorials/github_actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ jobs:
```

Notice that we are calling a bash script in `./scripts/publish`, you should configure it with your tools (twine, poetry, etc.). Check [commitizen example](https://github.com/commitizen-tools/commitizen/blob/master/scripts/publish)
You can also use [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) to publish your package.

Push the changes and that's it.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ mkdocs = "^1.0"
mkdocs-material = "^4.1"
isort = "^4.3.21"
freezegun = "^0.3.15"
pydocstyle = "^5.0.2"

[tool.poetry.scripts]
cz = "commitizen.cli:main"
Expand Down
1 change: 1 addition & 0 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ ${PREFIX}black commitizen tests --check
${PREFIX}isort --recursive --check-only commitizen tests
${PREFIX}flake8 commitizen/ tests/
${PREFIX}mypy commitizen/ tests/
${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415
8 changes: 4 additions & 4 deletions tests/CHANGELOG_FOR_TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- update given files with new version
- **config**: new set key, used to set version to cfg
- support for pyproject.toml
- first semantic version bump implementaiton
- first semantic version bump implementation

### fix

Expand Down Expand Up @@ -92,11 +92,11 @@

### refactor

- **conventionalCommit**: moved fitlers to questions instead of message
- **conventionalCommit**: moved filters to questions instead of message

### fix

- **manifest**: inluded missing files
- **manifest**: included missing files

## v0.9.5 (2018-08-24)

Expand All @@ -114,7 +114,7 @@

### feat

- **commiter**: conventional commit is a bit more intelligent now
- **committer**: conventional commit is a bit more intelligent now

## v0.9.2 (2017-11-11)

Expand Down
2 changes: 1 addition & 1 deletion tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_bump_on_git_with_hooks_no_verify_disabled(mocker, capsys):
cli.main()

_, err = capsys.readouterr()
assert 'git.commit errror: "0.1.0"' in err
assert 'git.commit error: "0.1.0"' in err


@pytest.mark.usefixtures("tmp_commitizen_project")
Expand Down
16 changes: 8 additions & 8 deletions tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_changlog_from_version_zero_point_two(mocker, capsys):
cli.main()

out, _ = capsys.readouterr()
assert out == "\n## Unreleased \n\n### Feat\n\n- after 0.2\n- after 0.2.0\n\n"
assert out == "\n## Unreleased\n\n### Feat\n\n- after 0.2\n- after 0.2.0\n\n"


@pytest.mark.usefixtures("tmp_commitizen_project")
Expand All @@ -54,7 +54,7 @@ def test_changlog_with_different_cz(mocker, capsys):
out, _ = capsys.readouterr()
assert (
out
== &q 10000 uot;\n## Unreleased \n\n\n- JRA-35 #time 1w 2d 4h 30m Total work logged\n- JRA-34 #comment corrected indent issue\n\n"
== "\n## Unreleased\n\n\n- JRA-35 #time 1w 2d 4h 30m Total work logged\n- JRA-34 #comment corrected indent issue\n\n"
)


Expand All @@ -74,7 +74,7 @@ def test_changlog_from_start(mocker, capsys):

assert (
out
== "\n## Unreleased \n\n### Refactor\n\n- is in changelog\n\n### Feat\n\n- new file\n"
== "\n## Unreleased\n\n### Refactor\n\n- is in changelog\n\n### Feat\n\n- new file\n"
)


Expand Down Expand Up @@ -108,7 +108,7 @@ def test_changlog_replacing_unreleased_using_incremental(mocker, capsys):
today = date.today().isoformat()
assert (
out
== f"\n\n## Unreleased \n\n### Feat\n\n- add more stuff\n\n### Fix\n\n- mama gotta work\n\n## 0.2.0 ({today})\n\n### Fix\n\n- output glitch\n\n### Feat\n\n- add new output\n"
== f"\n\n## Unreleased\n\n### Feat\n\n- add more stuff\n\n### Fix\n\n- mama gotta work\n\n## 0.2.0 ({today})\n\n### Fix\n\n- output glitch\n\n### Feat\n\n- add new output\n"
)


Expand Down Expand Up @@ -146,7 +146,7 @@ def test_changlog_is_persisted_using_incremental(mocker, capsys):
today = date.today().isoformat()
assert (
out
== f"\n\n## Unreleased \n\n### Feat\n\n- add more stuff\n\n### Fix\n\n- mama gotta work\n\n## 0.2.0 ({today})\n\n### Fix\n\n- output glitch\n\n### Feat\n\n- add new output\n\nnote: this should be persisted using increment\n"
== f"\n\n## Unreleased\n\n### Feat\n\n- add more stuff\n\n### Fix\n\n- mama gotta work\n\n## 0.2.0 ({today})\n\n### Fix\n\n- output glitch\n\n### Feat\n\n- add new output\n\nnote: this should be persisted using increment\n"
)


Expand Down Expand Up @@ -180,7 +180,7 @@ def test_changlog_incremental_angular_sample(mocker, capsys):

assert (
out
== "\n## Unreleased \n\n### Feat\n\n- add more stuff\n- add new output\n\n### Fix\n\n- mama gotta work\n- output glitch\n\n# [10.0.0-next.3](https://github.com/angular/angular/compare/10.0.0-next.2...10.0.0-next.3) (2020-04-22)\n\n### Bug Fixes\n* **common:** format day-periods that cross midnight ([#36611](https://github.com/angular/angular/issues/36611)) ([c6e5fc4](https://github.com/angular/angular/commit/c6e5fc4)), closes [#36566](https://github.com/angular/angular/issues/36566)\n"
== "\n## Unreleased\n\n### Feat\n\n- add more stuff\n- add new output\n\n### Fix\n\n- mama gotta work\n- output glitch\n\n# [10.0.0-next.3](https://github.com/angular/angular/compare/10.0.0-next.2...10.0.0-next.3) (2020-04-22)\n\n### Bug Fixes\n* **common:** format day-periods that cross midnight ([#36611](https://github.com/angular/angular/issues/36611)) ([c6e5fc4](https://github.com/angular/angular/commit/c6e5fc4)), closes [#36566](https://github.com/angular/angular/issues/36566)\n"
)


Expand Down Expand Up @@ -233,7 +233,7 @@ def test_changlog_incremental_keep_a_changelog_sample(mocker, capsys):

assert (
out
== """# Changelog\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n\n## Unreleased \n\n### Feat\n\n- add more stuff\n- add new output\n\n### Fix\n\n- mama gotta work\n- output glitch\n\n## [1.0.0] - 2017-06-20\n### Added\n- New visual identity by [@tylerfortune8](https://github.com/tylerfortune8).\n- Version navigation.\n\n### Changed\n- Start using "changelog" over "change log" since it\'s the common usage.\n\n### Removed\n- Section about "changelog" vs "CHANGELOG".\n\n## [0.3.0] - 2015-12-03\n### Added\n- RU translation from [@aishek](https://github.com/aishek).\n"""
== """# Changelog\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),\nand this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n\n\n## Unreleased\n\n### Feat\n\n- add more stuff\n- add new output\n\n### Fix\n\n- mama gotta work\n- output glitch\n\n## [1.0.0] - 2017-06-20\n### Added\n- New visual identity by [@tylerfortune8](https://github.com/tylerfortune8).\n- Version navigation.\n\n### Changed\n- Start using "changelog" over "change log" since it\'s the common usage.\n\n### Removed\n- Section about "changelog" vs "CHANGELOG".\n\n## [0.3.0] - 2015-12-03\n### Added\n- RU translation from [@aishek](https://github.com/aishek).\n"""
)


Expand All @@ -251,6 +251,6 @@ def test_changlog_hook(mocker, config):
)
mocker.patch.object(changelog.cz, "changelog_hook", changelog_hook_mock)
changelog()
full_changelog = "\n## Unreleased \n\n### Refactor\n\n- is in changelog\n\n### Feat\n\n- new file\n"
full_changelog = "\n## Unreleased\n\n### Refactor\n\n- is in changelog\n\n### Feat\n\n- new file\n"

changelog_hook_mock.assert_called_with(full_changelog, full_changelog)
Loading
0