raulcd commented on code in PR #14533:
URL: https://github.com/apache/arrow/pull/14533#discussion_r1065482420


##########
dev/merge_arrow_pr.py:
##########
@@ -110,10 +111,33 @@ def strip_ci_directives(commit_message):
     return _REGEX_CI_DIRECTIVE.sub('', commit_message)
 
 
+def git_default_branch_name():
+    default_branch_name = os.getenv("MERGE_SCRIPT_DEFAULT_BRANCH_NAME")
+
+    if default_branch_name is None:
+        try:
+            default_reference = run_cmd(
+                "git rev-parse --abbrev-ref origin/HEAD")
+            default_branch_name = default_reference.lstrip("origin/")
+            default_branch_name = default_branch_name.rstrip()
+        except subprocess.CalledProcessError:
+            # TODO: ARROW-18011 to track changing the hard coded default
+            # value from "master" to "main".
+            default_branch_name = "master"
+            warnings.warn('Unable to determine default branch name: '
+                          'MERGE_SCRIPT_DEFAULT_BRANCH_NAME environment '
+                          'variable is not set. Git repository does not '
+                          'contain a \'refs/remotes/origin/HEAD\'reference. '
+                          ' Setting the default branch name to ' +
+                          default_branch_name, RuntimeWarning)
+
+    return default_branch_name
+
+
 def fix_version_from_branch(branch, versions):
     # Note: Assumes this is a sorted (newest->oldest) list of un-released
     # versions
-    if branch == "master":
+    if branch == git_default_branch_name():
         return versions[-1]
     else:

Review Comment:
   I think this else is never executed because we never call 
`get_candidate_fix_version` with `merge_branches`. We always use the default 
`('master',)`. We could simplify the script to just `return versions[-1]` on 
this function and remove all the logic based on the branch.
   The merge script uses the GitHub API and that will already point the PR to 
the correct default branch.
   We don't use branches prefixed `branch-`. This code is 7 years old so it is 
probably a left over from an old workflow.



-- 
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.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

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

Reply via email to