Importing projects site projects from .sb3 files#855
Conversation
Test coverage91.98% line coverage reported by SimpleCov. |
|
We require contributors to sign our Contributor License Agreement, and we don't have you on file. In order for us to review and merge your code, please complete this form and we'll get you added and review your contribution as soon as possible. |
|
We require contributors to sign our Contributor License Agreement, and we don't have you on file. In order for us to review and merge your code, please complete this form and we'll get you added and review your contribution as soon as possible. |
|
We require contributors to sign our Contributor License Agreement, and we don't have you on file. In order for us to review and merge your code, please complete this form and we'll get you added and review your contribution as soon as possible. |
|
We require contributors to sign our Contributor License Agreement, and we don't have you on file. In order for us to review and merge your code, please complete this form and we'll get you added and review your contribution as soon as possible. |
There was a problem hiding this comment.
Pull request overview
Adds support for importing Scratch “site projects” from .sb3 archives by parsing project.json, extracting referenced assets, and wiring .sb3 handling into both filesystem and GitHub webhook-based imports.
Changes:
- Introduces
Sb3Parserplus anScratchSb3AssetImporterfor extracting/importing Scratch component JSON + assets from.sb3archives. - Updates
ProjectImporter,UploadJob, andFilesystemProjectto accept.sb3as a Scratch component input. - Adds test coverage for the parser, asset importer, and end-to-end upload/import behavior.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/support/sb3_archive_helper.rb | Adds test helper for generating .sb3 (zip) archives used by new specs. |
| spec/lib/scratch_sb3_asset_importer_spec.rb | Covers importing global Scratch assets from .sb3 archive entries. |
| spec/lib/sb3_parser_spec.rb | Covers parsing project.json and referenced assets from .sb3. |
| spec/lib/project_importer_spec.rb | Adds Scratch-specific import tests for .sb3 components + assets. |
| spec/jobs/upload_job_spec.rb | Adds webhook upload coverage for .sb3 Scratch projects. |
| lib/tasks/project_components/scratch-integration-test-starter/project_config.yml | Adds a filesystem-importable Scratch project config for the integration starter. |
| lib/scratch_sb3_asset_importer.rb | New importer for creating global ScratchAsset records from .sb3 assets. |
| lib/scratch_asset_importer.rb | Makes create_scratch_asset private (encapsulation change). |
| lib/sb3_parser.rb | New .sb3 archive parser extracting component JSON and referenced assets. |
| lib/project_importer.rb | Adds Scratch .sb3 import flow for scratch component content + global assets. |
| app/models/filesystem_project.rb | Allows .sb3 components for filesystem project imports. |
| app/jobs/upload_job.rb | Treats .sb3 files as components and fetches them as IO for import. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
We require contributors to sign our Contributor License Agreement, and we don't have you on file. In order for us to review and merge your code, please complete this form and we'll get you added and review your contribution as soon as possible. |
| io.rewind if io.respond_to?(:rewind) | ||
| result = nil | ||
| Zip::File.open_buffer(io.read) { |zip_file| result = yield zip_file } | ||
| result |
There was a problem hiding this comment.
Is the rewind needed? Also you don't need to assign the result, but you can call return inside the block.
| io.rewind if io.respond_to?(:rewind) | |
| result = nil | |
| Zip::File.open_buffer(io.read) { |zip_file| result = yield zip_file } | |
| result | |
| Zip::File.open_buffer(io.read) do | |
| return yield it | |
| end |
|
We require contributors to sign our Contributor License Agreement, and we don't have you on file. In order for us to review and merge your code, please complete this form and we'll get you added and review your contribution as soon as possible. |
|
We require contributors to sign our Contributor License Agreement, and we don't have you on file. In order for us to review and merge your code, please complete this form and we'll get you added and review your contribution as soon as possible. |
|
We require contributors to sign our Contributor License Agreement, and we don't have you on file. In order for us to review and merge your code, please complete this form and we'll get you added and review your contribution as soon as possible. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a860704. Configure here.
| raise ImportError, 'Scratch project content could not be parsed' if project_content.blank? | ||
|
|
||
| project.scratch_component = ScratchComponent.new(content: project_content) | ||
| project.scratch_assets = assets.map { create_scratch_asset(it) } |
There was a problem hiding this comment.
Re-import deletes user scratch uploads
High Severity
Assigning project.scratch_assets replaces the entire association, so a site-project re-import destroys every existing ScratchAsset on that project—not only previously imported files. User uploads stored on the shared starter project (e.g. pending assets before remix with uploaded_user_id set) are removed without being merged or preserved.
Reviewed by Cursor Bugbot for commit a860704. Configure here.


What's changed?
.sb3filescratch_sb3_asset_importer.rbcode_editor_scratchprojects.sb3files.sb3files