Skip to content

Commit

Permalink
chore: fix docs and annotations and permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
katomaso committed May 2, 2024
1 parent 0e43750 commit 464230a
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Gira reacts to changes in your dependency files and bring you JIRA tickets menti
- 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>`
Gira is especially useful 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.

Expand All @@ -24,8 +24,8 @@ commit messages. The markdown version is intended for changelogs.

```bash
$ gira [--format=commit]
internal-dependency1 <versionB> => <versionB>: JIRA-123, JIRA-567
other-followed-lib <versionB> => <versionB>: JIRA-876, JIRA-543
internal-dependency1 <versionA> => <versionB>: JIRA-123, JIRA-567
other-followed-lib <versionA> => <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.
Expand Down Expand Up @@ -94,7 +94,7 @@ as follows:

```bash
$ gira
internal-dependency1 <versionB> => <versionB>:
internal-dependency1 <versionA> => <versionB>:
JIRA-123: details about the issue (url)
JIRA-567: details about the issue (url)
```
8 changes: 7 additions & 1 deletion gira/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ class Upgrade:
new_version: Optional[str]
messages: Optional[list[str]]

def __init__(self, name, old_version=None, new_version=None, messages=None):
def __init__(
self,
name: str,
old_version: Optional[str] = None,
new_version: Optional[str] = None,
messages=None,
):
self.name = name
self.old_version = old_version
self.new_version = new_version
Expand Down
11 changes: 6 additions & 5 deletions gira/deps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Dependencies module reads different """
"""Dependencies module reads different"""

import re
import sys

Expand All @@ -13,12 +14,12 @@
from . import logger

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


def parseable(filepath: Path) -> bool:
def parsable(filepath: Path) -> bool:
"""Extract changes in observed dependencies from dependency/lock files diffs"""
return filepath.name in parseable_filenames
return filepath.name in parsable_filenames


def parse(path: Path, content: str, observed: dict[str, str]) -> dict[str, str]:
Expand All @@ -36,7 +37,7 @@ def parse_pytoml(content: str, observed: dict[str, str]) -> dict[str, str]:
parsed = toml.loads(content)

if _section(parsed, "project.dependencies"):
"""Parse standart pytoml dependencies definition
"""Parse standard pytoml dependencies definition
Example:
[project]
Expand Down
13 changes: 7 additions & 6 deletions gira/formatter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Iterable, TextIO
from abc import ABC
from typing import Iterable, Optional, TextIO

from .core import Upgrade
from .jira import Ticket
Expand All @@ -14,28 +15,28 @@ def get_formatter(name: str, stream: TextIO):
raise ValueError(f"Unknown format {name}")


class Formatter:
class Formatter(ABC):
needs_details: bool

def __init__(self, stream: TextIO):
self._stream = stream

def print(self, upgrade: Upgrade, tickets: Iterable[Ticket]):
raise NotImplementedError()
def print(self, upgrade: Upgrade, tickets: Iterable[Ticket]) -> None:
"""Write textual representation of the upgrade and tickets to the internal stream."""


class CommitFormatter(Formatter):
needs_details = False

def print(self, upgrade: Upgrade, tickets: Iterable[Ticket]):
def print(self, upgrade: Upgrade, tickets: Iterable[Ticket]) -> None:
chars = 0
sep = " "
self._stream.write("\n")
chars += self._stream.write(f"Dep-Change: {upgrade.name} ")
if chars > 70:
chars = self._stream.write("\n ")

def _s(s): # shorten
def _s(s: Optional[str]) -> Optional[str]: # shorten
return s[:7] if s and len(s) > 10 else s

chars += self._stream.write(f"({_s(upgrade.old_version)} -> {_s(upgrade.new_version)})")
Expand Down
4 changes: 2 additions & 2 deletions gira/gira.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def gira(config: config.Config, stream: TextIO, format: str, ref: Optional[str])

# extract changes from diffs of locks or other dependency specifying files
upgrades: list[core.Upgrade] = []
for file in filter(deps.parseable, files):
for file in filter(deps.parsable, files):
logger.debug(f"Processing {file} for dependencies")
pre = deps.parse(file, repository.get_old_content(file), config.observe)
post = deps.parse(file, repository.get_current_content(file), config.observe)
Expand Down Expand Up @@ -68,7 +68,7 @@ def gira(config: config.Config, stream: TextIO, format: str, ref: Optional[str])
f" {upgrade.old_version}: {upgrade.messages}"
)
tickets = {ticket for m in upgrade.messages for ticket in jira.extract_ticket_names(m)}

logger.debug(f"Extracted tickets: {tickets}")
if len(tickets) == 0:
logger.info(
f"No JIRA tickets found in commits for {upgrade.name} between"
Expand Down
2 changes: 1 addition & 1 deletion gira/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Ticket:
url: str
summary: str

def __init__(self, name, url="", summary=""):
def __init__(self, name: str, url: str = "", summary: str = ""):
self.name = name
self.url = url
self.summary = summary
Expand Down
Empty file modified run_tests.sh
100644 → 100755
Empty file.

0 comments on commit 464230a

Please sign in to comment.