Merge pull request 'agit: Add documentation to EDIT_MSG and strip comments' (#3986) from kenji/agit: Add documentation to EDIT_MSG and strip comments into main
Reviewed-on: https://git.clan.lol/clan/clan-core/pulls/3986
This commit is contained in:
@@ -51,6 +51,13 @@ def open_editor_for_pr() -> tuple[str, str]:
|
|||||||
with tempfile.NamedTemporaryFile(
|
with tempfile.NamedTemporaryFile(
|
||||||
mode="w+", suffix=".txt", delete=False
|
mode="w+", suffix=".txt", delete=False
|
||||||
) as temp_file:
|
) as temp_file:
|
||||||
|
temp_file.write("\n")
|
||||||
|
temp_file.write("# Please enter the PR title on the first line.\n")
|
||||||
|
temp_file.write("# Lines starting with '#' will be ignored.\n")
|
||||||
|
temp_file.write("# The first line will be used as the PR title.\n")
|
||||||
|
temp_file.write("# Everything else will be used as the PR description.\n")
|
||||||
|
temp_file.write("#\n")
|
||||||
|
temp_file.flush()
|
||||||
temp_file_path = temp_file.name
|
temp_file_path = temp_file.name
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -63,17 +70,28 @@ def open_editor_for_pr() -> tuple[str, str]:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
with Path(temp_file_path).open() as f:
|
with Path(temp_file_path).open() as f:
|
||||||
content = f.read().strip()
|
content = f.read()
|
||||||
|
|
||||||
if not content:
|
lines = []
|
||||||
|
for line in content.split("\n"):
|
||||||
|
if not line.lstrip().startswith("#"):
|
||||||
|
lines.append(line)
|
||||||
|
|
||||||
|
cleaned_content = "\n".join(lines).strip()
|
||||||
|
|
||||||
|
if not cleaned_content:
|
||||||
print("No content provided, aborting.")
|
print("No content provided, aborting.")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
lines = content.split("\n")
|
content_lines = cleaned_content.split("\n")
|
||||||
title = lines[0].strip()
|
title = content_lines[0].strip()
|
||||||
|
|
||||||
|
if not title:
|
||||||
|
print("No title provided, aborting.")
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
description_lines = []
|
description_lines = []
|
||||||
for line in lines[1:]:
|
for line in content_lines[1:]:
|
||||||
if description_lines or line.strip():
|
if description_lines or line.strip():
|
||||||
description_lines.append(line)
|
description_lines.append(line)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user