Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasrodes committed Nov 29, 2024
1 parent c0fd51b commit c214292
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions apps/pr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def bake_branch_name(repo, pr_title, no_llm, remote_branches):
category = pr_title.category

# Get input title (without emoji, scope, etc.)
title = _extract_relevant_title_for_branch_name(pr_title.title, not no_llm)
title = _extract_relevant_title_for_branch_name(pr_title.title, category, not no_llm)

# Bake complete PR branch name
# name = f"{user}-{category}-{title}"
Expand All @@ -383,13 +383,14 @@ def bake_branch_name(repo, pr_title, no_llm, remote_branches):
# if name in remote_branches:
# log.info("Generating a hash for this branch name to prevent name collisions.")
# name = f"{name}-{user}"
if name in remote_branches:
local_branches = [branch.name for branch in repo.branches]
if (name in remote_branches) or (name in local_branches):
log.info("Generating a hash for this branch name to prevent name collisions.")
name = f"{name}-{generate_short_hash()}"
return name


def _extract_relevant_title_for_branch_name(text_in: str, use_llm) -> str:
def _extract_relevant_title_for_branch_name(text_in: str, category: str, use_llm) -> str:
"""
Process the input string by:
1. Removing all symbols, keeping only letters and numbers.
Expand All @@ -411,8 +412,13 @@ def _extract_relevant_title_for_branch_name(text_in: str, use_llm) -> str:

# Split into tokens/words
tokens = cleaned_text.split()

# Clean if there is word included in category
tokens = [t for t in tokens if t.lower() != category]

# Keep only the first 3 tokens
tokens = tokens[:3]

# Combine tokens with '-'
name = "-".join(tokens).lower()

Expand Down

0 comments on commit c214292

Please sign in to comment.