brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.2 KiB · 5cc7d1f Raw
220 lines · bash
1#!/usr/bin/env bash2#===-- merge-request.sh  ---------------------------------------------------===#3#4# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5# See https://llvm.org/LICENSE.txt for license information.6# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7#8#===------------------------------------------------------------------------===#9#10# Submit a merge request to bugzilla.11#12#===------------------------------------------------------------------------===#13 14dryrun=""15stable_version=""16revisions=""17BUGZILLA_BIN=""18BUGZILLA_CMD=""19release_metabug=""20bugzilla_product="new-bugs"21bugzilla_component="new bugs"22bugzilla_assigned_to=""23bugzilla_user=""24bugzilla_version=""25bugzilla_url="https://bugs.llvm.org/xmlrpc.cgi"26 27function usage() {28  echo "usage: `basename $0` -user EMAIL -stable-version X.Y -r NUM"29  echo ""30  echo " -user EMAIL             Your email address for logging into bugzilla."31  echo " -stable-version X.Y     The stable release version (e.g. 4.0, 5.0)."32  echo " -r NUM                  Revision number to merge (e.g. 1234567)."33  echo "                         This option can be specified multiple times."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 ]; do40  case $1 in41    -user)42      shift43      bugzilla_user="$1"44      ;;45    -stable-version)46      shift47      stable_version="$1"48      ;;49    -r)50      shift51      revisions="$revisions $1"52      ;;53    -project)54      shift55      project="$1"56      ;;57    -component)58      shift59      bugzilla_component="$1"60      ;;61    -bugzilla-bin)62      shift63      BUGZILLA_BIN="$1"64      ;;65    -assign-to)66      shift67      bugzilla_assigned_to="--assigned_to=$1"68      ;;69    -dry-run)70      dryrun="echo"71      ;;72    -help | --help | -h | --h | -\? )73      usage74      exit 075      ;;76    * )77      echo "unknown option: $1"78      usage79      exit 180      ;;81  esac82  shift83done84 85if [ -z "$stable_version" ]; then86  echo "error: no stable version specified"87  exit 188fi89 90case $stable_version in91  4.0)92    release_metabug="32061"93    ;;94  5.0)95    release_metabug="34492"96    ;;97  6.0)98    release_metabug="36649"99    ;;100  7.0)101    release_metabug="39106"102    ;;103  8.0)104    release_metabug="41221"105    ;;106  9.0)107    release_metabug="43360"108    ;;109  *)110    echo "error: invalid stable version"111    exit 1112esac113bugzilla_version=$stable_version114 115if [ -z "$revisions" ]; then116  echo "error: no revisions specified"117  exit 1118fi119 120if [ -z "$bugzilla_user" ]; then121  echo "error: bugzilla username not specified."122  exit 1123fi124 125if [ -z "$BUGZILLA_BIN" ]; then126  BUGZILLA_BIN=`which bugzilla`127  if [ $? -ne 0 ]; then128    echo "error: could not find bugzilla executable."129    echo "Make sure the bugzilla cli tool is installed on your system: "130    echo "pip install python-bugzilla (recommended)"131    echo ""132    echo "Fedora: dnf install python-bugzilla"133    echo "Ubuntu/Debian: apt-get install bugzilla-cli"134    exit 1135  fi136fi137 138BUGZILLA_MAJOR_VERSION=`$BUGZILLA_BIN --version 2>&1 | cut -d . -f 1`139 140if [ $BUGZILLA_MAJOR_VERSION -eq 1 ]; then141 142  echo "***************************** Error ** ********************************"143  echo "You are using an older version of the bugzilla cli tool, which is not "144  echo "supported.  You need to use bugzilla cli version 2.0.0 or higher:"145  echo "***********************************************************************"146  exit 1147fi148 149BUGZILLA_CMD="$BUGZILLA_BIN --bugzilla=$bugzilla_url"150 151rev_string=""152for r in $revisions; do153  rev_string="$rev_string r$r"154done155 156echo "Checking for duplicate bugs..."157 158check_duplicates=`$BUGZILLA_CMD query --blocked=$release_metabug --field="cf_fixed_by_commits=$rev_string"`159 160if [ -n "$check_duplicates" ]; then161  echo "Duplicate bug found:"162  echo $check_duplicates163  exit 1164fi165 166echo "Done"167 168# Get short commit summary.  To avoid having a huge summary, we just169# use the commit message for the first commit.170commit_summary=''171for r in $revisions; do172  commit_msg=`svn log -r $r https://llvm.org/svn/llvm-project/`173  if [ $? -ne 0 ]; then174    echo "warning: failed to get commit message."175    commit_msg=""176  fi177  break178done179 180if [ -n "$commit_msg" ]; then181  commit_summary=`echo "$commit_msg" | sed '4q;d' | cut -c1-80`182  commit_summary=" : ${commit_summary}"183fi184 185bug_summary="Merge${rev_string} into the $stable_version branch${commit_summary}"186 187set -x188 189# Login to bugzilla190$BUGZILLA_CMD login $bugzilla_user191 192bug_id=`${dryrun} $BUGZILLA_CMD --ensure-logged-in new \193  -p "$bugzilla_product" \194  -c "$bugzilla_component" --blocked=$release_metabug \195  -o All --priority=P --arch All -v $bugzilla_version \196  --field="cf_fixed_by_commits=$rev_string" \197  --summary "${bug_summary}" \198  -l "Is it OK to merge the following revision(s) to the $stable_version branch?" \199  $bugzilla_assigned_to \200  -i`201 202if [ -n "$dryrun" ]; then203  exit 0204fi205 206set +x207 208if [ -z "$bug_id" ]; then209  echo "Failed to create bug."210  exit 1211fi212 213echo " Created new bug:"214echo https://llvm.org/PR$bug_id215 216# Add links to revisions217for r in $revisions; do218  $BUGZILLA_CMD --ensure-logged-in modify -l "https://reviews.llvm.org/rL$r" $bug_id219done220