Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DX: autoupdate PR title in precommit.ci #265

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/repoma/check_dev_files/precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from repoma.errors import PrecommitError
from repoma.utilities import CONFIG_PATH
from repoma.utilities.executor import Executor
from repoma.utilities.precommit import PrecommitConfig
from repoma.utilities.precommit import PrecommitConfig, load_round_trip_precommit_config
from repoma.utilities.yaml import create_prettier_round_trip_yaml


Expand All @@ -20,6 +20,7 @@
executor = Executor()
executor(_sort_hooks)
executor(_update_conda_environment, cfg)
executor(_update_precommit_ci_commit_msg)

Check warning on line 23 in src/repoma/check_dev_files/precommit.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/precommit.py#L23

Added line #L23 was not covered by tests
executor(_update_precommit_ci_skip, cfg)
executor.finalize()

Expand Down Expand Up @@ -47,6 +48,26 @@
return (2, hooks[0]["id"])


def _update_precommit_ci_commit_msg() -> None:
if not CONFIG_PATH.precommit.exists():
return
config, yaml = load_round_trip_precommit_config()
precommit_ci: CommentedMap | None = config.get("ci")

Check warning on line 55 in src/repoma/check_dev_files/precommit.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/precommit.py#L53-L55

Added lines #L53 - L55 were not covered by tests
if precommit_ci is None:
return

Check warning on line 57 in src/repoma/check_dev_files/precommit.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/precommit.py#L57

Added line #L57 was not covered by tests
if CONFIG_PATH.pip_constraints.exists():
expected_msg = "MAINT: autoupdate pre-commit hooks"

Check warning on line 59 in src/repoma/check_dev_files/precommit.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/precommit.py#L59

Added line #L59 was not covered by tests
else:
expected_msg = "MAINT: autoupdate pre-commit hooks"
key = "autoupdate_commit_msg"
autoupdate_commit_msg = precommit_ci.get(key)

Check warning on line 63 in src/repoma/check_dev_files/precommit.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/precommit.py#L61-L63

Added lines #L61 - L63 were not covered by tests
if autoupdate_commit_msg != expected_msg:
precommit_ci[key] = expected_msg
yaml.dump(config, CONFIG_PATH.precommit)
msg = f"Updated ci.{key} in {CONFIG_PATH.precommit} to {expected_msg!r}"
raise PrecommitError(msg)

Check warning on line 68 in src/repoma/check_dev_files/precommit.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/precommit.py#L65-L68

Added lines #L65 - L68 were not covered by tests


def _update_precommit_ci_skip(config: PrecommitConfig) -> None:
if config.ci is None:
return
Expand Down
Loading