Fabio Utzig | efe67ae | 2017-12-05 16:03:02 -0200 | [diff] [blame] | 1 | #!/bin/bash |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 2 | |
| 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 Ermel | 76d2b89 | 2023-02-15 14:57:20 +0000 | [diff] [blame] | 15 | DEPENDABOT_COMMITER='GitHub <noreply@github.com>' |
| 16 | DEPENDABOT_AUTHOR='dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>' |
| 17 | |
Fabio Utzig | 9c5d14a | 2023-03-01 20:10:21 -0300 | [diff] [blame] | 18 | if [[ -n "$1" ]]; then |
| 19 | commits=$(git show -s --format=%h ${1}~..HEAD) |
Almir Okato | 3eb0681 | 2023-01-27 16:15:30 -0300 | [diff] [blame] | 20 | else |
Fabio Utzig | 9c5d14a | 2023-03-01 20:10:21 -0300 | [diff] [blame] | 21 | 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]}) |
| 27 | fi |
| 28 | |
| 29 | if [[ -z "${commits}" ]]; then |
| 30 | echo "No commits found in this PR!" |
Fabio Utzig | 6da40d0 | 2017-09-12 11:32:32 -0300 | [diff] [blame] | 31 | exit 1 |
| 32 | fi |
| 33 | |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 34 | for sha in $commits; do |
Dominik Ermel | 76d2b89 | 2023-02-15 14:57:20 +0000 | [diff] [blame] | 35 | 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 Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame] | 45 | |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 46 | lines="$(git show -s --format=%B ${sha})" |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame] | 47 | |
| 48 | found_author=false |
Fabio Utzig | ce50334 | 2021-01-14 09:52:11 -0300 | [diff] [blame] | 49 | # 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 Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 59 | IFS=$'\n' |
| 60 | for line in ${lines}; do |
| 61 | stripped=$(echo $line | sed -e 's/^\s*//' | sed -e 's/\s*$//') |
Fabio Utzig | f859255 | 2021-09-29 19:06:08 -0300 | [diff] [blame] | 62 | if [[ "${stripped}" == "${author}" ]]; then |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame] | 63 | found_author=true |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 64 | fi |
Fabio Utzig | f859255 | 2021-09-29 19:06:08 -0300 | [diff] [blame] | 65 | if [[ "${stripped}" == "${committer}" ]]; then |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame] | 66 | found_committer=true |
| 67 | fi |
| 68 | |
| 69 | [[ ${found_author} == true && ${found_committer} == true ]] && break |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 70 | done |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 71 | |
Fabio Utzig | d8f84bc | 2018-10-11 05:52:37 -0700 | [diff] [blame] | 72 | if [[ ${found_author} == false ]]; then |
Fabio Utzig | 73d8b03 | 2018-10-11 06:14:26 -0700 | [diff] [blame] | 73 | echo -e "Missing \"${author}\" in commit ${sha}" |
Fabio Utzig | d8f84bc | 2018-10-11 05:52:37 -0700 | [diff] [blame] | 74 | fi |
| 75 | if [[ ${found_committer} == false ]]; then |
Fabio Utzig | 38609e0 | 2018-10-13 15:16:25 -0700 | [diff] [blame] | 76 | echo -e "Missing \"${committer}\" in commit ${sha}" |
Fabio Utzig | d8f84bc | 2018-10-11 05:52:37 -0700 | [diff] [blame] | 77 | fi |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame] | 78 | if [[ ${found_author} == false || ${found_committer} == false ]]; then |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 79 | exit 1 |
| 80 | fi |
| 81 | done |