1# !/bin/bash 2#===-- merge-request.sh ---------------------------------------------------===# 3# 4# The LLVM Compiler Infrastructure 5# 6# This file is distributed under the University of Illinois Open Source 7# License. 8# 9#===------------------------------------------------------------------------===# 10# 11# Submit a merge request to bugzilla. 12# 13#===------------------------------------------------------------------------===# 14 15dryrun="" 16stable_version="" 17revision="" 18BUGZILLA_BIN="" 19BUGZILLA_CMD="" 20release_metabug="" 21bugzilla_product="new-bugs" 22bugzilla_component="new bugs" 23bugzilla_assigned_to="" 24bugzilla_user="" 25bugzilla_version="" 26bugzilla_url="https://bugs.llvm.org/xmlrpc.cgi" 27 28function usage() { 29 echo "usage: `basename $0` -user EMAIL -stable-version X.Y -r NUM" 30 echo "" 31 echo " -user EMAIL Your email address for logging into bugzilla." 32 echo " -stable-version X.Y The stable release version (e.g. 4.0, 5.0)." 33 echo " -r NUM Revision number to merge (e.g. 1234567)." 34 echo " -bugzilla-bin PATH Path to bugzilla binary (optional)." 35 echo " -assign-to EMAIL Assign bug to user with EMAIL (optional)." 36 echo " -dry-run Print commands instead of executing them." 37} 38 39while [ $# -gt 0 ]; do 40 case $1 in 41 -user) 42 shift 43 bugzilla_user="$1" 44 ;; 45 -stable-version) 46 shift 47 stable_version="$1" 48 ;; 49 -r) 50 shift 51 revision="$1" 52 ;; 53 -project) 54 shift 55 project="$1" 56 ;; 57 -component) 58 shift 59 bugzilla_component="$1" 60 ;; 61 -bugzilla-bin) 62 shift 63 BUGZILLA_BIN="$1" 64 ;; 65 -assign-to) 66 shift 67 bugzilla_assigned_to="--assigned_to=$1" 68 ;; 69 -dry-run) 70 dryrun="echo" 71 ;; 72 -help | --help | -h | --h | -\? ) 73 usage 74 exit 0 75 ;; 76 * ) 77 echo "unknown option: $1" 78 usage 79 exit 1 80 ;; 81 esac 82 shift 83done 84 85if [ -z "$stable_version" ]; then 86 echo "error: no stable version specified" 87 exit 1 88fi 89 90case $stable_version in 91 4.0) 92 release_metabug="32061" 93 ;; 94 *) 95 echo "error: invalid stable version" 96 exit 1 97esac 98bugzilla_version=$stable_version 99 100if [ -z "$revision" ]; then 101 echo "error: revision not specified" 102 exit 1 103fi 104 105if [ -z "$bugzilla_user" ]; then 106 echo "error: bugzilla username not specified." 107 exit 1 108fi 109 110if [ -z "$BUGZILLA_BIN" ]; then 111 BUGZILLA_BIN=`which bugzilla` 112 if [ $? -ne 0 ]; then 113 echo "error: could not find bugzilla executable." 114 echo "Make sure the bugzilla cli tool is installed on your system: " 115 echo "pip install python-bugzilla (recommended)" 116 echo "" 117 echo "Fedora: dnf install python-bugzilla" 118 echo "Ubuntu/Debian: apt-get install bugzilla-cli" 119 exit 1 120 fi 121fi 122 123BUGZILLA_MAJOR_VERSION=`$BUGZILLA_BIN --version 2>&1 | cut -d . -f 1` 124 125if [ $BUGZILLA_MAJOR_VERSION -eq 1 ]; then 126 127 echo "***************************** Warning *******************************" 128 echo "You are using an older version of the bugzilla cli tool. You will be " 129 echo "able to create bugs, but this script will crash with the following " 130 echo "error when trying to read back information about the bug you created:" 131 echo "" 132 echo "KeyError: 'internals'" 133 echo "" 134 echo "To avoid this error, use version 2.0.0 or higher" 135 echo "https://pypi.python.org/pypi/python-bugzilla" 136 echo "*********************************************************************" 137fi 138 139BUGZILLA_CMD="$BUGZILLA_BIN --bugzilla=$bugzilla_url" 140 141bug_url="https://reviews.llvm.org/rL$revision" 142 143echo "Checking for duplicate bugs..." 144 145check_duplicates=`$BUGZILLA_CMD query --url $bug_url` 146 147if [ -n "$check_duplicates" ]; then 148 echo "Duplicate bug found:" 149 echo $check_duplicates 150 exit 1 151fi 152 153echo "Done" 154 155# Get short commit summary 156commit_summary='' 157commit_msg=`svn log -r $revision https://llvm.org/svn/llvm-project/` 158if [ $? -ne 0 ]; then 159 echo "warning: failed to get commit message." 160 commit_msg="" 161fi 162 163if [ -n "$commit_msg" ]; then 164 commit_summary=`echo "$commit_msg" | sed '4q;d' | cut -c1-80` 165 commit_summary=" : ${commit_summary}" 166fi 167 168bug_summary="Merge r$revision into the $stable_version branch${commit_summary}" 169 170if [ -z "$dryrun" ]; then 171 set -x 172fi 173 174${dryrun} $BUGZILLA_CMD --login --user=$bugzilla_user new \ 175 -p "$bugzilla_product" \ 176 -c "$bugzilla_component" -u $bug_url --blocked=$release_metabug \ 177 -o All --priority=P --arch All -v $bugzilla_version \ 178 --summary "${bug_summary}" \ 179 -l "Is this patch OK to merge to the $stable_version branch?" \ 180 $bugzilla_assigned_to \ 181 --oneline 182 183set +x 184 185if [ -n "$dryrun" ]; then 186 exit 0 187fi 188 189if [ $BUGZILLA_MAJOR_VERSION -eq 1 ]; then 190 success=`$BUGZILLA_CMD query --url $bug_url` 191 if [ -z "$success" ]; then 192 echo "Failed to create bug." 193 exit 1 194 fi 195 196 echo " Created new bug:" 197 echo $success 198fi 199