kou commented on a change in pull request #9598:
URL: https://github.com/apache/arrow/pull/9598#discussion_r584360440



##########
File path: dev/merge_arrow_pr.py
##########
@@ -547,6 +566,86 @@ def get_pr_num():
     return input("Which pull request would you like to merge? (e.g. 34): ")
 
 
+_JIRA_COMPONENT_REGEX = re.compile(r'(\[[^\]]*\])+')
+
+# Maps PR title prefixes to JIRA components
+PR_COMPONENTS_TO_JIRA_COMPONENTS = {
+    '[Rust]': 'Rust',
+    '[Rust][DataFusion]': 'Rust - DataFusion',
+    '[C++]': 'C++',
+    '[R]': 'R',
+}
+
+
+# Return the best matching JIRA component from a PR title, if any
+# "[Rust] Fix something" --> Rust
+# "[Rust][DataFusion] Fix" --> Rust - DataFusion
+# "[CPP] Fix " --> "C++"
+def jira_component_name_from_title(title):
+    match = _JIRA_COMPONENT_REGEX.match(title.strip())
+    if match:
+        pr_component = str(match.group(0))
+        return PR_COMPONENTS_TO_JIRA_COMPONENTS.get(pr_component)
+
+
+# If no jira ID can be found for the PR, offer to create one
+# returns returns the github pr_data
+def make_auto_jira(github_api, jira_con, cmd, pr_num):
+    pr_data = github_api.get_pr_data(pr_num)
+
+    try:
+        title = pr_data["title"]
+        html_link = pr_data["_links"]["html"]["href"]
+    except KeyError:
+        pprint.pprint(pr_data)
+        raise
+
+    # had valid JIRA already
+    if get_jira_id(title)[0]:
+        return pr_data
+
+    print("No JIRA link found for PR", pr_num)
+    options = ' or '.join('{0}-XXX'.format(project)
+                          for project in SUPPORTED_PROJECTS)
+    print("  Looked for PR title prefixed by {}".format(options))
+
+    # try to make a JIRA issue in the ARROW project with a
+    # component extracted from the PR title
+    component = jira_component_name_from_title(title)
+
+    if not component:
+        print("  Could not determine component from title")
+        print("  Expected '[Component] description', found '{}'".format(title))
+        print("  Known components: {}".format(
+            ", ".join(PR_COMPONENTS_TO_JIRA_COMPONENTS)))
+        return pr_data
+
+    components = [{"name": component}]
+    summary = "{}".format(title)
+
+    print("=== NEW JIRA ===")
+    print("Summary\t\t{}".format(summary))
+    print("Assignee\tNONE")
+    print("Components\t{}".format(component))
+    print("Status\t\tNew")
+    description = ("Issue automatically created " +

Review comment:
       How about using the pull request description as is?

##########
File path: dev/merge_arrow_pr.py
##########
@@ -547,6 +566,86 @@ def get_pr_num():
     return input("Which pull request would you like to merge? (e.g. 34): ")
 
 
+_JIRA_COMPONENT_REGEX = re.compile(r'(\[[^\]]*\])+')
+
+# Maps PR title prefixes to JIRA components
+PR_COMPONENTS_TO_JIRA_COMPONENTS = {
+    '[Rust]': 'Rust',
+    '[Rust][DataFusion]': 'Rust - DataFusion',
+    '[C++]': 'C++',
+    '[R]': 'R',
+}
+
+
+# Return the best matching JIRA component from a PR title, if any
+# "[Rust] Fix something" --> Rust
+# "[Rust][DataFusion] Fix" --> Rust - DataFusion
+# "[CPP] Fix " --> "C++"

Review comment:
       ```suggestion
   # "[C++] Fix " --> "C++"
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to