Copilot commented on code in PR #743:
URL: https://github.com/apache/burr/pull/743#discussion_r3106723335
##########
scripts/templates/result_email.j2:
##########
@@ -0,0 +1,32 @@
+{#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+#}
+[RESULT][VOTE] Release Apache {{ project_display_name }} (Incubating) {{
version }} RC{{ rc_num }}
+
+Hi all,
+
+Thanks everyone who participated in the vote for Release Apache {{
project_display_name }} {{ version }} RC{{ rc_num }}.
+
+Apache {{ project_display_name }} is an effort undergoing incubation at The
Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation
is required of all newly accepted projects until a further review indicates
that the infrastructure, communications, and decision making process have
stabilized in a manner consistent with other successful ASF projects. While
incubation status is not necessarily a reflection of the completeness or
stability of the code, it does indicate that the project has yet to be fully
endorsed by the ASF.
+
+The vote result is:
+
++1: {{ binding_yes }} (binding), {{ non_binding_yes }} (non-binding)
++0: {{ abstain }}
+-1: {{ no_votes }}
+
+Vote thread:
+{{ vote_thread_url }}
+
+Therefore, the release candidate has passed.
Review Comment:
This template always states "Therefore, the release candidate has passed."
regardless of the vote tally values. That can generate an incorrect email when
the vote fails. Consider making the outcome text driven by a context variable
computed from the counts (or add a CLI flag to select passed/failed) so the
rendered result matches the provided numbers.
##########
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:
`_emit_email_output` prints clipboard status messages to stdout after
printing the email content. If users redirect stdout into a file or pipe it
into another tool, these extra lines will contaminate the generated email.
Consider sending status/log messages to stderr (or gating them behind a
`--verbose` flag) so stdout remains the email body only.
##########
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:
In the non-Jinja2 fallback, `re.sub(..., str(value), ...)` treats
backslashes in `value` as escape sequences/backreferences, which can corrupt
rendered output (or raise) for some inputs. Use a replacement function (lambda)
or otherwise ensure the replacement is treated literally.
##########
scripts/templates/result_email.j2:
##########
@@ -0,0 +1,32 @@
+{#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
Review Comment:
The embedded ASF license header in this template appears truncated (it omits
the standard "Unless required by applicable law..." disclaimer and subsequent
lines that are present in other repo files). To stay consistent with the
project's license-header practice, consider using the full Apache header block
here as well.
##########
scripts/templates/announce_email.j2:
##########
@@ -0,0 +1,33 @@
+{#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
Review Comment:
The embedded ASF license header in this template appears truncated (it omits
the standard "Unless required by applicable law..." disclaimer and subsequent
lines that are present in other repo files). To stay consistent with the
project's license-header practice, consider using the full Apache header block
here as well.
##########
scripts/templates/vote_email.j2:
##########
@@ -0,0 +1,61 @@
+{#
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
Review Comment:
The embedded ASF license header in this template appears truncated (it omits
the standard "Unless required by applicable law..." disclaimer and subsequent
lines that are present in other repo files). To stay consistent with the
project's license-header practice, consider using the full Apache header block
here as well.
--
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]