Skip to content

GitHub-linked scripts for the admin interface#490

Open
KonnorKurilla wants to merge 2 commits into
developfrom
feature/github-linked-scripts-explorer
Open

GitHub-linked scripts for the admin interface#490
KonnorKurilla wants to merge 2 commits into
developfrom
feature/github-linked-scripts-explorer

Conversation

@KonnorKurilla
Copy link
Copy Markdown
Contributor

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:

  • Create a Scripted API, link a GitHub file through the explorer, save. Confirm script_config has all four SCM fields.
  • Reopen the service. The explorer and snapshot banner should pre-fill from the saved config.
  • Hit Refresh on the banner. Content updates from GitHub.
  • Hit Auto-generate. dreamfactory_webhook_cache_role and dreamfactory_webhook_cache_app get created, scoped to DELETE on cache/*.
  • Paste the webhook URL into a GitHub repo, push a commit, confirm the cache clears and the next API call runs the new script.
  • Run the same flow on an Event Script.

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):

  • src/app/shared/components/df-link-service/ (component.ts, .html, .scss) — the explorer + webhook section
  • src/app/shared/components/df-script-editor/ (component.ts, .html, .scss) — snapshot banner, SCM-aware Refresh, hide-duplicate-actions input
  • src/app/adf-services/df-service-details/ (component.ts, .html) — wires df-link-service into Scripted APIs
  • src/app/adf-event-scripts/df-script-details/ (component.ts, .html) — wires it into Event Scripts + the submit/edit-load fixes
  • src/app/shared/types/files.ts — adds createdDate/lastModifiedDate to the Service type

Plus the separate update dist commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant