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