blob: 4738e370951d546a3f15483a42ab4c0f5ba4d8c0 [file] [log] [blame]
Fabio Utzigefe67ae2017-12-05 16:03:02 -02001#!/bin/bash
Fabio Utzig5b989102017-09-04 16:27:51 -03002
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
Fabio Utzig6da40d02017-09-12 11:32:32 -030015# this retrieves the merge commit created by GH
16parents=(`git log -n 1 --format=%p HEAD`)
Fabio Utzig5f9fbcc2017-12-05 13:47:08 -020017branch=(`git rev-parse --abbrev-ref HEAD`)
18
19# Should only run in PR branches
20[[ ${branch} == "master" ]] && exit 0
Fabio Utzig5b989102017-09-04 16:27:51 -030021
Fabio Utzig6da40d02017-09-12 11:32:32 -030022if [[ "${#parents[@]}" -ne 2 ]]; then
23 echo "This PR's merge commit is missing a parent!"
24 exit 1
25fi
26
27from="${parents[0]}"
28into="${parents[1]}"
29commits=$(git show -s --format=%h ${from}..${into})
Fabio Utzig5b989102017-09-04 16:27:51 -030030
Fabio Utzig31180172017-09-06 21:38:14 -030031has_commits=false
Fabio Utzig5b989102017-09-04 16:27:51 -030032for sha in $commits; do
Fabio Utzig0b561382017-09-07 17:04:26 -030033 author="Signed-off-by: $(git show -s --format="%an <%ae>" ${sha})"
34 committer="Signed-off-by: $(git show -s --format="%cn <%ce>" ${sha})"
35
Fabio Utzig31180172017-09-06 21:38:14 -030036 lines="$(git show -s --format=%B ${sha})"
Fabio Utzig0b561382017-09-07 17:04:26 -030037
38 found_author=false
39 found_committer=false
Fabio Utzig31180172017-09-06 21:38:14 -030040 IFS=$'\n'
41 for line in ${lines}; do
42 stripped=$(echo $line | sed -e 's/^\s*//' | sed -e 's/\s*$//')
Fabio Utzig0b561382017-09-07 17:04:26 -030043 if [[ ${stripped} == ${author} ]]; then
44 found_author=true
Fabio Utzig31180172017-09-06 21:38:14 -030045 fi
Fabio Utzig0b561382017-09-07 17:04:26 -030046 if [[ ${stripped} == ${committer} ]]; then
47 found_committer=true
48 fi
49
50 [[ ${found_author} == true && ${found_committer} == true ]] && break
Fabio Utzig31180172017-09-06 21:38:14 -030051 done
Fabio Utzig5b989102017-09-04 16:27:51 -030052
Fabio Utzig0b561382017-09-07 17:04:26 -030053 if [[ ${found_author} == false || ${found_committer} == false ]]; then
54 echo -e "One or more \"Signed-off-by\" lines missing in commit ${sha}"
Fabio Utzig5b989102017-09-04 16:27:51 -030055 exit 1
56 fi
Fabio Utzig31180172017-09-06 21:38:14 -030057
58 has_commits=true
Fabio Utzig5b989102017-09-04 16:27:51 -030059done
Fabio Utzig31180172017-09-06 21:38:14 -030060
61if [[ ${has_commits} = false ]]; then
62 echo "No commits found in this PR!"
63 exit 1
64fi