2023-08-26 21:19:35 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# {{ managedText }}
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
# "OD-123 OD-456".
|
|
|
|
|
|
|
|
PROJECT_DIR=$(git rev-parse --show-toplevel) # Get the root directory of the repo
|
|
|
|
ISSUE_FILE="$PROJECT_DIR/.issue-id"
|
|
|
|
|
|
|
|
if [ -f "${ISSUE_FILE}" ]; then
|
|
|
|
ISSUE_ID=$(cat "${ISSUE_FILE}" | sed 's/ /, /g')
|
|
|
|
|
|
|
|
if [ -n "${ISSUE_ID}" ]; then
|
2023-08-26 21:27:00 +00:00
|
|
|
sed -i.bak "s/# Refs:/Refs: $ISSUE_ID/" "$1"
|
2023-08-26 21:19:35 +00:00
|
|
|
fi
|
|
|
|
fi
|