• English
  • Branches and commits

    This standard defines how branches are named and how commit messages are written in Crehana's repositories.

    Branch name

    Every branch follows this structure:

    TICKET-CODE-descripcion

    Examples:

    HRIS-1234-validacion-email
    CELC-890-fix-query-cursos
    SWAT-999

    Commit message

    Every commit includes the Jira ticket code and a brief description. The format is mandatory:

    [ID-TICKET]-<tipo>(<alcance(opcional)>): <descripción corta>
    
    Descripción del cambio (opcional)

    Examples:

    HRIS-1234-feat agrega validación de email
    CELC-567-fix query de cursos
    SWAT-6789-hotfix fix error de resultados de areas
    CORE-1234-feat(crehana-ui): add new enum in user form options

    Merging to main

    When merging to main or master, squash the commits so the history stays as readable as possible.

    Automate the ticket ID with a hook

    The prepare-commit-msg hook extracts the ticket ID from the branch name and prepends it to the commit message, so you don't type it on every commit. Set it up in each repository you work on.

    1. Create the hook file, with no extension:

      cd .git/hooks
      nano prepare-commit-msg
    2. Paste this script. It uses the macOS sed syntax (sed -i ''), so it applies to Mac only:

      #!/bin/bash
      
      # Extract the current branch name
      # Extrae el nombre de la rama actual
      BRANCH_NAME=$(git symbolic-ref --short HEAD 2>/dev/null)
      
      # Exit if we are not on a branch (e.g., detached HEAD)
      # Sale si no estamos en una rama (ej. HEAD desprendido)
      if [ -z "$BRANCH_NAME" ]; then
        exit 0
      fi
      
      # Regex to extract Ticket ID (e.g., CELC-4000)
      # Regex para extraer el ID del ticket (ej. CELC-4000)
      TICKET_ID=$(echo "$BRANCH_NAME" | grep -oE "[A-Z]+-[0-9]+")
      
      # If TICKET_ID exists and is not already in the commit message
      # Si existe el TICKET_ID y no está ya en el mensaje del commit
      if [ ! -z "$TICKET_ID" ] && ! grep -q "$TICKET_ID" "$1"; then
          # In macOS, sed -i requires an empty string for the extension argument
          # En macOS, sed -i requiere un string vacío para el argumento de extensión
          sed -i '' "1s/^/[$TICKET_ID]-/" "$1"
      fi
    3. Make it executable:

      chmod +x .git/hooks/prepare-commit-msg

    Verification

    On a branch named HRIS-1234-validacion-email, make a commit with the message feat agrega validación de email. You should see the ID prepended:

    [HRIS-1234]-feat agrega validación de email