readthedocs.org
readthedocs.org copied to clipboard
Import manually: No branches available for newly created project
Details
If we create a new project, there are no branches immediately visible. This means that it isn't possible for the user to change the value of "Default branch" after creating a new project with a blank default branch -- which fails as described in #9367

- Read the Docs project URL: https://readthedocs.org/projects/example-sphinx-basic/
- Build URL (if applicable): https://readthedocs.org/projects/example-sphinx-basic/builds/17248339/
- Read the Docs username (if applicable): https://readthedocs.org/profiles/benjaoming/
Expected Result
A list of all branch names from public Github project should appear immediately when importing new projects manually.
Actual Result
No branch names :cold_face:
This happens since the repo doesn't have a branch named master, and it was imported manually. The sync of branches/tags happens after doing the clone/checkout, we could do the sync before doing the checkout, or do it if the checkout fails.
Is there a workaround for this issue other than deleting the project and starting over (and setting the branch name this time)? It seems like #9424 is probably a fix, but I don't know when that will be live.
@natefoo you can create a temporal branch named master, after that all the versions should appear (if they don't, try triggering a build for master)
@stsewd that worked, thanks!
You could add a way to edit the branch added when you import manually (after the project is done)
@showierdata9978 you can consider the workaround above :arrow_up:
@showierdata9978 you can consider the workaround above ⬆️
ye, IK i just said that as a possible fix!
The underlying issue is that the empty dropdown is supposed to show a list of valid branches. But the list isn't populated when the initial default branch is unset and doesn't match master.
maybe on import you could check if that branch exists, and if not show an error
im trying to find the page for manual import, your codebase is just so dang huge
found the js file
https://github.com/readthedocs/readthedocs.org/blob/43ee207ccb2315cda89114ef37f184163836fc66/readthedocs/projects/static-src/projects/js/import.js
i need to find where the user inputs the default branch, and check if that branch exists on the VCS
the amount of tabs i opened to find everything tho....

@showierdata9978 YES! The codebase for Read the Docs is a big one and is based on a decade of careful crafting and fiffling by a lot of people, so you are always welcome to ask questions.
Are you looking for a way to automatically fill in the branch name? I think that the approach taken has been to discover the default branch after creating the project if the branch name is left empty.
However, since the default branch name isn't discovered correctly, this approach fails. To fix it, I think that #9424 needs to move forwards.
@humitos would it be correct to assume that this issue will also be fixed by #9424?
Let's note in any case that this issue is closely related to #9367
I was thinking of checking with the vcs provider to check if the branch exists
On Fri, Dec 16, 2022, 8:44 AM Benjamin Balder Bach @.***> wrote:
@showierdata9978 https://github.com/showierdata9978 YES! The codebase for Read the Docs is a big one and is based on a decade of careful crafting and fiffling by a lot of people, so you are always welcome to ask questions.
Are you looking for a way to automatically fill in the branch name? I think that the approach taken has been to discover the default branch after creating the project if the branch name is left empty.
However, since the default branch name isn't discovered correctly, this approach fails. To fix it, I think that #9424 https://github.com/readthedocs/readthedocs.org/pull/9424 needs to move forwards.
@humitos https://github.com/humitos would it be correct to assume that this issue will also be fixed by #9424 https://github.com/readthedocs/readthedocs.org/pull/9424?
Let's note in any case that this issue is closely related to #9367 https://github.com/readthedocs/readthedocs.org/issues/9367
— Reply to this email directly, view it on GitHub https://github.com/readthedocs/readthedocs.org/issues/9369#issuecomment-1354969463, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQHW4P6CRYMOGUKF4ZHVTW3WNR53TANCNFSM5ZQJ3VGA . You are receiving this because you were mentioned.Message ID: @.***>
Where is the options attribute truly defined I would be able to make a fix if I knew that
(The html specifically)
Note: a quick fix is to just git clone, without a selected branch, then do git branch and show that to the user
I think it sounds good to think of this as input validation. If a branch is specified, verify that it exists. If no branch is specified, automatically use the default branch.
In any case, VCS actions have to happen server-side. I'm not sure if JS is relevant here, couldn't this be handled entirely in form validation?
Using git clone --depth 1 and then this method to get the default branch might work.
Ye, it could, js is relevant so I can trace it back lol
On Fri, Dec 16, 2022, 9:06 AM Benjamin Balder Bach @.***> wrote:
I think it sounds good to think of this as input validation. If a branch is specified, verify that it exists. If no branch is specified, automatically use the default branch.
In any case, VCS actions have to happen server-side. I'm not sure if JS is relevant here, couldn't this be handled entirely in form validation?
Using git clone --depth 1 and then this method https://github.com/readthedocs/readthedocs.org/issues/9367#issuecomment-1209204921 to get the default branch might work.
— Reply to this email directly, view it on GitHub https://github.com/readthedocs/readthedocs.org/issues/9369#issuecomment-1355026055, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQHW4P37O3FSAORJQDTMJCTWNSAORANCNFSM5ZQJ3VGA . You are receiving this because you were mentioned.Message ID: @.***>
why was this not used for validaion in the first place?
https://github.com/readthedocs/readthedocs.org/blob/af0d328db4f1b59648340640ebdeb9dd0cd12ed4/readthedocs/vcs_support/backends/git.py#L205
found where it needs to be addedd
https://github.com/readthedocs/readthedocs.org/blob/af0d328db4f1b59648340640ebdeb9dd0cd12ed4/readthedocs/projects/views/private.py#L398-L407
also just found this file, it could work as a spot to put the validator
readthedocs/projects/validators.py
ah, danget i cant use in because of the class VCSVersion
came up with this
def __call__(self, vcs ,fourm):
branch = fourm.fields['default_branch']
project_url = fourm.fields['project_url']
branches = vcs.branches
# Cant optimise this as vcs.branches returns list[VCSVersion]
branch_exists = False
for remote_branch in branches:
if branch == remote_branch.verbose_name:
branch_exists = True
break
if not branch_exists:
raise ValidationError("Default branch not found in VCS")
return
@showierdata9978 are you able to test your approach in a development environment? There is information available here: https://dev.readthedocs.io/en/latest/install.html
@showierdata9978 are you able to test your approach in a development environment? There is information available here: https://dev.readthedocs.io/en/latest/install.html
i am not, i will be able to in ~2 hours as im not at home right now
This issue was solved by https://github.com/readthedocs/readthedocs.org/pull/9424 and it's going to be deployed today.