Skip to content

Commit

Permalink
Renamed rule to galaxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Sep 16, 2022
1 parent 0b0a16d commit 83f8aac
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
5 changes: 2 additions & 3 deletions examples/meta/galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: foo
namespace: bar
version: 0.2.3
version: 0.2.3 # <-- that version is not valid, should be 1.0.0 or greater
authors:
- John
readme: ../README.md
Expand All @@ -11,5 +11,4 @@ dependencies:
other_namespace.collection2: ">=2.0.0,<3.0.0"
anderson55.my_collection: "*" # note: "*" selects the highest version available
license:
- GPL # <-- invalid license values based on galaxy schema
- Apache
- Apache-2.0
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
# galaxy collection version
# galaxy

This rule identifies if the collection version mentioned in galaxy.yml is ideal in terms of the version number being greater than or equal to 1.0.0.
This rule identifies if the collection version mentioned in galaxy.yml is ideal in terms of the version number being greater than or equal to `1.0.0`.

This rule can produce messages such:

- `collection-version-missing[galaxy]` - galaxy.yaml should have version tag.
- `collection-version[galaxy]` - collection version should be greater than or equal to 1.0.0
- `galaxy[version-missing]` - `galaxy.yaml` should have version tag.
- `galaxy[version-incorrect]` - collection version should be greater than or equal to `1.0.0`

If you want to ignore some of the messages above, you can add any of them to
the `ignore_list`.

## Problematic code

# galaxy.yml

```yaml
# galaxy.yml
---
name: foo
namespace: bar
version: 0.2.3 # <-- collection version should be <= 1.0.0
version: 0.2.3 # <-- collection version should be >= 1.0.0
authors:
- John
readme: ../README.md
Expand All @@ -27,9 +26,8 @@ description: "..."

## Correct code

# galaxy.yml

```yaml
# galaxy.yml
---
name: foo
namespace: bar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Implementation of GalaxyCollectionVersionRule."""
"""Implementation of GalaxyRule."""
from __future__ import annotations

import sys
Expand All @@ -16,10 +16,10 @@
from ansiblelint.file_utils import Lintable


class GalaxyCollectionVersionRule(AnsibleLintRule):
class GalaxyRule(AnsibleLintRule):
"""Rule for checking collection version is greater than 1.0.0."""

id = "galaxy-collection-version"
id = "galaxy"
description = "Confirm via galaxy.yml file if collection version is greater than or equal to 1.0.0"
severity = "MEDIUM"
tags = ["metadata"]
Expand All @@ -34,7 +34,7 @@ def matchplay(self, file: Lintable, data: odict[str, Any]) -> list[MatchError]:
self.create_matcherror(
message="galaxy.yaml should have version tag.",
linenumber=data[LINE_NUMBER_KEY],
tag="collection-version-missing[galaxy]",
tag="galaxy[version-missing]",
filename=file,
)
]
Expand All @@ -43,7 +43,7 @@ def matchplay(self, file: Lintable, data: odict[str, Any]) -> list[MatchError]:
self.create_matcherror(
message="collection version should be greater than or equal to 1.0.0",
linenumber=data[LINE_NUMBER_KEY],
tag="collection-version[galaxy]",
tag="galaxy[version-incorrect]",
filename=file,
)
]
Expand Down Expand Up @@ -93,16 +93,16 @@ def _coerce(other: object) -> Version:
def test_galaxy_collection_version_positive() -> None:
"""Positive test for collection version in galaxy."""
collection = RulesCollection()
collection.register(GalaxyCollectionVersionRule())
collection.register(GalaxyRule())
success = "examples/galaxy.yml"
good_runner = Runner(success, rules=collection)
assert [] == good_runner.run()

def test_galaxy_collection_version_negative() -> None:
"""Negative test for collection version in galaxy."""
collection = RulesCollection()
collection.register(GalaxyCollectionVersionRule())
collection.register(GalaxyRule())
failure = "examples/meta/galaxy.yml"
bad_runner = Runner(failure, rules=collection)
errs = bad_runner.run()
assert len(errs) == 3
assert len(errs) == 1

0 comments on commit 83f8aac

Please sign in to comment.