Skip to content

Import manually: No branches available for newly created project #9369

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

Closed
benjaoming opened this issue Jun 22, 2022 · 27 comments
Closed

Import manually: No branches available for newly created project #9369

benjaoming opened this issue Jun 22, 2022 · 27 comments
Labels
Accepted Accepted issue on our roadmap Bug A bug

Comments

@benjaoming
Copy link
Contributor

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

image

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 🥶

@benjaoming benjaoming added the Bug A bug label Jun 22, 2022
@stsewd
Copy link
Member

stsewd commented Jun 22, 2022

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.

@natefoo
Copy link

natefoo commented Jul 13, 2022

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.

@stsewd
Copy link
Member

stsewd commented Jul 13, 2022

@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)

@natefoo
Copy link

natefoo commented Jul 13, 2022

@stsewd that worked, thanks!

@humitos humitos added the Accepted Accepted issue on our roadmap label Jul 14, 2022
@showierdata9978
Copy link

You could add a way to edit the branch added when you import manually (after the project is done)

@benjaoming
Copy link
Contributor Author

@showierdata9978 you can consider the workaround above ⬆️

@showierdata9978
Copy link

@showierdata9978 you can consider the workaround above ⬆️

ye, IK i just said that as a possible fix!

@benjaoming
Copy link
Contributor Author

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.

@showierdata9978
Copy link

maybe on import you could check if that branch exists, and if not show an error

@showierdata9978
Copy link

im trying to find the page for manual import, your codebase is just so dang huge

@showierdata9978
Copy link

i need to find where the user inputs the default branch, and check if that branch exists on the VCS

@showierdata9978
Copy link

the amount of tabs i opened to find everything tho....

image

@benjaoming
Copy link
Contributor Author

@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

@showierdata9978
Copy link

showierdata9978 commented Dec 16, 2022 via email

@showierdata9978
Copy link

showierdata9978 commented Dec 16, 2022

Where is the options attribute truly defined I would be able to make a fix if I knew that

(The html specifically)

@showierdata9978
Copy link

showierdata9978 commented Dec 16, 2022

Note: a quick fix is to just git clone, without a selected branch, then do git branch and show that to the user

@benjaoming
Copy link
Contributor Author

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.

@showierdata9978
Copy link

showierdata9978 commented Dec 16, 2022 via email

@showierdata9978
Copy link

why was this not used for validaion in the first place?

def lsremote(self, include_tags=True, include_branches=True):

@showierdata9978
Copy link

showierdata9978 commented Dec 16, 2022

found where it needs to be addedd

def post(self, request, *args, **kwargs):
initial_data = {}
initial_data['basics'] = {}
for key in ['name', 'repo', 'repo_type', 'remote_repository', 'default_branch']:
initial_data['basics'][key] = request.POST.get(key)
initial_data['extra'] = {}
for key in ['description', 'project_url']:
initial_data['extra'][key] = request.POST.get(key)
request.method = 'GET'
return self.wizard_class.as_view(initial_dict=initial_data)(request)

@showierdata9978
Copy link

also just found this file, it could work as a spot to put the validator

readthedocs/projects/validators.py

@showierdata9978
Copy link

ah, danget i cant use in because of the class VCSVersion

@showierdata9978
Copy link

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

@benjaoming
Copy link
Contributor Author

@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
Copy link

showierdata9978 commented Dec 16, 2022

@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

@humitos
Copy link
Member

humitos commented Jan 31, 2023

This issue was solved by #9424 and it's going to be deployed today.

@humitos humitos closed this as completed Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Accepted issue on our roadmap Bug A bug
Projects
None yet
Development

No branches or pull requests

5 participants