diff options
author | Jakub Kicinski <kuba@kernel.org> | 2020-11-06 09:31:50 -0800 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2020-11-09 22:07:29 +0100 |
commit | c8413ea1f949af1ffcc0989ab33b385e7c1e9e60 (patch) | |
tree | c033a9560a3b50eff177301e3e470e907a5e9140 | |
parent | 49d46025063b272e75bbd6b4c1f45773123dad69 (diff) | |
download | pw-c8413ea1f949af1ffcc0989ab33b385e7c1e9e60.tar.gz |
pw-apply: add auto-merge logic
Query patchwork to see if there is a cover letter, if yes
enable the merge mode and determine the branch name and
merge message automatically.
If there is no cover letter merge commits one by one with
no merge.
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rwxr-xr-x | pw-apply | 97 |
1 files changed, 85 insertions, 12 deletions
@@ -6,8 +6,8 @@ usage() { cat <<-EOF - usage: pw-apply [-h] [-s SERIES] [-b MBOX] [-m BRANCHNAME] [-a] [-3] [-N] - [-e] + usage: pw-apply [-h] [-s SERIES] [-b MBOX] [-m BRANCHNAME] [-M] + [-a] [-3] [-N] [-e] -- [-C] [-a ACKEDBY] [-r REVIEWEDBY] [-t TESTEDBY] EOF exit @@ -25,6 +25,31 @@ mbox_from_series() git pw series download $1 mbox.i 2> /dev/null } +get_cover() +{ + srv=$(git config --get pw.server) + series_json=$(curl -s $srv/series/$1/) + cover_json=$(echo "$series_json" | jq '.cover_letter') + link=$(echo "$cover_json" | jq -r '.mbox' ) + + if [ "$link" == "null" ]; then + return + fi + + curl -s $link > cover.i + cover_subject=$(echo -e "$cover_json" | + jq -r '.name' | + sed -e 's/\[.*\] *//') + branch=$(echo -e "$cover_json" | + jq -r '.name' | + sed -e 's/ *\[.*\] *//g' | + tr '[:upper:]' '[:lower:]' | + tr -d '\n' | + tr -cs '[:alnum:]_-' '-') + [ -n "$branch" -a ${branch: -1} == '-' ] && branch=${branch:: -1} + cover_msgid=$(echo "$cover_json" | jq -r '.msgid' | tr -d '<>') +} + accept_series() { for patch in $(git pw series show $1 -f simple 2> /dev/null | \ @@ -69,6 +94,7 @@ while true; do -e | --do-edits ) edits="1"; shift ;; -N | --no-mb2q ) mb2q_normalize=""; shift ;; -m | --merge ) merge="1"; branch="$2"; shift 2 ;; + -M | --auto-merge) merge="1"; auto_branch="1"; shift ;; -b | --mbox ) mbox="$2"; shift 2 ;; -c | --cover) branch="tmp"; cover="$2"; shift 2 ;; -h | --help ) usage; break ;; @@ -76,6 +102,7 @@ while true; do * ) break ;; esac done +[ ! -z "$auto_branch" ] && [ -z "$series" ] && usage [ ! -z "$mbox" ] && [ ! -z "$series" ] && usage [ -z "$mbox" ] && [ -z "$series" ] && [ -z "$cover" ] && usage [ ! -z "$accept" ] && [ ! -z "$mbox" ] && usage @@ -83,6 +110,25 @@ done [ ! -z "$mbox" ] && mbox_from_url $mbox [ ! -z "$accept" ] && accept_series $series [ ! -z "$cover" ] && cover_from_url $cover + +body= +author=XYZ +if [ ! -z "$auto_branch" ]; then + get_cover $series + [ -z "$cover_msgid" ] && merge= +fi + +if [ ! -z "$auto_branch" -a ! -z "$cover_msgid" ]; then + body=$(cat cover.i | + awk 'BEGIN {h=1;t=0} + /^[A-Za-z. ]* \([0-9]+\):$/ {t=1} + // {if (!h && !t) print} + /^$/ {h=0} ') + author=$(cat cover.i | + sed -n 's/^From: \([A-Za-z. ]*[a-z]\).*$/\1/p' | + tail -1) +fi + git checkout -b $branch if [ ! -z "$mb2q_normalize" ]; then @@ -91,19 +137,31 @@ else cp mbox.i mbox.o fi -flags=$git_am_flags -# When running without mb2q ask git-am for msgid, and have a git hook -# transform that into a lore Link. -[ -z "$mb2q_normalize" ] && flags="$flags -m" -git am $git_am_flags mbox.o - +if [ -z "$merge" ]; then + flags=$git_am_flags + # When running without mb2q ask git-am for msgid, and have a git hook + # transform that into a lore Link. + [ -z "$mb2q_normalize" ] && flags="$flags -m" + git am $flags mbox.o +else + git am $git_am_flags mbox.o + if [ ! -z "$edits" ] ; then + git rebase -i master + fi + while [ -d .git/rebase-merge ]; do + echo -ne "\rWaiting for rebase to finish $(date)" + sleep 0.5 + done + echo +fi git checkout master if [ ! -z "$merge" ]; then git merge --stat --log --no-edit --no-ff $branch - author=`grep 'X-Patchwork-Submitter:' cover.i|cut -f2,3 -d' '` - branch_name=`grep 'Subject:' cover.i|cut -d']' -f2|cut -d' ' -f2-10` - text=`grep -A300 'X-Mailing-List:' cover.i |tail --lines=+3|grep -B300 "$author"|head --lines=-2` - git commit --amend --signoff -F- <<EOF + if [ ! -z "$cover" ]; then + author=`grep 'X-Patchwork-Submitter:' cover.i|cut -f2,3 -d' '` + branch_name=`grep 'Subject:' cover.i|cut -d']' -f2|cut -d' ' -f2-10` + text=`grep -A300 'X-Mailing-List:' cover.i |tail --lines=+3|grep -B300 "$author"|head --lines=-2` + git commit --amend --signoff -F- <<EOF Merge branch '$branch_name' $author says: @@ -112,6 +170,21 @@ $author says: $text ==================== EOF + else + git commit --amend --signoff -F- <<EOF +Merge branch '$branch' + +$author says: + +==================== +$cover_subject + +$body +==================== + +Link: https://lore.kernel.org/r/$cover_msgid +EOF + fi else git merge --stat --ff $branch fi |