Merged
Conversation
Test coverage89.92% line coverage reported by SimpleCov. |
We have permission from the Scratch Foundation to use the library assets available with Scratch. These tasks imports them assets defined in the in the library configuration files. See [1] for instructions on how to run. RaspberryPiFoundation/digital-editor-issues#1229
It's good practice when performing a lots of requests to add in time so not to overload any servers.
When running rake tasks locally there can be a lot of output from SQL queries and active storage, making it harder to see warnings. Make it possible to configure the Rails log level in development using environment variables. This is just like the code in production.rb except it uses the development default of debug.
Some of these tasks may take a while, the ruby progress bar library makes it easy to get a sense of progress. I've not shown the progress bar in tests as it messes the test output.
The library uses an <img> tag to load and embed the assets, which is different to how assets are loaded in projects For this to work, the asset needs to have a Cross-Origin-Resource-Policy set.
9e3c755 to
23387d7
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Adds tooling to import Scratch library assets into the app’s ScratchAsset/ActiveStorage store, and updates CORP behavior so Scratch asset requests can be embedded cross-origin.
Changes:
- Introduces
ScratchConfigImporterandScratchAssetImporterplus rake tasks to import backdrops/costumes/sounds/sprites from Scratch config JSON. - Extends
CorpMiddlewareto setCross-Origin-Resource-Policy: cross-originfor the Scratch asset GET endpoint. - Adds
ruby-progressbarand supporting specs + example env vars.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
lib/scratch_asset_importer.rb |
Implements asset fetching + persistence into ScratchAsset with optional progress output. |
lib/scratch_config_importer.rb |
Fetches/parses config JSON and extracts asset filenames to import. |
lib/tasks/scratch_assets.rake |
Adds rake tasks for importing different Scratch asset categories. |
lib/corp_middleware.rb |
Expands CORP header logic to include Scratch asset endpoint paths. |
spec/lib/scratch_asset_importer_spec.rb |
Adds importer behavior specs (create, skip existing, partial failures). |
spec/lib/scratch_config_importer_spec.rb |
Adds config parsing/extraction specs for importer handoff. |
spec/lib/corp_middleware_spec.rb |
Adds coverage for CORP header on Scratch asset requests. |
Gemfile / Gemfile.lock |
Adds ruby-progressbar dependency. |
config/environments/development.rb |
Makes log level configurable via RAILS_LOG_LEVEL. |
.env.example |
Documents Scratch asset import env vars. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There's a chance it won't be loaded when we use it
If the page 500s or 400s, this would be a clearer error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status
What's changed?
See commits for more.
Note that assets won't yet display as there's other issues preventing them. See https://github.com/orgs/RaspberryPiFoundation/projects/51/views/82?pane=issue&itemId=164355876&issue=RaspberryPiFoundation%7Cdigital-editor-issues%7C1229 for details.
Steps to perform after deploying to production