diff options
| author | Carlos Maiolino <[email protected]> | 2025-11-27 15:09:48 +0100 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2025-11-27 15:09:48 +0100 |
| commit | b2e1a1cb259e482720430ff9898d2e564ee73d0f (patch) | |
| tree | 586597a47068ed4197239bb41664caa7a97a5094 | |
| parent | 2a3f0db27360e40ebce504c0f95973b27f6ee3a0 (diff) | |
pr-create.sh: Create a pull request based on tag
Create a pull request for Linus based on a tag.
neomutt is opened and message assembled to be sent.
Signed-off-by: Carlos Maiolino <[email protected]>
| -rwxr-xr-x | maintainer/pr-create.sh | 138 |
1 files changed, 88 insertions, 50 deletions
diff --git a/maintainer/pr-create.sh b/maintainer/pr-create.sh index bffa72f..62721b0 100755 --- a/maintainer/pr-create.sh +++ b/maintainer/pr-create.sh @@ -4,69 +4,92 @@ # # Create a Pull Request and send it to Linus Torvalds # -# This script does: +# This script: # -# - Create a signed tag -# - push the branch and the tag to xfs-linux repository +# - Craft a PR and put in an email to Linus. # - Generate a list of patches in short-form -# - Craft a PR and email to Linus. # +# REMOTE: git remote repo the patches are in +# TGT_BRANCH: Branch to generate the pull request against -#REMOTE="cem-xfs" REMOTE="xfs-linux" -BRANCH="$1" -TAG="$2" -TAG_MESSAGE="Signed-off-by: Carlos Maiolino <[email protected]>" +TGT_BRANCH="linus/master" + +#Email headers RECIPIENT="[email protected]" +SUBJECT="" -# Sending email global vars -usage() { - echo "usage: pr-create <branch> <tag>" -} +# Email tool +NEOMUTT=$(which neomutt) +MUTT_CONFIG="$HOME/.mutt/muttrc-Kernel" + +#temp files +PULL_FILE=$(mktemp) +MSG_FILE=$(mktemp) -die() { - echo "${1}... Exiting" +#We accept a single argument +TAG=$1 + +_die() { + echo "${1}..." + usage exit 1 } -git_verify_branch() { - local CUR_BRANCH=`git branch --show-current` - - if [ "${CUR_BRANCH}" != "${BRANCH}" ]; then - echo "Different branch is checked out..." - echo "... Attempting to checkout branch ${BRANCH}" +usage() { + echo "usage: pr-create <tag>" +} - git checkout -q ${BRANCH} 2> /dev/null +check_email() { + if [ -z $NEOMUTT ]; then + _die "No neomutt found" + fi - if [ $? -ne 0 ]; then - return 1 - else - # Reset status to the old branch - git checkout -q ${CUR_BRANCH} 2> /dev/null - fi + if [ -z $MUTT_CONFIG ] || [ ! -f $MUTT_CONFIG ]; then + _die "Please ensure MUTT_CONFIG var is properly set" fi } -git_create_tag() { - git tag -s ${TAG} -m "${TAG_MESSAGE}" +fixes_setup() { + local V=$1 + local R=$2 + SUBJECT="[GIT PULL] XFS: Fixes for v$V-$R" + } -push_branch() { - git push ${REMOTE} ${BRANCH}:${BRANCH} +merge_setup() { + local V=$1 + SUBJECT="[GIT PULL] XFS: New code for v$V" } -push_tag() { - git push ${REMOTE} ${TAG} +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 } -git_craft_pr() { - local MSG=`git request-pull ${BRANCH} ${REMOTE} ${TAG}` - echo -e "$MSG" +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 MSG=$(git_craft_pr) + local PR=$(cat $1) cat << ENDL Hello Linus, @@ -77,30 +100,45 @@ An attempt merge against your current TOT has been successful. Thanks, Carlos -${MSG} +"${PR}" ENDL } generate_email() { - local MUTT_CONFIG="$HOME/.mutt/muttrc-Kernel" - neomutt -F ${MUTT_CONFIG} -s "$1" -i "$2" ${RECIPIENT} + neomutt -F "${MUTT_CONFIG}" -s "$1" -i "$2" "${RECIPIENT}" } -if [ -z "${BRANCH}" ] || [ -z "${TAG}" ]; then - usage -fi +check_email -git_verify_branch +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 [ $? -ne 0 ]; then - die "Couldn't verify branch" +if [ $TYPE = "merge" ] && [ $RC ]; then + _die "Can't have a -RC tag with a merge tag" fi -MAIL_MSG=$(mktemp) +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 -craft_message > $MAIL_MSG +generate_email "$SUBJECT" "$MSG_FILE" -SUBJ="[GIT PULL] XFS fixes for v6.14" -generate_email "$SUBJ" $MAIL_MSG +rm $MSG_FILE +rm $PULL_FILE |
