blob: f71e68ffa524359afef679bcfc482fd624ce19cf [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 Utzig6da40d02017-09-12 11:32:32 -030018if [[ "${#parents[@]}" -ne 2 ]]; then
19 echo "This PR's merge commit is missing a parent!"
20 exit 1
21fi
22
23from="${parents[0]}"
24into="${parents[1]}"
25commits=$(git show -s --format=%h ${from}..${into})
Fabio Utzig5b989102017-09-04 16:27:51 -030026
Fabio Utzig31180172017-09-06 21:38:14 -030027has_commits=false
Fabio Utzig5b989102017-09-04 16:27:51 -030028for sha in $commits; do
Fabio Utzig0b561382017-09-07 17:04:26 -030029 author="Signed-off-by: $(git show -s --format="%an <%ae>" ${sha})"
30 committer="Signed-off-by: $(git show -s --format="%cn <%ce>" ${sha})"
31
Fabio Utzig31180172017-09-06 21:38:14 -030032 lines="$(git show -s --format=%B ${sha})"
Fabio Utzig0b561382017-09-07 17:04:26 -030033
34 found_author=false
Fabio Utzigce503342021-01-14 09:52:11 -030035 # Don't enforce committer email on forks; this primarily avoids issues
36 # running workflows on the zephyr fork, because rebases done in the GH UX
37 # use the primary email of the committer, which might not match the one
38 # used in git CLI.
39 if [[ $GITHUB_REPOSITORY == mcu-tools/* ]]; then
40 found_committer=false
41 else
42 found_committer=true
43 fi
44
Fabio Utzig31180172017-09-06 21:38:14 -030045 IFS=$'\n'
46 for line in ${lines}; do
47 stripped=$(echo $line | sed -e 's/^\s*//' | sed -e 's/\s*$//')
Fabio Utzig0b561382017-09-07 17:04:26 -030048 if [[ ${stripped} == ${author} ]]; then
49 found_author=true
Fabio Utzig31180172017-09-06 21:38:14 -030050 fi
Fabio Utzig0b561382017-09-07 17:04:26 -030051 if [[ ${stripped} == ${committer} ]]; then
52 found_committer=true
53 fi
54
55 [[ ${found_author} == true && ${found_committer} == true ]] && break
Fabio Utzig31180172017-09-06 21:38:14 -030056 done
Fabio Utzig5b989102017-09-04 16:27:51 -030057
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070058 if [[ ${found_author} == false ]]; then
Fabio Utzig73d8b032018-10-11 06:14:26 -070059 echo -e "Missing \"${author}\" in commit ${sha}"
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070060 fi
61 if [[ ${found_committer} == false ]]; then
Fabio Utzig38609e02018-10-13 15:16:25 -070062 echo -e "Missing \"${committer}\" in commit ${sha}"
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070063 fi
Fabio Utzig0b561382017-09-07 17:04:26 -030064 if [[ ${found_author} == false || ${found_committer} == false ]]; then
Fabio Utzig5b989102017-09-04 16:27:51 -030065 exit 1
66 fi
Fabio Utzig31180172017-09-06 21:38:14 -030067
68 has_commits=true
Fabio Utzig5b989102017-09-04 16:27:51 -030069done
Fabio Utzig31180172017-09-06 21:38:14 -030070
71if [[ ${has_commits} = false ]]; then
72 echo "No commits found in this PR!"
73 exit 1
74fi