Skip to content

Commit

Permalink
fix: support both YAML extensions: .yml and .yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Peterka committed Feb 26, 2024
1 parent 29a50fb commit 5843727
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
Gira reacts to changes in your dependency files and bring you JIRA tickets mentioned in commits between current and updated version of the dependencies. Supported dependency files are

- pyproject.toml
- west.yaml
- pubspec.yaml
- west.yaml/yml
- pubspec.yaml/yml

Gira is especially usefull with [pre-commit](https://pre-commit.com) but is great for changelog enhancements when called as `gira --format markdown -r <previousTag>`

__Pssst__: works the best if your dependencies follow [semantic release](https://semantic-release.gitbook.io/semantic-release/) thus have tags in `vX.Y.*` format.


## Usage
## Usage - standalone

```bash
gira [-r revision] [-c config] [--format="commit|detail|markdown"]
Expand All @@ -30,13 +30,18 @@ other-followed-lib <versionB> => <versionB>: JIRA-876, JIRA-543

Config file is by default _.gira.yaml_ but can be pretty much any YAML or pyproject.toml. See section bellow.

## Pre-commit
## Usage - Pre-commit

```bash
$ pip install pre-commit
$ pre-commit install -t prepare-commit-msg -t pre-commit -t commit-msg
```

Add to your .pre-commit-config.yaml

```yaml
- repo: https://github.com/dronetag/gira
rev: v1.0.0
rev: v1.0.1
hooks:
- id: gira
# if you use other config than .gira.yaml then
Expand Down
14 changes: 1 addition & 13 deletions gira/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def _parse_file(path: Path) -> Config:
config = _conf(path)
elif path.name == "pyproject.toml":
config = _pytoml(path)
elif path.name.startswith("west"):
config = _west(path)
elif path.name.endswith(".yaml"):
elif path.suffix in (".yaml", ".yml"):
config = _generic_yaml(path)
if not config.observe:
raise RuntimeError(f"No observed dependencies configured in {path}")
Expand Down Expand Up @@ -75,16 +73,6 @@ def _generic_yaml(path: Path) -> Config:
return Config(jira=_section(parsed, "gira.jira"), observe=_section(parsed, "gira.observe"))


def _west(path: Path) -> Config:
parsed = yaml.load(path.read_text(), Loader=yaml.SafeLoader)
jira = _section(parsed, "manifest.gira.jira")
observe = _section(parsed, "manifest.gira.observe")
return Config(
jira=jira,
observe=observe,
)


def _section(d: Optional[dict], path: str) -> dict:
"""Return dot-separated path from dictionary"""
for key in path.split("."):
Expand Down
6 changes: 3 additions & 3 deletions gira/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from . import logger

version_re = re.compile(r"""([0-9]+\.[0-9]+[^"',]*)""")
parseable_filenames = ("pyproject.toml", "pubspec.yaml", "west.yaml")
parseable_filenames = ("pyproject.toml", "pubspec.yaml", "pubspec.yml", "west.yaml", "west.yml")


def parseable(filepath: Path) -> bool:
Expand All @@ -24,9 +24,9 @@ def parseable(filepath: Path) -> bool:
def parse(path: Path, content: str, observed: dict[str, str]) -> dict[str, str]:
if path.name == "pyproject.toml":
return parse_pytoml(content, observed)
if path.name == "pubspec.yaml":
if path.name in ("pubspec.yaml", "pubspec.yml"):
return parse_pubspec_yaml(content, observed)
if path.name == "west.yaml":
if path.name in ("west.yaml", "west.yml"):
return parse_west_yaml(content, observed)
raise NotImplementedError(f"No dependency parser for {path.name}")

Expand Down

0 comments on commit 5843727

Please sign in to comment.