summaryrefslogtreecommitdiff
path: root/devel/check_if_signed
blob: b8b4fef112b616a630fe9dadd61190c524a08fbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env sh

if test -z "$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"; then
  CI_MERGE_REQUEST_TARGET_BRANCH_NAME="master"
fi

echo "target=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
echo "source=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"

if test -z "$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"; then
  CI_MERGE_REQUEST_SOURCE_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
  echo "branch=$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME"
fi

# create list of commits of the current branch
commits=$(git rev-list --no-merges $CI_MERGE_REQUEST_TARGET_BRANCH_NAME..$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME)

# check if author's email matches email in 'Signed-off-by'
for hash in $commits; do
  author=$(git log --format='%ae' ${hash}^\!)
  signed=$(git log --format='%b' ${hash}^\! | grep -i "Signed-off-by:")
  if test $? -ne 0; then
    echo "Missing Signed-off-by"
    exit 1
  fi
  if ! echo $signed | grep -q "Signed-off-by:.*<${author}>"; then
    echo "Author '${author}' doesn't match"
    exit 1
  fi
done