17
17
# limitations under the License.
18
18
#
19
19
20
- # Utility for creating well-formed pull request merges and pushing them to Apache.
20
+ # Utility for creating well-formed pull request merges and pushing them to
21
+ # Apache.
21
22
# usage: ./apache-pr-merge.py (see config env vars below)
22
23
#
23
24
# Lightly modified from version of this script in incubator-parquet-format
@@ -121,33 +122,39 @@ def clean_up():
121
122
# merge the requested PR and return the merge hash
122
123
def merge_pr (pr_num , target_ref ):
123
124
pr_branch_name = "%s_MERGE_PR_%s" % (BRANCH_PREFIX , pr_num )
124
- target_branch_name = "%s_MERGE_PR_%s_%s" % (BRANCH_PREFIX , pr_num , target_ref .upper ())
125
- run_cmd ("git fetch %s pull/%s/head:%s" % (PR_REMOTE_NAME , pr_num , pr_branch_name ))
126
- run_cmd ("git fetch %s %s:%s" % (PUSH_REMOTE_NAME , target_ref , target_branch_name ))
125
+ target_branch_name = "%s_MERGE_PR_%s_%s" % (BRANCH_PREFIX , pr_num ,
126
+ target_ref .upper ())
127
+ run_cmd ("git fetch %s pull/%s/head:%s" % (PR_REMOTE_NAME , pr_num ,
128
+ pr_branch_name ))
129
+ run_cmd ("git fetch %s %s:%s" % (PUSH_REMOTE_NAME , target_ref ,
130
+ target_branch_name ))
127
131
run_cmd ("git checkout %s" % target_branch_name )
128
132
129
133
had_conflicts = False
130
134
try :
131
135
run_cmd (['git' , 'merge' , pr_branch_name , '--squash' ])
132
136
except Exception as e :
133
- msg = "Error merging: %s\n Would you like to manually fix-up this merge?" % e
137
+ msg = ("Error merging: %s\n Would you like to manually fix-up "
138
+ "this merge?" % e )
134
139
continue_maybe (msg )
135
- msg = "Okay, please fix any conflicts and 'git add' conflicting files... Finished?"
140
+ msg = ("Okay, please fix any conflicts and 'git add' "
141
+ "conflicting files... Finished?" )
136
142
continue_maybe (msg )
137
143
had_conflicts = True
138
144
139
145
commit_authors = run_cmd (['git' , 'log' , 'HEAD..%s' % pr_branch_name ,
140
146
'--pretty=format:%an <%ae>' ]).split ("\n " )
141
147
distinct_authors = sorted (set (commit_authors ),
142
- key = lambda x : commit_authors .count (x ), reverse = True )
148
+ key = lambda x : commit_authors .count (x ),
149
+ reverse = True )
143
150
primary_author = distinct_authors [0 ]
144
151
commits = run_cmd (['git' , 'log' , 'HEAD..%s' % pr_branch_name ,
145
152
'--pretty=format:%h [%an] %s' ]).split ("\n \n " )
146
153
147
154
merge_message_flags = []
148
155
149
156
merge_message_flags += ["-m" , title ]
150
- if body != None :
157
+ if body is not None :
151
158
merge_message_flags += ["-m" , '\n ' .join (textwrap .wrap (body ))]
152
159
153
160
authors = "\n " .join (["Author: %s" % a for a in distinct_authors ])
@@ -157,14 +164,17 @@ def merge_pr(pr_num, target_ref):
157
164
if had_conflicts :
158
165
committer_name = run_cmd ("git config --get user.name" ).strip ()
159
166
committer_email = run_cmd ("git config --get user.email" ).strip ()
160
- message = "This patch had conflicts when merged, resolved by\n Committer: %s <%s>" % (
161
- committer_name , committer_email )
167
+ message = ("This patch had conflicts when merged, "
168
+ "resolved by\n Committer: %s <%s>"
169
+ % (committer_name , committer_email ))
162
170
merge_message_flags += ["-m" , message ]
163
171
164
- # The string "Closes #%s" string is required for GitHub to correctly close the PR
172
+ # The string "Closes #%s" string is required for GitHub to correctly close
173
+ # the PR
165
174
merge_message_flags += [
166
175
"-m" ,
167
- "Closes #%s from %s and squashes the following commits:" % (pr_num , pr_repo_desc )]
176
+ "Closes #%s from %s and squashes the following commits:"
177
+ % (pr_num , pr_repo_desc )]
168
178
for c in commits :
169
179
merge_message_flags += ["-m" , c ]
170
180
@@ -229,9 +239,9 @@ def fix_version_from_branch(branch, versions):
229
239
return filter (lambda x : x .name .startswith (branch_ver ), versions )[- 1 ]
230
240
231
241
232
- branches = get_json ("%s/branches" % GITHUB_API_BASE )
233
- branch_names = filter (lambda x : x .startswith ("branch-" ),
234
- [x ['name' ] for x in branches ])
242
+ # branches = get_json("%s/branches" % GITHUB_API_BASE)
243
+ # branch_names = filter(lambda x: x.startswith("branch-"),
244
+ # [x['name'] for x in branches])
235
245
# Assumes branch names can be sorted lexicographically
236
246
# latest_branch = sorted(branch_names, reverse=True)[0]
237
247
@@ -247,37 +257,20 @@ def fix_version_from_branch(branch, versions):
247
257
pr_repo_desc = "%s/%s" % (user_login , base_ref )
248
258
249
259
if pr ["merged" ] is True :
250
- print ("Pull request {0} has already been merged, assuming "
251
- "you want to backport" .format (pr_num ))
252
- merge_commit_desc = run_cmd ([
253
- 'git' , 'log' , '--merges' , '--first-parent' ,
254
- '--grep=pull request #%s' % pr_num , '--oneline' ]).split ("\n " )[0 ]
255
- if merge_commit_desc == "" :
256
- fail ("Couldn't find any merge commit for #{0}"
257
- ", you may need to update HEAD." .format (pr_num ))
258
-
259
- merge_hash = merge_commit_desc [:7 ]
260
- message = merge_commit_desc [8 :]
261
-
262
- print ("Found: %s" % message )
263
- maybe_cherry_pick (pr_num , merge_hash , latest_branch )
260
+ print ("Pull request {0} has already been merged, please backport manually"
261
+ .format (pr_num ))
264
262
sys .exit (0 )
265
263
266
264
if not bool (pr ["mergeable" ]):
267
265
msg = ("Pull request {0} is not mergeable in its current form.\n "
268
266
"Continue? (experts only!)" .format (pr_num ))
269
267
continue_maybe (msg )
270
268
271
- print ("\n === Pull Request #%s ===" % pr_num )
272
- print ("title\t %s\n source\t %s\n target\t %s\n url\t %s" % (
273
- title , pr_repo_desc , target_ref , url ))
269
+ print ("\n === Pull Request #%s ===" % pr_num )
270
+ print ("title\t %s\n source\t %s\n target\t %s\n url\t %s"
271
+ % ( title , pr_repo_desc , target_ref , url ))
274
272
continue_maybe ("Proceed with merging pull request #%s?" % pr_num )
275
273
276
274
merged_refs = [target_ref ]
277
275
278
276
merge_hash = merge_pr (pr_num , target_ref )
279
-
280
- pick_prompt = "Would you like to pick %s into another branch?" % merge_hash
281
- while raw_input ("\n %s (y/n): " % pick_prompt ).lower () == "y" :
282
- merged_refs = merged_refs + [cherry_pick (pr_num , merge_hash ,
283
- latest_branch )]
0 commit comments