Feature: GitHub autofork url#4704
Conversation
1ee8773 to
05aef3d
Compare
Job #9890: Bundle Size — 62.25MiB (~+0.01%).
Warning Bundle contains 66 duplicate packages – View duplicate packages Bundle metrics
Bundle size by type
View job #9890 report View feature/github-fork-url branch activity |
| const githubBranch = urlParams.get('github_branch') | ||
| const importURL = urlParams.get('import_url') | ||
|
|
||
| const githubRepoObj: GithubRepo | null = (() => { |
There was a problem hiding this comment.
Could this just be turned into a regular function and have it be invoked here? Feels like a lot of URL handling logic all embedded within the Editor component.
There was a problem hiding this comment.
yeah very good point, it's became too massive
| startGithubAuthentication: startGithubAuthentication, | ||
| } as const | ||
|
|
||
| export function useOnClickAuthenticateWithGithub() { |
There was a problem hiding this comment.
should this live in a separate .tsx file?
There was a problem hiding this comment.
do you have a problem with the current location other than it's a ts file?
| 'branches', | ||
| githubRepo.owner, | ||
| githubRepo.repository, | ||
| 'default-branch', |
There was a problem hiding this comment.
shall we stick with GH's (unchanged) default here? (main)
There was a problem hiding this comment.
I'm not sure what you mean. if you say we can assume the default branch is main, that's wrong.
|
|
||
| function createStoryboardFileWithPlaceholderContents( | ||
| projectContents: ProjectContentTreeRoot, | ||
| isItNecessary: 'create-placeholder' | 'skip-creating-placeholder', |
There was a problem hiding this comment.
Be nice to extract this into a type definition as it appears to be in at least 2 places.
There was a problem hiding this comment.
Also isItNecessary is a bad name. shouldCreatePlaceholder or just createPlaceholder would be better
There was a problem hiding this comment.
I did the renaming, I did not create a type definition though because I think this is more readable. we should talk about it in the chat if you disagree :)
| }), | ||
| ]) | ||
|
|
||
| // TODO make sure the EditorState knows we have a github repo connected!!! |
There was a problem hiding this comment.
yep, for the test I will write
| return null | ||
| }) | ||
|
|
||
| const awaitLoadActionDispatchedByPersistenceMachine = (): Promise<{ projectId: string }> => { |
There was a problem hiding this comment.
Can this be a regular function?
|
|
||
| export const DefaultPackageJson = { | ||
| name: 'Utopia Project', | ||
| name: 'utopia-project', |
There was a problem hiding this comment.
somewhat unrelated mini fix
| githubRepo: GithubRepoWithBranch, | ||
| ) { | ||
| if (didWeInitiateGitRepoDownloadSinceTheEditorLoaded) { | ||
| return |
There was a problem hiding this comment.
Should this throw an error instead? This feels like something that shouldn't fail silently
There was a problem hiding this comment.
this function gets called a couple of times because of ancestor remounts, maybe I should put a comment here


Verbose URL
https://utopia.pizza/p/?github_owner=balazsbajorics&github_repo=hydrogen-november&github_branch=mainShorter URL
https://utopia.pizza/p/?clone=balazsbajorics/hydrogen-novemberShorter URL with branch name
https://utopia.pizza/p/?clone=balazsbajorics/hydrogen-november&github_branch=mainTry Me link:
Verbose URL link
Problem
The only (maintained, aside from the old zip-based repo checkout POC) working method for cloning a github repository was to create a new project, navigate to the github tab, then insert the owner / repo name, select a branch, press clone, overwrite contents of the new project.
We already had a URL-based entry point for the git checkout proof of concept which was cloning a git repo using a zip download. To my surprise it still works today, but it doesn't do the asset upload step, and does not connect the editor's github tab to the cloned repository. Plus I couldn't remember what other limitations it might have, so Balazs 2023 December decided to not spend time trying to understand if we should fix that instead of using the main github cloning feature.
What did I do
So I set out to replace the existing git auto-clone functionality with our "modern" and maintained github integration. I went down a bit of a dead end in #4660 and yesterday I decided to scrap most of my changes and come up with a vastly simplified solution.
Basically what this PR ended up doing is that it still does load (an empty) project, and then calls the same code path that runs when a user selects a repository in the github tab.
Flow of cloning a repo:
The flow is orchestrated from
GithubRepositoryCloneFlowwhich is a react component in editor-component. This is currently our only loading flow which is not directly orchestrated from editor.tsx.cloneGithubRepo3.
cloneGithubRepocreates a new totally empty project that only has a package.json. It firesPersistenceMachine.createNewso we get a proper Project ID, then saves this empty project to the serverLOADaction being dispatched to avoid race conditionsGithubOperations.updateProjectWithBranchContent(that's the exact same code path that is called if the user clicks "Load from Branch" in the github pane)Changes to the Server
Parallel to my editor changes, I also added a new server endpoint: the ability to clone a repo without specifying a branch. Since the default branch of git repos can be arbitrarily named, the server code first figures out the default repo branch name, and then calls the existing load-a-branch code path.
Not logged in states


If the user is not logged in, or not authenticated with github, we stop the flow and wait for their action.