GitLab: Append signature to a issue comments automatically

169 Views Asked by At

I am working on a private installation of GitLab and I would like to know if there is a way to append automatically a string of text at the end of the comment when answering an issue (as, for example, a signature).

Thanks in advance for any help you are able to provide.

1

There are 1 best solutions below

0
On

There's nothing in Gitlab that will let you automatically modify commit messages, or in Git to append to a message (that I know of), but you can prepend text to a commit message using a Git Hook. This can be useful for adding a branch name or User Story ID to a commit message.

Git Hooks are defined in the .git/hooks directory in your project. The hooks directory has some example files that show you how the different hooks can work. The examples in the file prepare-commit-msg.sample show a variety of ways to interact with a commit message, one of which is a way to add a "Signed off by John Doe" line to a commit message, which is similar to what you've asked for:

#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source.  The hook's purpose is to edit the commit
# message file.  If the hook fails with a non-zero status,
# the commit is aborted.
#
# To enable this hook, rename this file to "prepare-commit-msg".

# This hook includes three examples. The first one removes the
# "# Please enter the commit message..." help message.
#
# The second includes the output of "git diff --name-status -r"
# into the message, just before the "git status" output.  It is
# commented because it doesn't cope with --amend or with squashed
# commits.
#
# The third example adds a Signed-off-by line to the message, that can
# still be edited.  This is rarely a good idea.

COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3

/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE"

# case "$COMMIT_SOURCE,$SHA1" in
#  ,|template,)
#    /usr/bin/perl -i.bak -pe '
#       print "\n" . `git diff --cached --name-status -r`
#    if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;;
#  *) ;;
# esac

# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p')
# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE"
# if test -z "$COMMIT_SOURCE"
# then
#   /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE"
# fi

If you uncomment that last bit, git will add the value of the GIT_COMMITTER_IDENT variable to the commit message with Signed-off-by Committer.

Note: it says that modifying the commit message is a bad idea in the example, but I'm unsure why. I edited your question to add the git tag, so hopefully someone else will know more about it than I do.