blob: 1acc9e3e683cc3c9b327e07f296af79065b902f0 [file] [log] [blame]
Tom Stellardd9122432017-03-24 16:13:18 +00001# !/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=""
Tom Stellarda9191b52017-09-15 02:25:22 +000017revisions=""
Tom Stellardd9122432017-03-24 16:13:18 +000018BUGZILLA_BIN=""
19BUGZILLA_CMD=""
20release_metabug=""
21bugzilla_product="new-bugs"
22bugzilla_component="new bugs"
23bugzilla_assigned_to=""
24bugzilla_user=""
25bugzilla_version=""
Tom Stellardf43ece32017-05-23 20:35:38 +000026bugzilla_url="https://bugs.llvm.org/xmlrpc.cgi"
Tom Stellardd9122432017-03-24 16:13:18 +000027
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)."
Tom Stellarda9191b52017-09-15 02:25:22 +000034 echo " This option can be specified multiple times."
Tom Stellardd9122432017-03-24 16:13:18 +000035 echo " -bugzilla-bin PATH Path to bugzilla binary (optional)."
36 echo " -assign-to EMAIL Assign bug to user with EMAIL (optional)."
37 echo " -dry-run Print commands instead of executing them."
38}
39
40while [ $# -gt 0 ]; do
41 case $1 in
42 -user)
43 shift
44 bugzilla_user="$1"
45 ;;
46 -stable-version)
47 shift
48 stable_version="$1"
49 ;;
50 -r)
51 shift
Tom Stellarda9191b52017-09-15 02:25:22 +000052 revisions="$revisions $1"
Tom Stellardd9122432017-03-24 16:13:18 +000053 ;;
54 -project)
55 shift
56 project="$1"
57 ;;
58 -component)
59 shift
60 bugzilla_component="$1"
61 ;;
62 -bugzilla-bin)
63 shift
64 BUGZILLA_BIN="$1"
65 ;;
66 -assign-to)
67 shift
68 bugzilla_assigned_to="--assigned_to=$1"
69 ;;
70 -dry-run)
71 dryrun="echo"
72 ;;
73 -help | --help | -h | --h | -\? )
74 usage
75 exit 0
76 ;;
77 * )
78 echo "unknown option: $1"
79 usage
80 exit 1
81 ;;
82 esac
83 shift
84done
85
86if [ -z "$stable_version" ]; then
87 echo "error: no stable version specified"
88 exit 1
89fi
90
91case $stable_version in
92 4.0)
93 release_metabug="32061"
94 ;;
Tom Stellarda9191b52017-09-15 02:25:22 +000095 5.0)
96 release_metabug="34492"
97 ;;
Matt Arsenault05d8f162018-01-03 18:51:22 +000098 6.0)
99 release_metabug="35804"
100 ;;
Tom Stellardd9122432017-03-24 16:13:18 +0000101 *)
102 echo "error: invalid stable version"
103 exit 1
104esac
105bugzilla_version=$stable_version
106
Tom Stellarda9191b52017-09-15 02:25:22 +0000107if [ -z "$revisions" ]; then
108 echo "error: no revisions specified"
Tom Stellardd9122432017-03-24 16:13:18 +0000109 exit 1
110fi
111
112if [ -z "$bugzilla_user" ]; then
113 echo "error: bugzilla username not specified."
114 exit 1
115fi
116
117if [ -z "$BUGZILLA_BIN" ]; then
118 BUGZILLA_BIN=`which bugzilla`
119 if [ $? -ne 0 ]; then
120 echo "error: could not find bugzilla executable."
121 echo "Make sure the bugzilla cli tool is installed on your system: "
122 echo "pip install python-bugzilla (recommended)"
123 echo ""
124 echo "Fedora: dnf install python-bugzilla"
125 echo "Ubuntu/Debian: apt-get install bugzilla-cli"
126 exit 1
127 fi
128fi
129
130BUGZILLA_MAJOR_VERSION=`$BUGZILLA_BIN --version 2>&1 | cut -d . -f 1`
131
132if [ $BUGZILLA_MAJOR_VERSION -eq 1 ]; then
133
Tom Stellarda9191b52017-09-15 02:25:22 +0000134 echo "***************************** Error ** ********************************"
135 echo "You are using an older version of the bugzilla cli tool, which is not "
136 echo "supported. You need to use bugzilla cli version 2.0.0 or higher:"
137 echo "***********************************************************************"
138 exit 1
Tom Stellardd9122432017-03-24 16:13:18 +0000139fi
140
141BUGZILLA_CMD="$BUGZILLA_BIN --bugzilla=$bugzilla_url"
142
Tom Stellarda9191b52017-09-15 02:25:22 +0000143rev_string=""
144for r in $revisions; do
145 rev_string="$rev_string r$r"
146done
Tom Stellardd9122432017-03-24 16:13:18 +0000147
148echo "Checking for duplicate bugs..."
149
Tom Stellarda9191b52017-09-15 02:25:22 +0000150check_duplicates=`$BUGZILLA_CMD query --blocked=$release_metabug --field="cf_fixed_by_commits=$rev_string"`
Tom Stellardd9122432017-03-24 16:13:18 +0000151
152if [ -n "$check_duplicates" ]; then
153 echo "Duplicate bug found:"
154 echo $check_duplicates
155 exit 1
156fi
157
158echo "Done"
159
Tom Stellarda9191b52017-09-15 02:25:22 +0000160# Get short commit summary. To avoid having a huge summary, we just
161# use the commit message for the first commit.
Tom Stellardd9122432017-03-24 16:13:18 +0000162commit_summary=''
Tom Stellarda9191b52017-09-15 02:25:22 +0000163for r in $revisions; do
164 commit_msg=`svn log -r $r https://llvm.org/svn/llvm-project/`
165 if [ $? -ne 0 ]; then
166 echo "warning: failed to get commit message."
167 commit_msg=""
168 fi
169 break
170done
Tom Stellardd9122432017-03-24 16:13:18 +0000171
172if [ -n "$commit_msg" ]; then
173 commit_summary=`echo "$commit_msg" | sed '4q;d' | cut -c1-80`
174 commit_summary=" : ${commit_summary}"
175fi
176
Tom Stellarda9191b52017-09-15 02:25:22 +0000177bug_summary="Merge${rev_string} into the $stable_version branch${commit_summary}"
Tom Stellardd9122432017-03-24 16:13:18 +0000178
Tom Stellarda9191b52017-09-15 02:25:22 +0000179set -x
Tom Stellardd9122432017-03-24 16:13:18 +0000180
Tom Stellarda9191b52017-09-15 02:25:22 +0000181# Login to bugzilla
182$BUGZILLA_CMD login $bugzilla_user
183
184bug_id=`${dryrun} $BUGZILLA_CMD --ensure-logged-in new \
Tom Stellardd9122432017-03-24 16:13:18 +0000185 -p "$bugzilla_product" \
Tom Stellarda9191b52017-09-15 02:25:22 +0000186 -c "$bugzilla_component" --blocked=$release_metabug \
Tom Stellardd9122432017-03-24 16:13:18 +0000187 -o All --priority=P --arch All -v $bugzilla_version \
Tom Stellarda9191b52017-09-15 02:25:22 +0000188 --field="cf_fixed_by_commits=$rev_string" \
Tom Stellardd9122432017-03-24 16:13:18 +0000189 --summary "${bug_summary}" \
Tom Stellarda9191b52017-09-15 02:25:22 +0000190 -l "Is it OK to merge the following revision(s) to the $stable_version branch?" \
Tom Stellardd9122432017-03-24 16:13:18 +0000191 $bugzilla_assigned_to \
Tom Stellarda9191b52017-09-15 02:25:22 +0000192 -i`
Tom Stellardd9122432017-03-24 16:13:18 +0000193
194if [ -n "$dryrun" ]; then
195 exit 0
196fi
197
Tom Stellarda9191b52017-09-15 02:25:22 +0000198set +x
Tom Stellardd9122432017-03-24 16:13:18 +0000199
Tom Stellarda9191b52017-09-15 02:25:22 +0000200if [ -z "$bug_id" ]; then
201 echo "Failed to create bug."
202 exit 1
Tom Stellardd9122432017-03-24 16:13:18 +0000203fi
Tom Stellarda9191b52017-09-15 02:25:22 +0000204
205echo " Created new bug:"
206echo https://llvm.org/PR$bug_id
207
208# Add links to revisions
209for r in $revisions; do
210 $BUGZILLA_CMD --ensure-logged-in modify -l "https://reviews.llvm.org/rL$r" $bug_id
211done