hussain-s commented on code in PR #743:
URL: https://github.com/apache/burr/pull/743#discussion_r3107315742


##########
scripts/apache_release.py:
##########
@@ -119,6 +122,249 @@ def _run_command(
         _fail(f"{error_message}{error_detail}")
 
 
+def _render_template(template_name: str, context: dict[str, Any]) -> str:
+    """Render a template with Jinja2 if available, or a simple placeholder 
fallback."""
+    template_path = TEMPLATES_DIR / template_name
+
+    if not template_path.exists():
+        _fail(f"Template not found: {template_path}")
+
+    try:
+        from jinja2 import Environment, FileSystemLoader, StrictUndefined
+
+        environment = Environment(
+            loader=FileSystemLoader(str(TEMPLATES_DIR)),
+            autoescape=False,
+            keep_trailing_newline=True,
+            trim_blocks=True,
+            lstrip_blocks=True,
+            undefined=StrictUndefined,
+        )
+        return environment.get_template(template_name).render(**context)
+    except ImportError:
+        content = template_path.read_text(encoding="utf-8")
+        for key, value in context.items():
+            content = re.sub(r"{{\s*" + re.escape(key) + r"\s*}}", str(value), 
content)

Review Comment:
   I will address the comment



##########
scripts/apache_release.py:
##########
@@ -119,6 +122,249 @@ def _run_command(
         _fail(f"{error_message}{error_detail}")
 
 
+def _render_template(template_name: str, context: dict[str, Any]) -> str:
+    """Render a template with Jinja2 if available, or a simple placeholder 
fallback."""
+    template_path = TEMPLATES_DIR / template_name
+
+    if not template_path.exists():
+        _fail(f"Template not found: {template_path}")
+
+    try:
+        from jinja2 import Environment, FileSystemLoader, StrictUndefined
+
+        environment = Environment(
+            loader=FileSystemLoader(str(TEMPLATES_DIR)),
+            autoescape=False,
+            keep_trailing_newline=True,
+            trim_blocks=True,
+            lstrip_blocks=True,
+            undefined=StrictUndefined,
+        )
+        return environment.get_template(template_name).render(**context)
+    except ImportError:
+        content = template_path.read_text(encoding="utf-8")
+        for key, value in context.items():
+            content = re.sub(r"{{\s*" + re.escape(key) + r"\s*}}", str(value), 
content)
+        return re.sub(r"{#.*?#}\n?", "", content, flags=re.DOTALL)
+
+
+def _copy_to_clipboard(content: str) -> bool:
+    """Copy content to the system clipboard when a known clipboard tool 
exists."""
+    clipboard_commands = [
+        ["pbcopy"],
+        ["xclip", "-selection", "clipboard"],
+        ["xsel", "--clipboard", "--input"],
+        ["clip"],
+    ]
+
+    for command in clipboard_commands:
+        if shutil.which(command[0]) is None:
+            continue
+        try:
+            subprocess.run(command, input=content, text=True, check=True)
+            return True
+        except subprocess.CalledProcessError:
+            continue
+    return False
+
+
+def _emit_email_output(content: str, copy_to_clipboard: bool = False) -> None:
+    """Emit rendered email to stdout and optionally copy it to the 
clipboard."""
+    print(content)
+    if copy_to_clipboard:
+        if _copy_to_clipboard(content):
+            print("\n✓ Copied email content to clipboard")
+        else:
+            print("\n⚠️  Clipboard tool not found; email content was printed 
to stdout instead")

Review Comment:
   I will address the comment



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to