Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added post-commit hook to add robot tag to commit #671

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .githooks/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Retrieve the value of the environment variable
ENV_VAR_VALUE=$(printenv YARP_ROBOT_NAME)

echo "Post-commit hook running..."

# Check if the environment variable is set
if [ -z "$ENV_VAR_VALUE" ]; then
echo "Environment variable YARP_ROBOT_NAME is not set. Skipping post-commit hook."
exit 0
fi

# Get the current commit message
CURRENT_COMMIT_MSG=$(git log -1 --pretty=%B)

# Check if the commit message already starts with a [
if [[ "$CURRENT_COMMIT_MSG" =~ ^\[ ]]; then
echo "Commit message already starts with '[', not modifying the commit message."
exit 0
fi

# Prepend the environment variable value to the commit message
COMMIT_MSG_FILE=$(mktemp)
echo "[$ENV_VAR_VALUE] $CURRENT_COMMIT_MSG" > "$COMMIT_MSG_FILE"

# Amend the commit with the new message
git -c core.hooksPath=/dev/null commit --amend -F "$COMMIT_MSG_FILE"

# Clean up
rm "$COMMIT_MSG_FILE"