Skip to main content
Glama
deleonio
by deleonio
prepare-commit-msg1.42 kB
#!/bin/sh # # Validate branch name and append the ticket ID (from branch name) to commit messages. # Modified version of: https://medium.com/@adrian.garcia.estaun/add-the-ticket-id-to-your-commit-messages-automatically-2debfa0fbe9d # MISSING_ISSUE_NUMBER_MESSAGE="Skip auto issue referencing. Branch name does not start with a ticket ID. Format: ticketID-branch-description. E.g.: '1234-update-tests'" # Gets the commit message received as parameter and the current branch name. COMMIT_MSG_FILE="$1" COMMIT_SOURCE="$2" # Skip merge commits if [ "$COMMIT_SOURCE" = merge ]; then exit 0 fi message=$(cat "$COMMIT_MSG_FILE") branchName=$(git symbolic-ref --short HEAD) # Get the last part of the branch name. feature/foo/42-bugfix -> 42-bugfix normalizedBranchName=$(echo "$branchName" | awk -F'/' '{print $NF}') # Branch name starts with a ticket ID if echo "$normalizedBranchName" | grep -qE '^[0-9]+[-_]'; then # Get ticketID from branch name. Works with `-` or `_` as separator. 123-foobar -> 123 ticketID=$(echo "$normalizedBranchName" | sed -nE 's,([0-9]+)[_-].+,\1,p') if [ -z "$ticketID" ]; then echo "$MISSING_ISSUE_NUMBER_MESSAGE" exit 0 fi # Message already contains the ticket ID if echo "$message" | grep -qE '#[0-9]+'; then exit 0 fi output="$message"$'\n'$'\n'"Refs: #$ticketID" echo "$output" > "$1" else echo "$MISSING_ISSUE_NUMBER_MESSAGE" exit 0 fi

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/deleonio/public-ui-kolibri'

If you have feedback or need assistance with the MCP directory API, please join our Discord server