GitHub-linked scripts for the admin interface#490
Open
KonnorKurilla wants to merge 2 commits into
Open
Conversation
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.
What this does
Adds a way to point a Scripted API or Event Script at a file in a GitHub repo and have DreamFactory pull the script from there instead of pasting the content in by hand.
Right now if you want a script to come from GitHub, you have to know the exact repo, branch, and path and type them in. This adds a file explorer so you can browse the repo and click the file.
The pieces:
GitHub file explorer in the Link to Service panel. Pick a GitHub service and the repo field becomes an autocomplete populated from the GitHub API. It pages through results so it handles big accounts (up to 2000 repos). It detects the repo's default branch so you don't have to guess master vs main, and if detection misses it falls back to trying the other one. The path field becomes a lazy-loaded folder and file tree. Errors render inline in the panel rather than redirecting the whole page to an error screen.
Live-fetch wiring. When you pick a file, the component writes storage_service_id, scm_repository, scm_reference, and storage_path into the service config. The backend already uses those four to fetch the script from GitHub on each run (cached briefly), so the script stays current. Before this, the only option was a one-time snapshot baked into the content column.
Webhook section. Below the explorer there's a copy-able webhook URL you paste into the GitHub repo's webhook settings. On push, GitHub hits that URL and clears DreamFactory's cache for the service, so the next call pulls the updated script. The Auto-generate button creates or reuses a shared role and app, dreamfactory_webhook_cache_role and dreamfactory_webhook_cache_app, scoped to DELETE on cache/* so the webhook URL has a real API key without you hand-rolling one. If either the role or app gets deleted, clicking Auto-generate again repairs the pair.
Snapshot banner above the Script Contents editor. The editor shows a snapshot, not the live content, so the banner makes that obvious and gives you a Refresh button to re-pull from GitHub on demand.
Also hid the duplicate View Latest and Delete Cache buttons in the old df-script-editor footer once the new panel is doing that job.
Event Scripts got the same support as Scripted APIs. Added scmRepository and scmReference form controls, fixed the edit-load path that was silently dropping the storage fields, normalized storageServiceId in submit so it takes both a raw id and the {id, type} object the legacy dropdown produces, and stopped the submit from stripping storage_path for non-local_file services.
Backend
No backend changes. df-script (the Script service and ScriptableEventHandler both) and df-git already support the live-fetch path and the _repo browsing endpoints. df-core's VerbOverrides middleware already converts the webhook's POST + method=DELETE into a real DELETE on system/cache, so GitHub's push-only webhooks can invalidate the cache with nothing new on the backend.
Manual test plan:
Known limitation
The snapshot banner shows the service's last_modified_date as the snapshot time, but that's really "last saved" and moves whenever you save any unrelated field. A dedicated content_refreshed_at column on script_config and event_script would be accurate, but that's a backend migration in df-script. Worth a follow-up, not blocking this.
Files changed
Source (11 files):
Plus the separate update dist commit.