You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/12 12:12:31 UTC

[GitHub] [arrow] pitrou commented on a diff in pull request #14033: ARROW-15691: [Dev] Update archery to work with either master or main as default branch

pitrou commented on code in PR #14033:
URL: https://github.com/apache/arrow/pull/14033#discussion_r993371623


##########
dev/archery/archery/crossbow/core.py:
##########
@@ -361,6 +361,24 @@ def signature(self):
         return pygit2.Signature(self.user_name, self.user_email,
                                 int(time.time()))
 
+    @property
+    def default_branch_name(self):
+        default_branch_name = os.getenv("DEFAULT_BRANCH")

Review Comment:
   Hmm... doesn't this environment variable risk clashing with other utilities using the same variable name?
   Ideally we don't need an environment variable, or we can make it more specific (for example `ARCHERY_DEFAULT_BRANCH`).



##########
dev/archery/archery/crossbow/core.py:
##########
@@ -361,6 +361,24 @@ def signature(self):
         return pygit2.Signature(self.user_name, self.user_email,
                                 int(time.time()))
 
+    @property
+    def default_branch_name(self):
+        default_branch_name = os.getenv("DEFAULT_BRANCH")
+
+        if default_branch_name is None:
+            try:
+                ref_obj = self.repo.references["refs/remotes/origin/HEAD"]
+                target_name = ref_obj.target
+                target_name_tokenized = target_name.split("/")
+                default_branch_name = target_name_tokenized[-1]
+            except KeyError:
+                raise RuntimeError(
+                    'Unable to determine default branch name: DEFAULT_BRANCH '
+                    'environment variable is not set. Git repository does not '
+                    'contain a \'refs/remotes/origin/HEAD\' reference.')

Review Comment:
   Well... can we instead default to "master" for the time being?



##########
dev/archery/archery/release/core.py:
##########
@@ -361,6 +362,40 @@ def commits(self):
         commit_range = f"{lower}..{upper}"
         return list(map(Commit, self.repo.iter_commits(commit_range)))
 
+    @cached_property
+    def default_branch(self):
+        default_branch_name = os.getenv("DEFAULT_BRANCH")
+
+        if default_branch_name is None:
+            try:
+                # Set up repo object
+                arrow = ArrowSources.find()
+                repo = Repo(arrow.path)
+                origin = repo.remotes["origin"]
+                origin_refs = origin.refs
+
+                # Get git.RemoteReference object to origin/HEAD
+                origin_head = origin_refs["HEAD"]
+
+                # Get git.RemoteReference object to origin/main or
+                # origin/master
+                origin_head_reference = origin_head.reference
+
+                # Get string value of remote head reference, should return
+                # "origin/main" or "origin/master"
+                origin_head_name = origin_head_reference.name
+                origin_head_name_tokenized = origin_head_name.split("/")
+
+                # The last token is the default branch name
+                default_branch_name = origin_head_name_tokenized[-1]

Review Comment:
   This is roughly the same logic in as `dev/archery/archery/crossbow/core.py`, right? 
   Perhaps factor it out in the `Repository` class?



##########
dev/archery/archery/crossbow/cli.py:
##########
@@ -156,8 +156,13 @@ def submit(obj, tasks, groups, params, job_prefix, config_path, arrow_version,
         click.echo('Pushed job identifier is: `{}`'.format(job.branch))
 
 
+# Get the default branch name from the repository
+arrow_source_dir = ArrowSources.find()
+repo = Repo(arrow_source_dir.path)

Review Comment:
   Can we avoid doing this at module import?



##########
dev/archery/archery/release/core.py:
##########
@@ -22,6 +22,7 @@
 import pathlib
 import shelve
 import warnings
+import os

Review Comment:
   Please let's keep stdlib imports alphabetically ordered.



-- 
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-unsubscribe@arrow.apache.org

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