xref: /netbsd-src/external/apache2/llvm/dist/llvm/utils/release/merge-request.sh (revision 7330f729ccf0bd976a06f95fad452fe774fc7fd1)
1*7330f729Sjoerg#!/usr/bin/env bash
2*7330f729Sjoerg#===-- merge-request.sh  ---------------------------------------------------===#
3*7330f729Sjoerg#
4*7330f729Sjoerg# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*7330f729Sjoerg# See https://llvm.org/LICENSE.txt for license information.
6*7330f729Sjoerg# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*7330f729Sjoerg#
8*7330f729Sjoerg#===------------------------------------------------------------------------===#
9*7330f729Sjoerg#
10*7330f729Sjoerg# Submit a merge request to bugzilla.
11*7330f729Sjoerg#
12*7330f729Sjoerg#===------------------------------------------------------------------------===#
13*7330f729Sjoerg
14*7330f729Sjoergdryrun=""
15*7330f729Sjoergstable_version=""
16*7330f729Sjoergrevisions=""
17*7330f729SjoergBUGZILLA_BIN=""
18*7330f729SjoergBUGZILLA_CMD=""
19*7330f729Sjoergrelease_metabug=""
20*7330f729Sjoergbugzilla_product="new-bugs"
21*7330f729Sjoergbugzilla_component="new bugs"
22*7330f729Sjoergbugzilla_assigned_to=""
23*7330f729Sjoergbugzilla_user=""
24*7330f729Sjoergbugzilla_version=""
25*7330f729Sjoergbugzilla_url="https://bugs.llvm.org/xmlrpc.cgi"
26*7330f729Sjoerg
27*7330f729Sjoergfunction usage() {
28*7330f729Sjoerg  echo "usage: `basename $0` -user EMAIL -stable-version X.Y -r NUM"
29*7330f729Sjoerg  echo ""
30*7330f729Sjoerg  echo " -user EMAIL             Your email address for logging into bugzilla."
31*7330f729Sjoerg  echo " -stable-version X.Y     The stable release version (e.g. 4.0, 5.0)."
32*7330f729Sjoerg  echo " -r NUM                  Revision number to merge (e.g. 1234567)."
33*7330f729Sjoerg  echo "                         This option can be specified multiple times."
34*7330f729Sjoerg  echo " -bugzilla-bin PATH      Path to bugzilla binary (optional)."
35*7330f729Sjoerg  echo " -assign-to EMAIL        Assign bug to user with EMAIL (optional)."
36*7330f729Sjoerg  echo " -dry-run                Print commands instead of executing them."
37*7330f729Sjoerg}
38*7330f729Sjoerg
39*7330f729Sjoergwhile [ $# -gt 0 ]; do
40*7330f729Sjoerg  case $1 in
41*7330f729Sjoerg    -user)
42*7330f729Sjoerg      shift
43*7330f729Sjoerg      bugzilla_user="$1"
44*7330f729Sjoerg      ;;
45*7330f729Sjoerg    -stable-version)
46*7330f729Sjoerg      shift
47*7330f729Sjoerg      stable_version="$1"
48*7330f729Sjoerg      ;;
49*7330f729Sjoerg    -r)
50*7330f729Sjoerg      shift
51*7330f729Sjoerg      revisions="$revisions $1"
52*7330f729Sjoerg      ;;
53*7330f729Sjoerg    -project)
54*7330f729Sjoerg      shift
55*7330f729Sjoerg      project="$1"
56*7330f729Sjoerg      ;;
57*7330f729Sjoerg    -component)
58*7330f729Sjoerg      shift
59*7330f729Sjoerg      bugzilla_component="$1"
60*7330f729Sjoerg      ;;
61*7330f729Sjoerg    -bugzilla-bin)
62*7330f729Sjoerg      shift
63*7330f729Sjoerg      BUGZILLA_BIN="$1"
64*7330f729Sjoerg      ;;
65*7330f729Sjoerg    -assign-to)
66*7330f729Sjoerg      shift
67*7330f729Sjoerg      bugzilla_assigned_to="--assigned_to=$1"
68*7330f729Sjoerg      ;;
69*7330f729Sjoerg    -dry-run)
70*7330f729Sjoerg      dryrun="echo"
71*7330f729Sjoerg      ;;
72*7330f729Sjoerg    -help | --help | -h | --h | -\? )
73*7330f729Sjoerg      usage
74*7330f729Sjoerg      exit 0
75*7330f729Sjoerg      ;;
76*7330f729Sjoerg    * )
77*7330f729Sjoerg      echo "unknown option: $1"
78*7330f729Sjoerg      usage
79*7330f729Sjoerg      exit 1
80*7330f729Sjoerg      ;;
81*7330f729Sjoerg  esac
82*7330f729Sjoerg  shift
83*7330f729Sjoergdone
84*7330f729Sjoerg
85*7330f729Sjoergif [ -z "$stable_version" ]; then
86*7330f729Sjoerg  echo "error: no stable version specified"
87*7330f729Sjoerg  exit 1
88*7330f729Sjoergfi
89*7330f729Sjoerg
90*7330f729Sjoergcase $stable_version in
91*7330f729Sjoerg  4.0)
92*7330f729Sjoerg    release_metabug="32061"
93*7330f729Sjoerg    ;;
94*7330f729Sjoerg  5.0)
95*7330f729Sjoerg    release_metabug="34492"
96*7330f729Sjoerg    ;;
97*7330f729Sjoerg  6.0)
98*7330f729Sjoerg    release_metabug="36649"
99*7330f729Sjoerg    ;;
100*7330f729Sjoerg  7.0)
101*7330f729Sjoerg    release_metabug="39106"
102*7330f729Sjoerg    ;;
103*7330f729Sjoerg  8.0)
104*7330f729Sjoerg    release_metabug="41221"
105*7330f729Sjoerg    ;;
106*7330f729Sjoerg  9.0)
107*7330f729Sjoerg    release_metabug="43360"
108*7330f729Sjoerg    ;;
109*7330f729Sjoerg  *)
110*7330f729Sjoerg    echo "error: invalid stable version"
111*7330f729Sjoerg    exit 1
112*7330f729Sjoergesac
113*7330f729Sjoergbugzilla_version=$stable_version
114*7330f729Sjoerg
115*7330f729Sjoergif [ -z "$revisions" ]; then
116*7330f729Sjoerg  echo "error: no revisions specified"
117*7330f729Sjoerg  exit 1
118*7330f729Sjoergfi
119*7330f729Sjoerg
120*7330f729Sjoergif [ -z "$bugzilla_user" ]; then
121*7330f729Sjoerg  echo "error: bugzilla username not specified."
122*7330f729Sjoerg  exit 1
123*7330f729Sjoergfi
124*7330f729Sjoerg
125*7330f729Sjoergif [ -z "$BUGZILLA_BIN" ]; then
126*7330f729Sjoerg  BUGZILLA_BIN=`which bugzilla`
127*7330f729Sjoerg  if [ $? -ne 0 ]; then
128*7330f729Sjoerg    echo "error: could not find bugzilla executable."
129*7330f729Sjoerg    echo "Make sure the bugzilla cli tool is installed on your system: "
130*7330f729Sjoerg    echo "pip install python-bugzilla (recommended)"
131*7330f729Sjoerg    echo ""
132*7330f729Sjoerg    echo "Fedora: dnf install python-bugzilla"
133*7330f729Sjoerg    echo "Ubuntu/Debian: apt-get install bugzilla-cli"
134*7330f729Sjoerg    exit 1
135*7330f729Sjoerg  fi
136*7330f729Sjoergfi
137*7330f729Sjoerg
138*7330f729SjoergBUGZILLA_MAJOR_VERSION=`$BUGZILLA_BIN --version 2>&1 | cut -d . -f 1`
139*7330f729Sjoerg
140*7330f729Sjoergif [ $BUGZILLA_MAJOR_VERSION -eq 1 ]; then
141*7330f729Sjoerg
142*7330f729Sjoerg  echo "***************************** Error ** ********************************"
143*7330f729Sjoerg  echo "You are using an older version of the bugzilla cli tool, which is not "
144*7330f729Sjoerg  echo "supported.  You need to use bugzilla cli version 2.0.0 or higher:"
145*7330f729Sjoerg  echo "***********************************************************************"
146*7330f729Sjoerg  exit 1
147*7330f729Sjoergfi
148*7330f729Sjoerg
149*7330f729SjoergBUGZILLA_CMD="$BUGZILLA_BIN --bugzilla=$bugzilla_url"
150*7330f729Sjoerg
151*7330f729Sjoergrev_string=""
152*7330f729Sjoergfor r in $revisions; do
153*7330f729Sjoerg  rev_string="$rev_string r$r"
154*7330f729Sjoergdone
155*7330f729Sjoerg
156*7330f729Sjoergecho "Checking for duplicate bugs..."
157*7330f729Sjoerg
158*7330f729Sjoergcheck_duplicates=`$BUGZILLA_CMD query --blocked=$release_metabug --field="cf_fixed_by_commits=$rev_string"`
159*7330f729Sjoerg
160*7330f729Sjoergif [ -n "$check_duplicates" ]; then
161*7330f729Sjoerg  echo "Duplicate bug found:"
162*7330f729Sjoerg  echo $check_duplicates
163*7330f729Sjoerg  exit 1
164*7330f729Sjoergfi
165*7330f729Sjoerg
166*7330f729Sjoergecho "Done"
167*7330f729Sjoerg
168*7330f729Sjoerg# Get short commit summary.  To avoid having a huge summary, we just
169*7330f729Sjoerg# use the commit message for the first commit.
170*7330f729Sjoergcommit_summary=''
171*7330f729Sjoergfor r in $revisions; do
172*7330f729Sjoerg  commit_msg=`svn log -r $r https://llvm.org/svn/llvm-project/`
173*7330f729Sjoerg  if [ $? -ne 0 ]; then
174*7330f729Sjoerg    echo "warning: failed to get commit message."
175*7330f729Sjoerg    commit_msg=""
176*7330f729Sjoerg  fi
177*7330f729Sjoerg  break
178*7330f729Sjoergdone
179*7330f729Sjoerg
180*7330f729Sjoergif [ -n "$commit_msg" ]; then
181*7330f729Sjoerg  commit_summary=`echo "$commit_msg" | sed '4q;d' | cut -c1-80`
182*7330f729Sjoerg  commit_summary=" : ${commit_summary}"
183*7330f729Sjoergfi
184*7330f729Sjoerg
185*7330f729Sjoergbug_summary="Merge${rev_string} into the $stable_version branch${commit_summary}"
186*7330f729Sjoerg
187*7330f729Sjoergset -x
188*7330f729Sjoerg
189*7330f729Sjoerg# Login to bugzilla
190*7330f729Sjoerg$BUGZILLA_CMD login $bugzilla_user
191*7330f729Sjoerg
192*7330f729Sjoergbug_id=`${dryrun} $BUGZILLA_CMD --ensure-logged-in new \
193*7330f729Sjoerg  -p "$bugzilla_product" \
194*7330f729Sjoerg  -c "$bugzilla_component" --blocked=$release_metabug \
195*7330f729Sjoerg  -o All --priority=P --arch All -v $bugzilla_version \
196*7330f729Sjoerg  --field="cf_fixed_by_commits=$rev_string" \
197*7330f729Sjoerg  --summary "${bug_summary}" \
198*7330f729Sjoerg  -l "Is it OK to merge the following revision(s) to the $stable_version branch?" \
199*7330f729Sjoerg  $bugzilla_assigned_to \
200*7330f729Sjoerg  -i`
201*7330f729Sjoerg
202*7330f729Sjoergif [ -n "$dryrun" ]; then
203*7330f729Sjoerg  exit 0
204*7330f729Sjoergfi
205*7330f729Sjoerg
206*7330f729Sjoergset +x
207*7330f729Sjoerg
208*7330f729Sjoergif [ -z "$bug_id" ]; then
209*7330f729Sjoerg  echo "Failed to create bug."
210*7330f729Sjoerg  exit 1
211*7330f729Sjoergfi
212*7330f729Sjoerg
213*7330f729Sjoergecho " Created new bug:"
214*7330f729Sjoergecho https://llvm.org/PR$bug_id
215*7330f729Sjoerg
216*7330f729Sjoerg# Add links to revisions
217*7330f729Sjoergfor r in $revisions; do
218*7330f729Sjoerg  $BUGZILLA_CMD --ensure-logged-in modify -l "https://reviews.llvm.org/rL$r" $bug_id
219*7330f729Sjoergdone
220