Skip to content

Commit

Permalink
Remove usage of grep and pipes in hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
CasperWA committed Aug 22, 2023
1 parent d601906 commit f502549
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions ci_cd/tasks/api_reference_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,22 +366,22 @@ def write_file(full_path: Path, content: str) -> None:
# Check if there have been any changes.
# List changes if yes.

# NOTE: grep returns an exit code of 1 if it doesn't find anything
# (which will be good in this case).
# Concerning the weird last grep command see:
# NOTE: Concerning the weird regular expression, see:
# http://manpages.ubuntu.com/manpages/precise/en/man1/git-status.1.html
result = context.run(

Check warning on line 371 in ci_cd/tasks/api_reference_docs.py

View check run for this annotation

Codecov / codecov/patch

ci_cd/tasks/api_reference_docs.py#L371

Added line #L371 was not covered by tests
f'git -C "{root_repo_path}" status --porcelain '
f"{docs_api_ref_dir.relative_to(root_repo_path)} | "
"grep -E '^[? MARC][?MD]' || exit 0",
f"{docs_api_ref_dir.relative_to(root_repo_path)}",
hide=True,
)
if result.stdout:
sys.exit(
f"{Emoji.CURLY_LOOP.value} The following files have been "
f"changed/added/removed:\n\n{result.stdout}\nPlease stage them:\n\n"
f" git add {docs_api_ref_dir.relative_to(root_repo_path)}"
)
for line in result.stdout.splitlines():
if re.match(r"^[? MARC][?MD]", line):
sys.exit(

Check warning on line 379 in ci_cd/tasks/api_reference_docs.py

View check run for this annotation

Codecov / codecov/patch

ci_cd/tasks/api_reference_docs.py#L377-L379

Added lines #L377 - L379 were not covered by tests
f"{Emoji.CURLY_LOOP.value} The following files have been "
f"changed/added/removed:\n\n{result.stdout}\n"
"Please stage them:\n\n"
f" git add {docs_api_ref_dir.relative_to(root_repo_path)}"
)
print(
f"{Emoji.CHECK_MARK.value} No changes - your API reference documentation "
"is up-to-date !"
Expand Down
20 changes: 10 additions & 10 deletions ci_cd/tasks/docs_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Create the documentation index (home) page from `README.md`.
"""
import re
import sys
from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -87,22 +88,21 @@ def create_docs_index( # pylint: disable=too-many-locals
# Check if there have been any changes.
# List changes if yes.

# NOTE: grep returns an exit code of 1 if it doesn't find anything
# (which will be good in this case).
# Concerning the weird last grep command see:
# NOTE: Concerning the weird regular expression, see:
# http://manpages.ubuntu.com/manpages/precise/en/man1/git-status.1.html
result: "Result" = context.run( # type: ignore[no-redef]
f'git -C "{root_repo_path}" status --porcelain '
f"{docs_index.relative_to(root_repo_path)} | "
"grep -E '^[? MARC][?MD]' || exit 0",
f"{docs_index.relative_to(root_repo_path)}",
hide=True,
)
if result.stdout:
sys.exit(
f"{Emoji.CURLY_LOOP.value} The landing page has been updated.\n\n"
"Please stage it:\n\n"
f" git add {docs_index.relative_to(root_repo_path)}"
)
for line in result.stdout.splitlines():
if re.match(r"^[? MARC][?MD]", line):
sys.exit(

Check warning on line 101 in ci_cd/tasks/docs_index.py

View check run for this annotation

Codecov / codecov/patch

ci_cd/tasks/docs_index.py#L99-L101

Added lines #L99 - L101 were not covered by tests
f"{Emoji.CURLY_LOOP.value} The landing page has been updated."
"\n\nPlease stage it:\n\n"
f" git add {docs_index.relative_to(root_repo_path)}"
)
print(
f"{Emoji.CHECK_MARK.value} No changes - your landing page is up-to-date !"
)

0 comments on commit f502549

Please sign in to comment.