#!/bin/bash # pr-create: # # Create a Pull Request and send it to Linus Torvalds # # This script: # # - Craft a PR and put in an email to Linus. # - Generate a list of patches in short-form # # REMOTE: git remote repo the patches are in # TGT_BRANCH: Branch to generate the pull request against REMOTE="xfs-linux" TGT_BRANCH="linus/master" #Email headers RECIPIENT="cem@kernel.org" SUBJECT="" # Email tool NEOMUTT=$(which neomutt) MUTT_CONFIG="$HOME/.mutt/muttrc-Kernel" #temp files PULL_FILE=$(mktemp) MSG_FILE=$(mktemp) #We accept a single argument TAG=$1 _die() { echo "${1}..." usage exit 1 } usage() { echo "usage: pr-create " } check_email() { if [ -z $NEOMUTT ]; then _die "No neomutt found" fi if [ -z $MUTT_CONFIG ] || [ ! -f $MUTT_CONFIG ]; then _die "Please ensure MUTT_CONFIG var is properly set" fi } fixes_setup() { local V=$1 local R=$2 SUBJECT="[GIT PULL] XFS: Fixes for v$V-$R" } merge_setup() { local V=$1 SUBJECT="[GIT PULL] XFS: New code for v$V" } verify_tag() { local T=$1 git tag --verify $T &> /dev/null RES=$? if [ $RES -gt 0 ]; then echo "Tag: $T" _die "Verificaiton failed. Does the tag exist?" fi } generate_pull() { local T=$1 git request-pull $TGT_BRANCH $REMOTE $T &> $PULL_FILE local res=$? if [ $res -gt 0 ]; then local ret=$(head -5 $PULL_FILE) echo "Unable to create pull request:" _die "$ret" fi } craft_message() { local PR=$(cat $1) cat << ENDL Hello Linus, Could you please pull patches included in the tag below? An attempt merge against your current TOT has been successful. Thanks, Carlos "${PR}" ENDL } generate_email() { neomutt -F "${MUTT_CONFIG}" -s "$1" -i "$2" "${RECIPIENT}" } check_email TYPE=$(echo $TAG | sed 's/xfs-//' | awk '{split($0, a, "-"); print a[1]}') VER=$(echo $TAG | sed 's/xfs-//' | awk '{split($0, a, "-"); print a[2]}') RC=$(echo $TAG | sed 's/xfs-//' | awk '{split($0, a, "-"); print a[3]}') if [ $TYPE = "merge" ] && [ $RC ]; then _die "Can't have a -RC tag with a merge tag" fi if [ $TYPE = "fixes" ] && [ -z $RC ]; then _die "A Fixes tag requires a -RC version" fi case $TYPE in "fixes") fixes_setup $VER $RC;; "merge") merge_setup $VER;; *) _die "Invalid tag" esac verify_tag $TAG generate_pull $TAG MSG=$(craft_message $PULL_FILE) echo "$MSG" > $MSG_FILE generate_email "$SUBJECT" "$MSG_FILE" rm $MSG_FILE rm $PULL_FILE