Skip to content
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

Validate new component slug #153

Merged
merged 1 commit into from
Jul 29, 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
17 changes: 13 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ Please document all notable changes to this project in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added

* Validation of component slug ([#153])

## [v0.2.2]

### Fixed

* Ignore filename too long ([#147])
* Ignore filename too long ([#151])

## [v0.2.1]

### Fixed

* Read token from file ([#146])
* Read token from file ([#148])

## [v0.2.0]

Expand Down Expand Up @@ -101,7 +107,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

Initial implementation

[Unreleased]: https://github.com/projectsyn/commodore/compare/v0.2.0...HEAD
[Unreleased]: https://github.com/projectsyn/commodore/compare/v0.2.2...HEAD
[v0.1.0]: https://github.com/projectsyn/commodore/releases/tag/v0.1.0
[v0.1.1]: https://github.com/projectsyn/commodore/releases/tag/v0.1.1
[v0.1.2]: https://github.com/projectsyn/commodore/releases/tag/v0.1.2
Expand All @@ -111,6 +117,7 @@ Initial implementation
[v0.1.6]: https://github.com/projectsyn/commodore/releases/tag/v0.1.6
[v0.2.0]: https://github.com/projectsyn/commodore/releases/tag/v0.2.0
[v0.2.1]: https://github.com/projectsyn/commodore/releases/tag/v0.2.1
[v0.2.2]: https://github.com/projectsyn/commodore/releases/tag/v0.2.2
[#53]: https://github.com/projectsyn/commodore/pull/53
[#58]: https://github.com/projectsyn/commodore/pull/58
[#81]: https://github.com/projectsyn/commodore/pull/81
Expand All @@ -133,4 +140,6 @@ Initial implementation
[#140]: https://github.com/projectsyn/commodore/pull/140
[#143]: https://github.com/projectsyn/commodore/pull/143
[#145]: https://github.com/projectsyn/commodore/pull/145
[#146]: https://github.com/projectsyn/commodore/pull/146
[#148]: https://github.com/projectsyn/commodore/pull/148
[#151]: https://github.com/projectsyn/commodore/pull/151
[#153]: https://github.com/projectsyn/commodore/pull/153
2 changes: 1 addition & 1 deletion commodore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def component_new(config: Config, slug, name, lib, pp, owner, copyright_holder,
f.create()


@component.command(name='compile', short_help='Compile a single component')
@component.command(name='compile', short_help='Compile a single component.')
@click.argument('path', type=click.Path(exists=True, file_okay=False, dir_okay=True))
@click.option('-f', '--values', multiple=True,
type=click.Path(exists=True, file_okay=True, dir_okay=False),
Expand Down
10 changes: 10 additions & 0 deletions commodore/component/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ def __init__(self, config, slug):
self.slug = slug
self.today = datetime.date.today()

@property
def slug(self):
return self._slug

@slug.setter
def slug(self, slug):
if slug.startswith('component-'):
raise click.ClickException('The component slug may not start with "component-"')
self._slug = slug

@property
def name(self):
if not self._name:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_component_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,14 @@ def test_run_component_new_command_with_name(tmp_path: P):
data = file.read()
assert component_name in data
assert component_slug not in data


def test_run_component_new_command_with_illegal_slug(tmp_path: P):
"""
Run the component new command with an illegal slug
"""

setup_directory(tmp_path)
component_slug = 'component-test-illegal'
exit_status = os.system(f"commodore -vvv component new {component_slug}")
assert exit_status != 0