Skip to content

Apache DataFusion SQL Query Engine

ARROW-6178: [Developer] Keep prompting for authors in merge script for multi-author PRs if given bad input

Wes McKinneye01575c1cb59
diff --git a/dev/merge_arrow_pr.py b/dev/merge_arrow_pr.py
index 37d7fa8a77..f37dbf78f7 100755
--- a/dev/merge_arrow_pr.py
+++ b/dev/merge_arrow_pr.py
@@ -354,18 +354,8 @@ class PullRequest(object):
print("Author {}: {}".format(i + 1, author))
if len(distinct_authors) > 1:
- primary_author = self.cmd.prompt(
- "Enter primary author in the format of "
- "\"name <email>\" [%s]: " % distinct_authors[0])
-
- if primary_author == "":
- primary_author = distinct_authors[0]
- else:
- # When primary author is specified manually, de-dup it from
- # author list and put it at the head of author list.
- distinct_authors = [x for x in distinct_authors
- if x != primary_author]
- distinct_authors = [primary_author] + distinct_authors
+ primary_author, distinct_authors = get_primary_author(
+ self.cmd, distinct_authors)
else:
# If there is only one author, do not prompt for a lead author
primary_author = distinct_authors[0]
@@ -441,6 +431,29 @@ class PullRequest(object):
return merge_hash
+def get_primary_author(cmd, distinct_authors):
+ author_pat = re.compile(r'(.*) <(.*)>')
+
+ while True:
+ primary_author = cmd.prompt(
+ "Enter primary author in the format of "
+ "\"name <email>\" [%s]: " % distinct_authors[0])
+
+ if primary_author == "":
+ return primary_author, distinct_authors
+
+ if author_pat.match(primary_author):
+ break
+ print('Bad author "{}", please try again'.format(primary_author))
+
+ # When primary author is specified manually, de-dup it from
+ # author list and put it at the head of author list.
+ distinct_authors = [x for x in distinct_authors
+ if x != primary_author]
+ distinct_authors = [primary_author] + distinct_authors
+ return primary_author, distinct_authors
+
+
def prompt_for_fix_version(cmd, jira_issue):
(all_versions,
default_fix_versions) = jira_issue.get_candidate_fix_versions()
diff --git a/dev/test_merge_arrow_pr.py b/dev/test_merge_arrow_pr.py
index f97331a09d..2f940fa305 100644
--- a/dev/test_merge_arrow_pr.py
+++ b/dev/test_merge_arrow_pr.py
@@ -182,6 +182,25 @@ def test_jira_resolve_released_fix_version():
assert fix_versions_json == [RAW_VERSION_JSON[-1]]
+def test_multiple_authors_bad_input():
+ a0 = 'Jimbob Crawfish <[email protected]>'
+ a1 = 'Jarvis McCratchett <[email protected]>'
+ a2 = 'Hank Miller <[email protected]>'
+ distinct_authors = [a0, a1]
+
+ cmd = FakeCLI(responses=['oops', a1])
+ primary_author, new_distinct_authors = merge_arrow_pr.get_primary_author(
+ cmd, distinct_authors)
+ assert primary_author == a1
+ assert new_distinct_authors == [a1, a0]
+
+ cmd = FakeCLI(responses=[a2])
+ primary_author, new_distinct_authors = merge_arrow_pr.get_primary_author(
+ cmd, distinct_authors)
+ assert primary_author == a2
+ assert new_distinct_authors == [a2, a0, a1]
+
+
def test_jira_already_resolved():
status = FakeStatus('Resolved')
fields = FakeFields(status, 'issue summary', FakeAssignee('groundhog'),