Merge pull request '[Issue 2] Pull request branch name should contain text from the issue title' (#3) from issue-2 into main
Some checks failed
Run Python tests (through Pytest) / Test (push) Successful in 24s
Verify Python project can be installed, loaded and have version checked / Test (push) Has been cancelled

Reviewed-on: #3
This commit is contained in:
Jmaa 2025-04-13 13:40:56 +00:00
commit 3a147962ec

View File

@ -15,6 +15,16 @@ import subprocess
import os
import secret_loader
import re
def generate_branch_name(issue_title: str) -> str:
"""
Create a branch name by sanitizing the issue title.
Non-alphanumeric characters (except spaces) are removed,
the text is lowercased, and spaces are replaced with dashes.
"""
sanitized = re.sub(r"[^0-9a-zA-Z ]+", "", issue_title)
return "issue-" + "-".join(sanitized.lower().split())
logger = logging.getLogger(__name__)
@ -130,10 +140,10 @@ def main():
issue_number = issue.get("number")
issue_description = issue.get("body", "")
title = issue.get("title", f"Issue {issue_number}")
branch_name = f"issue-{issue_number}"
branch_name = generate_branch_name(title)
try:
with tempfile.TemporaryDirectory() as tmpdirname:
process_issue(args, Path(tmpdirname), branch_name, issue_description, issue_number)
process_issue(args, Path(tmpdirname), branch_name, title, issue_description, issue_number)
logger.info(f"Created branch {branch_name} for issue {issue_number}.")
except Exception:
logger.exception('Error processing issue')