Skip to content

Commit a0595a3

Browse files
committed
Trim backporting/charry-picking cruft likely not needed for pandas
1 parent 1a64c86 commit a0595a3

File tree

1 file changed

+30
-37
lines changed

1 file changed

+30
-37
lines changed

scripts/merge-py.py

+30-37
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
# limitations under the License.
1818
#
1919

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.
2122
# usage: ./apache-pr-merge.py (see config env vars below)
2223
#
2324
# Lightly modified from version of this script in incubator-parquet-format
@@ -121,33 +122,39 @@ def clean_up():
121122
# merge the requested PR and return the merge hash
122123
def merge_pr(pr_num, target_ref):
123124
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))
127131
run_cmd("git checkout %s" % target_branch_name)
128132

129133
had_conflicts = False
130134
try:
131135
run_cmd(['git', 'merge', pr_branch_name, '--squash'])
132136
except Exception as e:
133-
msg = "Error merging: %s\nWould you like to manually fix-up this merge?" % e
137+
msg = ("Error merging: %s\nWould you like to manually fix-up "
138+
"this merge?" % e)
134139
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?")
136142
continue_maybe(msg)
137143
had_conflicts = True
138144

139145
commit_authors = run_cmd(['git', 'log', 'HEAD..%s' % pr_branch_name,
140146
'--pretty=format:%an <%ae>']).split("\n")
141147
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)
143150
primary_author = distinct_authors[0]
144151
commits = run_cmd(['git', 'log', 'HEAD..%s' % pr_branch_name,
145152
'--pretty=format:%h [%an] %s']).split("\n\n")
146153

147154
merge_message_flags = []
148155

149156
merge_message_flags += ["-m", title]
150-
if body != None:
157+
if body is not None:
151158
merge_message_flags += ["-m", '\n'.join(textwrap.wrap(body))]
152159

153160
authors = "\n".join(["Author: %s" % a for a in distinct_authors])
@@ -157,14 +164,17 @@ def merge_pr(pr_num, target_ref):
157164
if had_conflicts:
158165
committer_name = run_cmd("git config --get user.name").strip()
159166
committer_email = run_cmd("git config --get user.email").strip()
160-
message = "This patch had conflicts when merged, resolved by\nCommitter: %s <%s>" % (
161-
committer_name, committer_email)
167+
message = ("This patch had conflicts when merged, "
168+
"resolved by\nCommitter: %s <%s>"
169+
% (committer_name, committer_email))
162170
merge_message_flags += ["-m", message]
163171

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
165174
merge_message_flags += [
166175
"-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)]
168178
for c in commits:
169179
merge_message_flags += ["-m", c]
170180

@@ -229,9 +239,9 @@ def fix_version_from_branch(branch, versions):
229239
return filter(lambda x: x.name.startswith(branch_ver), versions)[-1]
230240

231241

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])
235245
# Assumes branch names can be sorted lexicographically
236246
# latest_branch = sorted(branch_names, reverse=True)[0]
237247

@@ -247,37 +257,20 @@ def fix_version_from_branch(branch, versions):
247257
pr_repo_desc = "%s/%s" % (user_login, base_ref)
248258

249259
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))
264262
sys.exit(0)
265263

266264
if not bool(pr["mergeable"]):
267265
msg = ("Pull request {0} is not mergeable in its current form.\n"
268266
"Continue? (experts only!)".format(pr_num))
269267
continue_maybe(msg)
270268

271-
print ("\n=== Pull Request #%s ===" % pr_num)
272-
print ("title\t%s\nsource\t%s\ntarget\t%s\nurl\t%s" % (
273-
title, pr_repo_desc, target_ref, url))
269+
print("\n=== Pull Request #%s ===" % pr_num)
270+
print("title\t%s\nsource\t%s\ntarget\t%s\nurl\t%s"
271+
% (title, pr_repo_desc, target_ref, url))
274272
continue_maybe("Proceed with merging pull request #%s?" % pr_num)
275273

276274
merged_refs = [target_ref]
277275

278276
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

Comments
 (0)