importing github project in offline app#11208
Conversation
There was a problem hiding this comment.
Pull request overview
Enables importing GitHub-backed projects even when the GitHub editor UI is disabled (e.g., offline app / Electron), by proceeding with the import and stripping GitHub metadata before loading the project.
Changes:
- Removes the early “GitHub import not supported” guard and introduces a
githubEnabledflag. - Skips forced GitHub sign-in when GitHub UI is disabled.
- Attempts to scrub GitHub metadata from the imported header before loading.
| if (!githubEnabled) { | ||
| hd.githubId = undefined; | ||
| hd.githubTag = undefined; | ||
| hd.githubCurrent = false; |
There was a problem hiding this comment.
Clearing hd.githubId/githubTag/githubCurrent here is likely not enough to “scrap” GitHub info: during loadHeaderAsync, pkg.loadPkgAsync triggers workspace.recomputeHeaderFlagsAsync, which re-populates these fields from pxt.github.GIT_JSON (git.json) in the project files. This means the project may still be treated as a GitHub project (e.g., Save/Rename UI suppressed) even when githubEnabled is false. Consider removing the git.json file from the imported project (and persisting the updated header/files via workspace.saveAsync) when GitHub is disabled, or otherwise preventing recomputeHeaderFlagsAsync from rehydrating GitHub metadata for this import path.
| if (!githubEnabled) { | |
| hd.githubId = undefined; | |
| hd.githubTag = undefined; | |
| hd.githubCurrent = false; | |
| if (!githubEnabled) { | |
| // Scrub GitHub metadata from the header | |
| hd.githubId = undefined; | |
| hd.githubTag = undefined; | |
| hd.githubCurrent = false; | |
| // Also remove git.json from the project files so that | |
| // workspace.recomputeHeaderFlagsAsync cannot rehydrate | |
| // GitHub metadata from disk when the header is loaded. | |
| try { | |
| const files: pxt.workspace.ScriptText = await workspace.getTextAsync(hd.id); | |
| if (files && files[pxt.github.GIT_JSON]) { | |
| delete files[pxt.github.GIT_JSON]; | |
| await workspace.saveAsync(hd, files); | |
| } | |
| } catch (err) { | |
| // Failing to scrub git.json should not prevent the project from loading. | |
| // Log the error for diagnostics and continue. | |
| console.error("Failed to remove git.json for imported GitHub project when GitHub is disabled", err); | |
| } |
fix microsoft/pxt-arcade#7515 (but more generally, fix importing github projects when in situations github view is disabled); when you load in project it'll work, just will have github information scrapped:
