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 | |
Fabio Utzig | 6da40d0 | 2017-09-12 11:32:32 -0300 | [diff] [blame] | 15 | # this retrieves the merge commit created by GH |
| 16 | parents=(`git log -n 1 --format=%p HEAD`) |
Fabio Utzig | 5f9fbcc | 2017-12-05 13:47:08 -0200 | [diff] [blame] | 17 | branch=(`git rev-parse --abbrev-ref HEAD`) |
| 18 | |
| 19 | # Should only run in PR branches |
| 20 | [[ ${branch} == "master" ]] && exit 0 |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 21 | |
Fabio Utzig | 6da40d0 | 2017-09-12 11:32:32 -0300 | [diff] [blame] | 22 | if [[ "${#parents[@]}" -ne 2 ]]; then |
| 23 | echo "This PR's merge commit is missing a parent!" |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | from="${parents[0]}" |
| 28 | into="${parents[1]}" |
| 29 | commits=$(git show -s --format=%h ${from}..${into}) |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 30 | |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 31 | has_commits=false |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 32 | for sha in $commits; do |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame] | 33 | 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 Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 36 | lines="$(git show -s --format=%B ${sha})" |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame] | 37 | |
| 38 | found_author=false |
| 39 | found_committer=false |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 40 | IFS=$'\n' |
| 41 | for line in ${lines}; do |
| 42 | stripped=$(echo $line | sed -e 's/^\s*//' | sed -e 's/\s*$//') |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame] | 43 | if [[ ${stripped} == ${author} ]]; then |
| 44 | found_author=true |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 45 | fi |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame] | 46 | if [[ ${stripped} == ${committer} ]]; then |
| 47 | found_committer=true |
| 48 | fi |
| 49 | |
| 50 | [[ ${found_author} == true && ${found_committer} == true ]] && break |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 51 | done |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 52 | |
Fabio Utzig | 0b56138 | 2017-09-07 17:04:26 -0300 | [diff] [blame] | 53 | if [[ ${found_author} == false || ${found_committer} == false ]]; then |
| 54 | echo -e "One or more \"Signed-off-by\" lines missing in commit ${sha}" |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 55 | exit 1 |
| 56 | fi |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 57 | |
| 58 | has_commits=true |
Fabio Utzig | 5b98910 | 2017-09-04 16:27:51 -0300 | [diff] [blame] | 59 | done |
Fabio Utzig | 3118017 | 2017-09-06 21:38:14 -0300 | [diff] [blame] | 60 | |
| 61 | if [[ ${has_commits} = false ]]; then |
| 62 | echo "No commits found in this PR!" |
| 63 | exit 1 |
| 64 | fi |