Skip to content

Commit

Permalink
feat: Add Markdown and GitHub output formats to the griffe check co…
Browse files Browse the repository at this point in the history
…mmand

These two features are merged from Insiders as the second funding goal ($1000/month) is reached.
  • Loading branch information
pawamoy committed Oct 11, 2024
1 parent 6a9ca1d commit 806805c
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
4 changes: 2 additions & 2 deletions docs/guide/users/checking.md
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ $ griffe check griffe -ssrc -b0.46.0 -a0.45.0 --verbose
[](){#format-markdown}
### Markdown

[:octicons-heart-fill-24:{ .pulse } Sponsors only](../../insiders/index.md){ .insiders } — [:octicons-tag-24: Insiders 1.0.0](../../insiders/changelog.md#1.0.0)
[:octicons-tag-24: Insiders 1.0.0](../../insiders/changelog.md#1.0.0)

- **CLI**: `-f markdown`
- **API**: `check(..., style="markdown")` / `check(..., style=ExplanationStyle.MARKDOWN)`
Expand Down Expand Up @@ -705,7 +705,7 @@ The Markdown format is adapted for changelogs. It doesn't show the file and line
[](){#format-github}
### GitHub

[:octicons-heart-fill-24:{ .pulse } Sponsors only](../../insiders/index.md){ .insiders } — [:octicons-tag-24: Insiders 1.0.0](../../insiders/changelog.md#1.0.0)
[:octicons-tag-24: Insiders 1.0.0](../../insiders/changelog.md#1.0.0)

- **CLI**: `-f github`
- **API**: `check(..., style="github")` / `check(..., style=ExplanationStyle.GITHUB)`
Expand Down
2 changes: 1 addition & 1 deletion src/_griffe/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def add_subparser(command: str, text: str, **kwargs: Any) -> argparse.ArgumentPa
help="Force disable colors in the output.",
)
check_options.add_argument("-v", "--verbose", action="store_true", help="Verbose output.")
formats = ("oneline", "verbose")
formats = [fmt.value for fmt in ExplanationStyle]
check_options.add_argument("-f", "--format", dest="style", choices=formats, default=None, help="Output format.")
add_common_options(check_parser)

Expand Down
40 changes: 38 additions & 2 deletions src/_griffe/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,46 @@ def _explain_verbose(self) -> str:
return "\n".join(lines)

def _explain_markdown(self) -> str:
return self._explain_oneline()
explanation = f"- `{self._canonical_path}`: *{self.kind.value}*"
old = self._format_old_value()
if old != "unset":
old = f"`{old}`"
new = self._format_new_value()
if new != "unset":
new = f"`{new}`"
if old and new:
change = f"{old} -> {new}"
elif old:
change = old
elif new:
change = new
else:
change = ""
if change:
return f"{explanation}: {change}"
return explanation

def _explain_github(self) -> str:
return self._explain_oneline()
location = f"file={self._location},line={self._lineno}"
title = f"title={self._format_title()}"
explanation = f"::warning {location},{title}::{self.kind.value}"
old = self._format_old_value()
if old != "unset":
old = f"`{old}`"
new = self._format_new_value()
if new != "unset":
new = f"`{new}`"
if old and new:
change = f"{old} -> {new}"
elif old:
change = old
elif new:
change = new
else:
change = ""
if change:
return f"{explanation}: {change}"
return explanation


class ParameterMovedBreakage(Breakage):
Expand Down

0 comments on commit 806805c

Please sign in to comment.