Skip to content

Conversation

@emsearcy
Copy link
Contributor

Summary

This PR introduces a new slug_from_project_name() function to provide better sanitization of project slugs in the mock data generation.

Changes Made

New Function: slug_from_project_name()

  • Location: src/lfx_v2_mockdata/__init__.py
  • Purpose: Generate sanitized slugs from project names
  • Logic:
    • Convert project name to lowercase
    • Replace non-alphanumeric characters with hyphens
    • Replace consecutive hyphens with a single hyphen
    • Strip leading and trailing hyphens

Jinja Environment Integration

  • Exported the function to the Jinja environment globals
  • Available in all playbook templates as {{ slug_from_project_name(project_name) }}

Updated Playbooks

  • File: playbooks/projects/base_projects/3_umbrellas.yaml
  • Changes: Replaced manual slug generation using | lower | replace(" ", "-") with calls to slug_from_project_name()
  • Affected areas:
    • BUF (Big Umbrella Foundation) child project slugs
    • IUBP (Industry Umbrella of Branded Projects) child project slugs
    • Repository and website URLs that depend on slugs

Benefits

  1. Consistent sanitization: All project slugs now follow the same sanitization rules
  2. Better handling of edge cases: Properly handles special characters, consecutive spaces, and leading/trailing whitespace
  3. Centralized logic: Single function for all slug generation, easier to maintain and modify
  4. Future-proof: New playbooks can easily use the same sanitization logic

Testing

The function handles various edge cases including:

  • Special characters and punctuation
  • Multiple consecutive spaces or hyphens
  • Leading and trailing whitespace
  • Empty strings
  • Mixed case input

Examples

slug_from_project_name("The Linux Foundation")  # "the-linux-foundation"
slug_from_project_name("Big Umbrella Foundation (BUF)")  # "big-umbrella-foundation-buf"
slug_from_project_name("Multiple   Spaces")  # "multiple-spaces"
slug_from_project_name("Special@#$%Characters")  # "special-characters"

…itization

- Create slug_from_project_name function that properly sanitizes project names
- Function converts to lowercase, replaces non-alphanumeric with hyphens,
  collapses consecutive hyphens, and strips leading/trailing hyphens
- Export function to Jinja environment for use in templates
- Replace manual slug generation in umbrella project playbooks
- Ensures consistent and properly sanitized project slugs across all playbooks

🤖 Generated with [GitHub Copilot](https://github.com/features/copilot) (via Zed)

Signed-off-by: Eric Searcy <[email protected]>
Copilot AI review requested due to automatic review settings November 28, 2025 19:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a centralized slug_from_project_name() function to standardize project slug generation from project names, improving consistency and handling of edge cases across the codebase.

Key Changes:

  • New utility function with regex-based sanitization that converts project names to URL-safe slugs
  • Integration of the function into the Jinja2 template environment for use in playbooks
  • Refactored playbook templates to use the new function instead of inline filter chains

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/lfx_v2_mockdata/__init__.py Added slug_from_project_name() function with regex-based sanitization logic and exported it to Jinja environment globals
playbooks/projects/base_projects/3_umbrellas.yaml Replaced manual slug generation (lower | replace(" ", "-")) with calls to the new slug_from_project_name() function for BUF and IUBP child projects

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +121 to +123
# Replace consecutive hyphens with a single hyphen.
slug = re.sub(r"-+", "-", slug)

Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex replacement on line 122 is redundant. Line 119 already uses the + quantifier in [^a-z0-9]+, which matches one or more non-alphanumeric characters and replaces them with a single hyphen. This inherently prevents consecutive hyphens from being created, making the second re.sub(r"-+", "-", slug) call unnecessary.

Consider removing line 122 for better performance and code clarity.

Suggested change
# Replace consecutive hyphens with a single hyphen.
slug = re.sub(r"-+", "-", slug)

Copilot uses AI. Check for mistakes.
@emsearcy emsearcy merged commit 596653b into linuxfoundation:main Dec 2, 2025
9 checks passed
@emsearcy emsearcy deleted the sanitize-slugs branch December 16, 2025 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants