Repository: imAsparky/django-cookiecutter

Issue:
[DOCS]: Add django project custom issue templates
**Describe alternatives you've considered**
Would you please share your clear and concise description of any alternative/similar documentation you've considered.



**Additional context**
Would you please share any other context or screenshots about the documentation request here.



Discussion:

Resolving patch:
diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py
--- a/hooks/post_gen_project.py
+++ b/hooks/post_gen_project.py
@@ -1,9 +1,9 @@
 #!/usr/bin/env python
 """django-cookiecutter post project generation jobs."""
-# import os
-# import subprocess  # nosec
+import os
+import subprocess  # nosec
 
-# PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
+PROJECT_DIRECTORY = os.path.realpath(os.path.curdir)
 
 # REMOTE_REPO = "git@github.com:{{cookiecutter.github_username}}/\
 # {{cookiecutter.git_project_name}}.git"
@@ -13,30 +13,41 @@
 # GIT_EMAIL = "{{cookiecutter.github_user_email}}"
 
 
-# def post_gen_setup(*args, supress_exception=False, cwd=None):
-#     """Helper to set up the Django project with the chosen options."""
-#     cur_dir = os.getcwd()
+def post_gen_setup(*args, supress_exception=False, cwd=None):
+    """Helper to set up the Django project with the chosen options."""
+    cur_dir = os.getcwd()
 
-#     try:
-#         if cwd:
-#             os.chdir(cwd)
+    try:
+        if cwd:
+            os.chdir(cwd)
 
-#         with subprocess.Popen(  # nosec
-#             args, stdout=subprocess.PIPE, stderr=subprocess.PIPE
-#         ) as proc:
+        with subprocess.Popen(  # nosec
+            args, stdout=subprocess.PIPE, stderr=subprocess.PIPE
+        ) as proc:
 
-#             out, err = proc.communicate()
-#             out = out.decode("utf-8")
-#             err = err.decode("utf-8")
-#             if err and not supress_exception:
-#                 raise Exception(err)
-#             if err and supress_exception:
-#                 return out
+            out, err = proc.communicate()
+            out = out.decode("utf-8")
+            err = err.decode("utf-8")
+            if err and not supress_exception:
+                raise Exception(err)
+            if err and supress_exception:
+                return out
 
-#             return out
+            return out
 
-#     finally:
-#         os.chdir(cur_dir)
+    finally:
+        os.chdir(cur_dir)
+
+
+def delete_issue_templates():
+    """Delete the ISSUE_TEMPLATES folder."""
+
+    post_gen_setup(
+        "rm",
+        "-rf",
+        ".github/ISSUE_TEMPLATE",
+        cwd=PROJECT_DIRECTORY,
+    )
 
 
 # def init_git():
@@ -104,41 +115,35 @@
 #         )
 
 
-# def remove_file(filepath):
-#     """Remove files not required for this generated python package."""
-#     if os.path.exists(os.path.join(PROJECT_DIRECTORY, filepath)):
-#         os.remove(os.path.join(PROJECT_DIRECTORY, filepath))
+def remove_file(filepath):
+    """Remove files not required for this generated python package."""
+    if os.path.exists(os.path.join(PROJECT_DIRECTORY, filepath)):
+        os.remove(os.path.join(PROJECT_DIRECTORY, filepath))
 
 
 if __name__ == "__main__":
 
-    print("In main")
-
-
-# if "Not open source" == "{{ cookiecutter.open_source_license }}":
-#     remove_file("LICENSE")
+    # if "Not open source" == "{{ cookiecutter.open_source_license }}":
+    #     remove_file("LICENSE")
 
-# if "{{ cookiecutter.create_conventional_commits_edit_message }}" != "y":
-#     remove_file(".github/.git-commit-template.txt")
+    # if "{{ cookiecutter.create_conventional_commits_edit_message }}" != "y":
+    #     remove_file(".github/.git-commit-template.txt")
 
-# if "{{ cookiecutter.create_repo_auto_test_workflow }}" != "y":
-#     remove_file(".github/workflows/test_contribution.yaml")
+    # if "{{ cookiecutter.create_repo_auto_test_workflow }}" != "y":
+    #     remove_file(".github/workflows/test_contribution.yaml")
 
-# if "{{ cookiecutter.use_GH_action_semantic_version }}" != "y":
-#     remove_file(".github/workflows/semantic_release.yaml")
-#     remove_file(".github/semantic.yaml")
+    # if "{{ cookiecutter.use_GH_action_semantic_version }}" != "y":
+    #     remove_file(".github/workflows/semantic_release.yaml")
+    #     remove_file(".github/semantic.yaml")
 
-# if "{{ cookiecutter.use_GH_action_semantic_version }}" == "y":
-#     remove_file("HISTORY.rst")
+    # if "{{ cookiecutter.use_GH_action_semantic_version }}" == "y":
+    #     remove_file("HISTORY.rst")
 
-# if "{{ cookiecutter.use_GH_custom_issue_templates }}" != "y":
-#     remove_file(".github/ISSUE_TEMPLATE/bug-report.md")
-#     remove_file(".github/ISSUE_TEMPLATE/chore.md")
-#     remove_file(".github/ISSUE_TEMPLATE/documentation-request.md")
-#     remove_file(".github/ISSUE_TEMPLATE/feature-request.md")
+    if "{{ cookiecutter.use_GH_custom_issue_templates }}" == "y":
+        remove_file(".github/ISSUE_TEMPLATE.md")
+    else:
+        delete_issue_templates()
 
-# if "{{ cookiecutter.use_GH_custom_issue_templates }}" == "y":
-#     remove_file(".github/ISSUE_TEMPLATE.md")
 
 # if "{{ cookiecutter.use_pre_commit }}" != "y":
 #     remove_file(".pre-commit-config.yaml")


Test patch:
diff --git a/tests/test_bake_django.py b/tests/test_bake_django.py
--- a/tests/test_bake_django.py
+++ b/tests/test_bake_django.py
@@ -1,5 +1,7 @@
 """django-cookiecutter test suite."""
 
+import os
+
 
 def test_django_bakes_ok_with_defaults(cookies):
     """Test cookiecutter created the django project ok."""
@@ -12,6 +14,21 @@ def test_django_bakes_ok_with_defaults(cookies):
     assert default_django.project_path.name == "django-boilerplate"
 
 
+def test_baked_django_asgi_file(cookies):
+    """Test Django asgy.py file has generated correctly."""
+
+    default_django = cookies.bake()
+
+    asgi_path = default_django.project_path / "django_boilerplate/asgi.py"
+    asgi_file = asgi_path.read_text().splitlines()
+
+    assert "ASGI config for django-boilerplate project." in asgi_file
+    assert (
+        "os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_boilerplate.settings')"
+        in asgi_file
+    )
+
+
 def test_baked_django_settings_file(cookies):
     """Test Django settings.py file has generated correctly."""
 
@@ -32,21 +49,6 @@ def test_baked_django_settings_file(cookies):
     assert 'USE_L10N = "True"' in settings_file
 
 
-def test_baked_django_asgi_file(cookies):
-    """Test Django asgy.py file has generated correctly."""
-
-    default_django = cookies.bake()
-
-    asgi_path = default_django.project_path / "django_boilerplate/asgi.py"
-    asgi_file = asgi_path.read_text().splitlines()
-
-    assert "ASGI config for django-boilerplate project." in asgi_file
-    assert (
-        "os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_boilerplate.settings')"
-        in asgi_file
-    )
-
-
 def test_baked_django_urls_file(cookies):
     """Test Django urls.py file has generated correctly."""
 
@@ -60,6 +62,62 @@ def test_baked_django_urls_file(cookies):
     # assert 'DEBUG = "False"' in settings_file
 
 
+def test_baked_django_with_custom_issue_template_files(cookies):
+    """Test Django project has custom ISSUE templates generated correctly.
+
+    Tests that the Custom Issue templates have had the "assignee"
+    generated correctly, and post_gen deleted the standard template.
+
+    """
+
+    default_django = cookies.bake()
+
+    bug_path = default_django.project_path / ".github/ISSUE_TEMPLATE/bug-report.md"
+    bug_file = bug_path.read_text().splitlines()
+
+    chore_path = default_django.project_path / ".github/ISSUE_TEMPLATE/chore.md"
+    chore_file = chore_path.read_text().splitlines()
+
+    documentation_path = (
+        default_django.project_path / ".github/ISSUE_TEMPLATE/documentation-request.md"
+    )
+    documentation_file = documentation_path.read_text().splitlines()
+
+    feature_path = (
+        default_django.project_path / ".github/ISSUE_TEMPLATE/feature-request.md"
+    )
+    feature_file = feature_path.read_text().splitlines()
+
+    assert 'assignees: "imAsparky"' in bug_file
+    assert 'assignees: "imAsparky"' in chore_file
+    assert 'assignees: "imAsparky"' in documentation_file
+    assert 'assignees: "imAsparky"' in feature_file
+
+    assert "ISSUE_TEMPLATE.md" not in os.listdir(
+        (default_django.project_path / ".github")
+    )
+
+
+def test_baked_django_without_custom_issue_template_files(cookies):
+    """Test Django project has no custom ISSUE templates generated.
+
+    Tests that the standard template has the "project name"
+    generated correctly, and post-gen deleted the Custom Issue templates.
+
+    """
+
+    default_django = cookies.bake(extra_context={"use_GH_custom_issue_templates": "n"})
+
+    standard_issue_path = default_django.project_path / ".github/ISSUE_TEMPLATE.md"
+    standard_issue_file = standard_issue_path.read_text().splitlines()
+
+    assert '- "django-boilerplate" version:' in standard_issue_file
+
+    ISSUE_TEMPLATE_parent = default_django.project_path / ".github"
+    dir_list = os.listdir((ISSUE_TEMPLATE_parent))
+    assert "ISSUE_TEMPLATE" not in dir_list
+
+
 def test_baked_django_wsgi_file(cookies):
     """Test Django asgi.py file has generated correctly."""