lafiona commented on code in PR #14033:
URL: https://github.com/apache/arrow/pull/14033#discussion_r993778812
##########
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:
Although the code in both classes perform the same functions, they are not
using the same Git libraries. While `dev/arhcery/archery/crossbow/core.py` uses
`pygit2`, `dev/archery/archery/release/core.py` uses `GitPython`. The `Repo`
class that is used in each module are also not shared.
In an effort to limit dependencies, I wrote the code to work with the
libraries that were already being imported.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]