-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Build: better support for empty default branch #12462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 13 commits
dbae5b4
0074e5e
24854de
9572098
082b1be
77ae232
f636eb9
8701e3c
9903db6
335fff8
c7e0087
c9e7138
1723c27
68b4405
722617c
a3374b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1177,15 +1177,21 @@ def get_original_latest_version(self): | |
When latest is machine created, it's basically an alias | ||
for the default branch/tag (like main/master), | ||
|
||
Returns None if the current default version doesn't point to a valid version. | ||
Returns None if latest doesn't point to a valid version, | ||
or if isn't managed by RTD (machine=False). | ||
""" | ||
default_version_name = self.get_default_branch() | ||
# For latest, the identifier is the name of the branch/tag. | ||
latest_version_identifier = ( | ||
self.versions.filter(slug=LATEST, machine=True) | ||
.values_list("identifier", flat=True) | ||
.first() | ||
) | ||
if not latest_version_identifier: | ||
return None | ||
return ( | ||
self.versions(manager=INTERNAL) | ||
.exclude(slug=LATEST) | ||
.filter( | ||
verbose_name=default_version_name, | ||
) | ||
.filter(verbose_name=latest_version_identifier) | ||
.first() | ||
) | ||
|
||
|
@@ -1203,8 +1209,22 @@ def update_latest_version(self): | |
return | ||
|
||
# default_branch can be a tag or a branch name! | ||
default_version_name = self.get_default_branch() | ||
original_latest = self.get_original_latest_version() | ||
default_version_name = self.get_default_branch(fallback_to_vcs=False) | ||
# If the default_branch is not set, it means that the user | ||
# wants to use the default branch of the respository, but | ||
# we don't know what that is here, `latest` will be updated | ||
# on the next build. | ||
if not default_version_name: | ||
return | ||
|
||
# Search for a branch or tag with the name of the default branch, | ||
# so we can sync latest with it. | ||
original_latest = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems we updated There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, they are slightly different. One gets the version matching the value of the current LATEST, while the other tries to get the version matching the value of |
||
self.versions(manager=INTERNAL) | ||
.exclude(slug=LATEST) | ||
.filter(verbose_name=default_version_name) | ||
.first() | ||
) | ||
latest.verbose_name = LATEST_VERBOSE_NAME | ||
latest.type = original_latest.type if original_latest else BRANCH | ||
# For latest, the identifier is the name of the branch/tag. | ||
|
@@ -1304,14 +1324,22 @@ def get_default_version(self): | |
return self.default_version | ||
return LATEST | ||
|
||
def get_default_branch(self): | ||
"""Get the version representing 'latest'.""" | ||
def get_default_branch(self, fallback_to_vcs=True): | ||
""" | ||
Get the name of the branch or tag that the user wants to use as 'latest'. | ||
|
||
In case the user explicitly set a default branch, we use that, | ||
otherwise we try to get it from the remote repository. | ||
""" | ||
if self.default_branch: | ||
return self.default_branch | ||
|
||
if self.remote_repository and self.remote_repository.default_branch: | ||
return self.remote_repository.default_branch | ||
|
||
if not fallback_to_vcs: | ||
return None | ||
|
||
vcs_class = self.vcs_class() | ||
if vcs_class: | ||
return vcs_class.fallback_branch | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is introducing an extra query for each time latest is returned in a response, since we now rely on latest having the correct value of the default branch (similar to get_original_stable_version).