blob: 5d41afe567ec4a6fc4e3f4c48dbeb17506db3a56 [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
Dominik Ermel76d2b892023-02-15 14:57:20 +000015DEPENDABOT_COMMITER='GitHub <noreply@github.com>'
16DEPENDABOT_AUTHOR='dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>'
17
Fabio Utzig9c5d14a2023-03-01 20:10:21 -030018if [[ -n "$1" ]]; then
19 commits=$(git show -s --format=%h ${1}~..HEAD)
Almir Okato3eb06812023-01-27 16:15:30 -030020else
Fabio Utzig9c5d14a2023-03-01 20:10:21 -030021 parents=(`git log -n 1 --format=%p HEAD`)
22 if [[ "${#parents[@]}" -ne 2 ]]; then
23 echo "HEAD is not a merge commit, please supply the oldest SHA"
24 exit 1
25 fi
26 commits=$(git show -s --format=%h ${parents[0]}..${parents[1]})
27fi
28
29if [[ -z "${commits}" ]]; then
30 echo "No commits found in this PR!"
Fabio Utzig6da40d02017-09-12 11:32:32 -030031 exit 1
32fi
33
Fabio Utzig5b989102017-09-04 16:27:51 -030034for sha in $commits; do
Dominik Ermel76d2b892023-02-15 14:57:20 +000035 author="$(git show -s --format="%an <%ae>" ${sha})"
36 committer="$(git show -s --format="%cn <%ce>" ${sha})"
37
38 if [[ "${committer}" == "${DEPENDABOT_COMMITER}" ]] &&
39 [[ "${author}" == "${DEPENDABOT_AUTHOR}" ]]; then
40 continue
41 fi
42
43 author="Signed-off-by: ${author}"
44 committer="Signed-off-by: ${committer}"
Fabio Utzig0b561382017-09-07 17:04:26 -030045
Fabio Utzig31180172017-09-06 21:38:14 -030046 lines="$(git show -s --format=%B ${sha})"
Fabio Utzig0b561382017-09-07 17:04:26 -030047
48 found_author=false
Fabio Utzigce503342021-01-14 09:52:11 -030049 # Don't enforce committer email on forks; this primarily avoids issues
50 # running workflows on the zephyr fork, because rebases done in the GH UX
51 # use the primary email of the committer, which might not match the one
52 # used in git CLI.
53 if [[ $GITHUB_REPOSITORY == mcu-tools/* ]]; then
54 found_committer=false
55 else
56 found_committer=true
57 fi
58
Fabio Utzig31180172017-09-06 21:38:14 -030059 IFS=$'\n'
60 for line in ${lines}; do
61 stripped=$(echo $line | sed -e 's/^\s*//' | sed -e 's/\s*$//')
Fabio Utzigf8592552021-09-29 19:06:08 -030062 if [[ "${stripped}" == "${author}" ]]; then
Fabio Utzig0b561382017-09-07 17:04:26 -030063 found_author=true
Fabio Utzig31180172017-09-06 21:38:14 -030064 fi
Fabio Utzigf8592552021-09-29 19:06:08 -030065 if [[ "${stripped}" == "${committer}" ]]; then
Fabio Utzig0b561382017-09-07 17:04:26 -030066 found_committer=true
67 fi
68
69 [[ ${found_author} == true && ${found_committer} == true ]] && break
Fabio Utzig31180172017-09-06 21:38:14 -030070 done
Fabio Utzig5b989102017-09-04 16:27:51 -030071
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070072 if [[ ${found_author} == false ]]; then
Fabio Utzig73d8b032018-10-11 06:14:26 -070073 echo -e "Missing \"${author}\" in commit ${sha}"
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070074 fi
75 if [[ ${found_committer} == false ]]; then
Fabio Utzig38609e02018-10-13 15:16:25 -070076 echo -e "Missing \"${committer}\" in commit ${sha}"
Fabio Utzigd8f84bc2018-10-11 05:52:37 -070077 fi
Fabio Utzig0b561382017-09-07 17:04:26 -030078 if [[ ${found_author} == false || ${found_committer} == false ]]; then
Fabio Utzig5b989102017-09-04 16:27:51 -030079 exit 1
80 fi
81done