blob: d213fa701dc699d2fd6af93ce8f51761120785dc [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 Utzig5b989102017-09-04 16:27:51 -030017
Fabio Utzig6aca73d2020-09-28 19:17:22 -030018log=$(git log --oneline | head -n10)
Fabio Utzig6da40d02017-09-12 11:32:32 -030019if [[ "${#parents[@]}" -ne 2 ]]; then
Fabio Utzig6aca73d2020-09-28 19:17:22 -030020 echo "log: ${log}"
Fabio Utzig6da40d02017-09-12 11:32:32 -030021 echo "This PR's merge commit is missing a parent!"
22 exit 1
23fi
24
25from="${parents[0]}"
26into="${parents[1]}"
27commits=$(git show -s --format=%h ${from}..${into})
Fabio Utzig5b989102017-09-04 16:27:51 -030028
Fabio Utzig31180172017-09-06 21:38:14 -030029has_commits=false
Fabio Utzig5b989102017-09-04 16:27:51 -030030for sha in $commits; do
Fabio Utzig0b561382017-09-07 17:04:26 -030031 author="Signed-off-by: $(git show -s --format="%an <%ae>" ${sha})"
32 committer="Signed-off-by: $(git show -s --format="%cn <%ce>" ${sha})"
33
Fabio Utzig31180172017-09-06 21:38:14 -030034 lines="$(git show -s --format=%B ${sha})"
Fabio Utzig0b561382017-09-07 17:04:26 -030035
36 found_author=false
37 found_committer=false
Fabio Utzig31180172017-09-06 21:38:14 -030038 IFS=$'\n'
39 for line in ${lines}; do
40 stripped=$(echo $line | sed -e 's/^\s*//' | sed -e 's/\s*$//')
Fabio Utzig0b561382017-09-07 17:04:26 -030041 if [[ ${stripped} == ${author} ]]; then
42 found_author=true
Fabio Utzig31180172017-09-06 21:38:14 -030043 fi
Fabio Utzig0b561382017-09-07 17:04:26 -030044 if [[ ${stripped} == ${committer} ]]; then
45 found_committer=true
46 fi
47
48 [[ ${found_author} == true && ${found_committer} == true ]] && break
Fabio Utzig31180172017-09-06 21:38:14 -030049 done
Fabio Utzig5b989102017-09-04 16:27:51 -030050
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070051 if [[ ${found_author} == false ]]; then
Fabio Utzig73d8b032018-10-11 06:14:26 -070052 echo -e "Missing \"${author}\" in commit ${sha}"
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070053 fi
54 if [[ ${found_committer} == false ]]; then
Fabio Utzig38609e02018-10-13 15:16:25 -070055 echo -e "Missing \"${committer}\" in commit ${sha}"
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070056 fi
Fabio Utzig0b561382017-09-07 17:04:26 -030057 if [[ ${found_author} == false || ${found_committer} == false ]]; then
Fabio Utzig5b989102017-09-04 16:27:51 -030058 exit 1
59 fi
Fabio Utzig31180172017-09-06 21:38:14 -030060
61 has_commits=true
Fabio Utzig5b989102017-09-04 16:27:51 -030062done
Fabio Utzig31180172017-09-06 21:38:14 -030063
64if [[ ${has_commits} = false ]]; then
65 echo "No commits found in this PR!"
66 exit 1
67fi