docker-example-drupal/.githooks/prepare-commit-msg

28 lines
821 B
Plaintext
Raw Permalink Normal View History

2023-08-26 22:36:07 +00:00
#!/usr/bin/env bash
# Do not edit this file. It is automatically generated by https://www.oliverdavies.uk/build-configs.
# Load the issue ID from an `.issue-id` file within the project and replace the
# `ISSUE_ID` placeholder within a Git commit message.
#
# For example, running `echo "OD-123" > .issue-id` will add `Refs: OD-123` to
# the commit message.
#
# This also works with multiple issue IDs in the same string, e.g.
2023-08-26 23:04:22 +00:00
# "OD-123 OD-456", or IDs on multiple lines.
2023-08-26 22:36:07 +00:00
2023-11-23 07:06:07 +00:00
set -o errexit
set -o nounset
set -o pipefail
2023-08-26 22:45:44 +00:00
2023-08-26 23:18:59 +00:00
PROJECT_DIR=$(git rev-parse --show-toplevel)
2023-08-26 22:36:07 +00:00
ISSUE_FILE="$PROJECT_DIR/.issue-id"
if [ -f "${ISSUE_FILE}" ]; then
2023-08-26 23:04:22 +00:00
ISSUE_IDS=$(cat "${ISSUE_FILE}" | tr '\n' ',' | tr ' ' ',' | sed 's/,$//' | sed 's/,/, /g')
2023-08-26 22:36:07 +00:00
2023-08-26 23:04:22 +00:00
if [ -n "${ISSUE_IDS}" ]; then
sed -i.bak "s/# Refs:/Refs: $ISSUE_IDS/" "$1"
2023-08-26 22:36:07 +00:00
fi
fi