aboutsummaryrefslogtreecommitdiffstats
path: root/pw-request-pull
blob: 07c5276776f456bc52c5346d01a4a5e075ca202c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (C) 2019 Daniel Borkmann <daniel@iogearbox.net>

usage()
{
  cat <<-EOF
  usage: pw-request-pull [-h] [-t TREE] [-s SINCE_COMMIT] [-S] [-c] [-d]
EOF
  exit
}

remote=""
since=""
sign=""
tree=""
create=""
delete=""
today=$(date +%Y-%m-%d)

while true; do
  case "$1" in
    -s | --since ) since="$2"; shift 2 ;;
    -S | --sign ) sign="for-netdev"; shift ;;
    -c | --tag-create ) create="true"; shift ;;
    -d | --tag-delete ) delete="true"; shift ;;
    -t | --tree ) tree="$2"; shift 2 ;;
    -h | --help ) usage; break ;;
    * )  break ;;
  esac
done
[ -z "$tree" ]  && usage
case $tree in
  bpf-next ) remote=(net-next https://git.kernel.org/pub/scm/linux/kernel/git/bpf/$tree.git) ;;
  bpf ) remote=(net https://git.kernel.org/pub/scm/linux/kernel/git/bpf/$tree.git) ;;
  * ) usage ;;
esac
if [ -z "$since" ]; then
  git fetch ${remote[0]}
  branch=$(git rev-parse --abbrev-ref HEAD)
  since=$(git merge-base $branch ${remote[0]}/master)
fi
[ -z "$since" ] && usage

old=$(git log $since -n 1 --format=%ct)
new=$(git log HEAD   -n 1 --format=%ct)
delta=$((($new - $old)/(60*60*24)+1))
count=$(git rev-list --no-merges --count $since...HEAD)
thanks=$(git log --no-merges $since...HEAD --format="%b" | awk '$1 ~ /Reported-by:|Acked-by:|Reviewed-by:|Tested-by:/' | cut -d ' ' -f2- | cut -d '<' -f1 | awk '{$1=$1};1' | grep -v '@' | sort | uniq | sort -n | sed ':a;N;$!ba;s/\n/, /g' | fold -s -w73)
file="pr-$tree-$today.patch"
tag=""
if [ ! -z "$sign" ]; then
  if [ ! -z "$create" ]; then
    git tag -s $sign -m "$tree-$sign"
    git verify-tag $sign
    git push origin $sign
    echo "Signed tag $sign pushed to $tree!"
    exit
  fi
  if [ ! -z "$delete" ]; then
    git push --delete origin $sign
    git tag -d $sign
    echo "Signed tag $sign removed from $tree!"
    exit
  fi
  tag="tags/$sign"
fi
git request-pull $since ${remote[1]} $sign > $file
what=$(cat $file | grep "files changed")

echo -e "Subject: pull-request: $tree $today\n\nHi David, hi Jakub, hi Paolo, hi Eric,\n\nThe following pull-request contains BPF updates for your *${remote[0]}* tree.\n\nWe've added $count non-merge commits during the last $delta day(s) which contain\na total of$what.\n\nThe main changes are:\n\n1) ..., from XYZ. Among others:\n\n    - Blah blah sub item.\n\n2) ..., from ABC.\n\nPlease consider pulling these changes from:\n\n  git://git.kernel.org/pub/scm/linux/kernel/git/bpf/$tree.git $tag\n\nThanks a lot!\n\nAlso thanks to reporters, reviewers and testers of commits in this pull-request:\n\n$thanks\n\n----------------------------------------------------------------\n\n$(cat $file)" > $file
bug=$(grep -c gitolite $file)
if [ "$bug" -gt "0" ]; then
  echo "PR not generated: using gitolite url, not public one!"
  rm -f $file
else
  echo "PR: $file"
fi