diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index d0cc61cd..00000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: "" -labels: Bug -assignees: "" ---- - -## Bug description - - - - - -## How to reproduce? - -Steps to reproduce the behavior: - -1. - -## Expected behavior - - - -## System info - -Bug resulted on the following system: - -- OS: -- Version -- Python version: -- Virtual environment: diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 049eb32b..00000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: "" -labels: "✨ Enhancement" -assignees: "" ---- - -## Problem description - - - -## Proposed solution - - - - - - - diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index 14b80852..00000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,11 +0,0 @@ - - - - - diff --git a/.vscode/settings.json b/.vscode/settings.json index 5b4b86e9..0622e029 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -56,8 +56,6 @@ ".constraints/*.txt": true, ".github/workflows/cd.yml": true, ".github/workflows/ci.yml": true, - "src/repoma/.github/ISSUE_TEMPLATE": true, - "src/repoma/.github/pull_request_template.md": true, "src/repoma/.github/workflows/clean-caches.yml": true, "src/repoma/.github/workflows/pr-linting.yml": true, "src/repoma/.github/workflows/release-drafter.yml": true, diff --git a/src/repoma/.github/ISSUE_TEMPLATE b/src/repoma/.github/ISSUE_TEMPLATE deleted file mode 120000 index 335e0ae7..00000000 --- a/src/repoma/.github/ISSUE_TEMPLATE +++ /dev/null @@ -1 +0,0 @@ -../../../.github/ISSUE_TEMPLATE/ \ No newline at end of file diff --git a/src/repoma/.github/pull_request_template.md b/src/repoma/.github/pull_request_template.md deleted file mode 120000 index 95e1395f..00000000 --- a/src/repoma/.github/pull_request_template.md +++ /dev/null @@ -1 +0,0 @@ -../../../.github/pull_request_template.md \ No newline at end of file diff --git a/src/repoma/check_dev_files/__init__.py b/src/repoma/check_dev_files/__init__.py index 05835be7..482a9c74 100644 --- a/src/repoma/check_dev_files/__init__.py +++ b/src/repoma/check_dev_files/__init__.py @@ -14,7 +14,6 @@ cspell, editorconfig, github_labels, - github_templates, github_workflows, gitpod, mypy, @@ -65,6 +64,12 @@ def main(argv: Optional[Sequence[str]] = None) -> int: required=False, type=str, ) + parser.add_argument( + "--keep-issue-templates", + help="Do not remove the .github/ISSUE_TEMPLATE directory", + action="store_true", + default=False, + ) parser.add_argument( "--ignore-author", action="store_true", @@ -165,7 +170,6 @@ def main(argv: Optional[Sequence[str]] = None) -> int: executor(editorconfig.main, args.no_python) if not args.allow_labels: executor(github_labels.main) - executor(github_templates.main) executor( github_workflows.main, allow_deprecated=args.allow_deprecated_workflows, @@ -194,7 +198,7 @@ def main(argv: Optional[Sequence[str]] = None) -> int: executor(pyupgrade.main) executor(ruff.main) executor(setup_cfg.main, args.ignore_author) - executor(remove_deprecated_tools) + executor(remove_deprecated_tools, args.keep_issue_templates) executor(vscode.main) if not args.no_gitpod: executor(gitpod.main) diff --git a/src/repoma/check_dev_files/deprecated.py b/src/repoma/check_dev_files/deprecated.py index 9df1f047..3c5d972c 100644 --- a/src/repoma/check_dev_files/deprecated.py +++ b/src/repoma/check_dev_files/deprecated.py @@ -1,5 +1,6 @@ """Remove deprecated linters and formatters.""" import os +import shutil from typing import TYPE_CHECKING, List from repoma.errors import PrecommitError @@ -18,10 +19,12 @@ from tomlkit.items import Table -def remove_deprecated_tools() -> None: +def remove_deprecated_tools(keep_issue_templates: bool) -> None: executor = Executor() executor(_remove_flake8) executor(_remove_isort) + if not keep_issue_templates: + executor(_remove_github_issue_templates) executor(_remove_pydocstyle) executor(_remove_pylint) executor.finalize() @@ -85,6 +88,15 @@ def __remove_nbqa_option(option: str) -> None: raise PrecommitError(msg) +def _remove_github_issue_templates() -> None: + __remove_configs( + [ + ".github/ISSUE_TEMPLATE", + ".github/pull_request_template.md", + ] + ) + + def _remove_pydocstyle() -> None: executor = Executor() executor( @@ -122,7 +134,10 @@ def __remove_configs(paths: List[str]) -> None: def __remove_file(path: str) -> None: if not os.path.exists(path): return - os.remove(path) + if os.path.isdir(path): + shutil.rmtree(path) + else: + os.remove(path) msg = f"Removed {path}" raise PrecommitError(msg) diff --git a/src/repoma/check_dev_files/github_templates.py b/src/repoma/check_dev_files/github_templates.py deleted file mode 100644 index 160163c7..00000000 --- a/src/repoma/check_dev_files/github_templates.py +++ /dev/null @@ -1,83 +0,0 @@ -"""Check existing issue and PR templates for GitHub.""" - -import os -import shutil -from pathlib import Path -from typing import List - -from repoma.errors import PrecommitError -from repoma.utilities import REPOMA_DIR -from repoma.utilities.executor import Executor - -__PR_TEMPLATE_PATH = Path(".github/pull_request_template.md") -__ISSUE_TEMPLATE_PATH = Path(".github/ISSUE_TEMPLATE") - - -def main() -> None: - executor = Executor() - executor(_check_pr_template) - executor(_check_issue_templates) - executor.finalize() - - -def _check_issue_templates() -> None: - existing_templates = _list_template_files(__ISSUE_TEMPLATE_PATH) - expected_templates = _list_template_files(REPOMA_DIR / __ISSUE_TEMPLATE_PATH) - error_message = "" - if set(existing_templates) != set(expected_templates): - shutil.rmtree(__ISSUE_TEMPLATE_PATH, ignore_errors=True) - os.makedirs(__ISSUE_TEMPLATE_PATH, exist_ok=True) - error_message = f"{__ISSUE_TEMPLATE_PATH} doesn't contain expected templates:\n" - for basename in expected_templates: - import_path = REPOMA_DIR / __ISSUE_TEMPLATE_PATH / basename - export_path = __ISSUE_TEMPLATE_PATH / basename - expected_content = __get_template_content(import_path) - existing_content = "" - if os.path.exists(export_path): - existing_content = __get_template_content(export_path) - if expected_content != existing_content: - if error_message == "": - error_message = "The following issue have been updated:\n`" - error_message += f" {export_path}\n" - __write_template(expected_content, export_path) - if error_message: - error_message += "Problem has been fixed." - raise PrecommitError(error_message) - - -def _check_pr_template() -> None: - if not os.path.exists(__PR_TEMPLATE_PATH): - os.makedirs(os.path.dirname(__PR_TEMPLATE_PATH), exist_ok=True) - expected_content = __get_template_content(REPOMA_DIR / __PR_TEMPLATE_PATH) - __write_template(expected_content, __PR_TEMPLATE_PATH) - msg = ( - f"This repository has no {__PR_TEMPLATE_PATH} file. Problem has been fixed." - ) - raise PrecommitError(msg) - with open(__PR_TEMPLATE_PATH) as stream: - template_content = stream.read() - expected_content = __get_template_content(REPOMA_DIR / __PR_TEMPLATE_PATH) - if template_content != expected_content: - __write_template(expected_content, path=__PR_TEMPLATE_PATH) - msg = ( - f"PR template {__PR_TEMPLATE_PATH} does not contain expected content." - " Problem has been fixed." - ) - raise PrecommitError(msg) - - -def __get_template_content(path: Path) -> str: - with open(path) as stream: - return stream.read() - - -def _list_template_files(directory: Path) -> List[str]: - template_files = [] - for _, __, files in os.walk(directory): # pyright: ignore[reportUnusedVariable] - template_files.extend(files) - return template_files - - -def __write_template(content: str, path: Path) -> None: - with open(path, "w") as stream: - stream.write(content) diff --git a/tests/check_dev_files/test_github_templates.py b/tests/check_dev_files/test_github_templates.py deleted file mode 100644 index 0a5fdfa2..00000000 --- a/tests/check_dev_files/test_github_templates.py +++ /dev/null @@ -1,10 +0,0 @@ -from repoma.check_dev_files.github_templates import _list_template_files -from repoma.utilities import REPOMA_DIR - - -def test_list_issue_templates(): - files = _list_template_files(REPOMA_DIR / ".github/ISSUE_TEMPLATE") - assert set(files) == { - "bug_report.md", - "feature_request.md", - }