MCPcopy Create free account
hub / github.com/apache/solr / generate_slug

Method generate_slug

dev-tools/scripts/changes2logchange.py:326–361  ·  view source on GitHub ↗

Generate a slug from issue ID and title. Format: ISSUE-12345 short slug or VERSION entry 001 short slug Note: Previous slug formats used dashes ("ISSUE-12345-short-slug"), but this script now uses spaces between components (e.g., "ISSUE-12345 short slug"). Spaces ar

(issue_id: str, title: str)

Source from the content-addressed store, hash-verified

324
325 @staticmethod
326 def generate_slug(issue_id: str, title: str) -> str:
327 """
328 Generate a slug from issue ID and title.
329
330 Format: ISSUE-12345 short slug or VERSION entry 001 short slug
331 Note: Previous slug formats used dashes ("ISSUE-12345-short-slug"), but this script now uses spaces between components (e.g., "ISSUE-12345 short slug").
332 Spaces are preferred over dashes for improved readability, better preservation of word boundaries, and to avoid unnecessary character substitutions. This change also ensures that filenames remain filesystem-safe while being more human-friendly.
333 Uses the actual issue ID without forcing SOLR- prefix
334 Ensures filesystem-safe filenames and respects word boundaries
335 Whitespace is preserved as spaces (not converted to dashes)
336 """
337 # Sanitize issue_id to remove unsafe characters (preserve case and # for readability)
338 base_issue = SlugGenerator._sanitize_issue_id(issue_id)
339
340 # Create slug from title: lowercase, preserve spaces, replace only unsafe chars with dash
341 title_slug = SlugGenerator._sanitize_filename_part(title)
342
343 # Limit to reasonable length while respecting word boundaries
344 # Target max length: 50 chars for slug (leaving room for base_issue and space)
345 if len(title_slug) > 50:
346 # Find last word/space boundary within 50 chars
347 truncated = title_slug[:50]
348 # Find the last space within the limit
349 last_space = truncated.rfind(' ')
350 if last_space > 20: # Keep at least 20 chars to avoid too-short slugs
351 title_slug = truncated[:last_space]
352 else:
353 # If no good space boundary, try to find a dash (from unsafe chars)
354 last_dash = truncated.rfind('-')
355 if last_dash > 20:
356 title_slug = truncated[:last_dash]
357 else:
358 # If no good boundary, use hard limit and clean up
359 title_slug = truncated.rstrip(' -')
360
361 return f"{base_issue} {title_slug}"
362
363 @staticmethod
364 def _sanitize_issue_id(issue_id: str) -> str:

Callers 1

_process_versionMethod · 0.80

Calls 2

_sanitize_issue_idMethod · 0.80

Tested by

no test coverage detected