Skip to content

Commit

Permalink
Skip PR with skip changelog (#33)
Browse files Browse the repository at this point in the history
* Skip PR with skip changelog

* Pop skip

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add group config to test

* Correct type hint for group config

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
cidrblock and pre-commit-ci[bot] authored May 15, 2023
1 parent fff7a34 commit 14cedf5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
26 changes: 17 additions & 9 deletions antsichaut/antsichaut.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import cached_property
from importlib.metadata import version as _version
from pathlib import Path
from typing import Any, Optional
from typing import Any, Optional, Sequence

import configargparse
import requests
Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__( # noqa: PLR0913
repository: str,
since_version: str,
to_version: str,
group_config: list[dict[str, str]],
group_config: list[dict[str, Sequence[str]]],
filename: str = "changelogs/changelog.yaml",
token: Optional[str] = None,
) -> None:
Expand Down Expand Up @@ -257,14 +257,19 @@ def parse_changelog( # noqa: C901, PLR0912
)

leftover_changes = []

skip_labels = self.group_config.pop(
[i for i, d in enumerate(self.group_config) if d["title"] == "skip_changelog"][0],
)["labels"]

for pull_request in changes:
# if a PR contains a skip changelog label, ignore it entirely
# do not add it to the changelog
if any(label in pull_request["labels"] for label in skip_labels):
break

for config in self.group_config:
if any(label in pull_request["labels"] for label in config["labels"]):
# if a PR contains a skip changelog label,
# do not add it to the changelog
if config["title"] in ["skip_changelog", "skip-changelog", "skipchangelog"]:
break

change_type = config["title"]

# add the new change section if it does not exist yet
Expand Down Expand Up @@ -473,7 +478,10 @@ def main() -> None:
dest="skip_changelog_labels",
type=str,
action="append",
help="the labels for skip_changelog. Default: ['skip_changelog']",
help=(
"the labels for skip_changelog. "
"Default: ['skip_changelog', 'skip-changelog', 'skipchangelog']"
),
env_var="SKIP_CHANGELOG_LABELS",
required=False,
)
Expand All @@ -500,7 +508,7 @@ def main() -> None:
if not args.bugfixes_labels:
args.bugfixes_labels = ["bug", "bugfix"]
if not args.skip_changelog_labels:
args.skip_changelog_labels = ["skip_changelog"]
args.skip_changelog_labels = ["skip_changelog", "skip-changelog", "skipchangelog"]

repository = args.repository
since_version = args.since_version
Expand Down
10 changes: 8 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

REPO = "ansible-community/antsichaut"
FIXTURE_DIR = Path(__file__).parent / "fixtures"
GROUP_CONFIG = [
{
"title": "skip_changelog",
"labels": ["skip_changelog", "skip-changelog", "skipchangelog"],
},
]


def test_failure(capsys: pytest.CaptureFixture[str]) -> None:
Expand All @@ -29,7 +35,7 @@ def test_failure(capsys: pytest.CaptureFixture[str]) -> None:
repository=REPO,
since_version="0.0.0",
to_version="",
group_config=[],
group_config=GROUP_CONFIG,
)
cci.run()
captured = capsys.readouterr()
Expand Down Expand Up @@ -86,7 +92,7 @@ def _write_changelog(self) -> None:
repository=REPO,
since_version="0.3.2",
to_version="0.3.5",
group_config=[],
group_config=GROUP_CONFIG,
token=token,
)
cci.run()
Expand Down

0 comments on commit 14cedf5

Please sign in to comment.