workspaces 0.1.18 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/DESIGN.md +31 -30
- data/README.md +42 -2
- data/lib/workspaces/config.rb +4 -0
- data/lib/workspaces/coordinator.rb +8 -0
- data/lib/workspaces/dashboard/app.js +19 -20
- data/lib/workspaces/dashboard/card.html.erb +42 -0
- data/lib/workspaces/dashboard/styles.css +160 -135
- data/lib/workspaces/dashboard/template.html.erb +13 -13
- data/lib/workspaces/dashboard_view.rb +115 -17
- data/lib/workspaces/front_door.rb +102 -7
- data/lib/workspaces/presentation.rb +18 -28
- data/lib/workspaces/version.rb +1 -1
- metadata +3 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'erb'
|
|
2
2
|
require 'json'
|
|
3
|
+
require 'time'
|
|
3
4
|
require_relative 'config'
|
|
4
5
|
require_relative 'presentation'
|
|
5
6
|
require_relative 'duration_format'
|
|
@@ -13,22 +14,42 @@ module Workspaces
|
|
|
13
14
|
def self.index(workspaces)
|
|
14
15
|
view = new({})
|
|
15
16
|
view.document('Workspaces', <<~HTML)
|
|
16
|
-
<main class="dashboard"><header class="dashboard__header"><h1>Workspaces</h1></header>
|
|
17
|
-
<section class="status-panel"><h2>Create workspace</h2>
|
|
18
|
-
<p>
|
|
17
|
+
<main class="dashboard"><header class="dashboard__header"><h1>Workspaces</h1><p class="dashboard__note">#{view.inventory_summary(workspaces)}</p></header>
|
|
18
|
+
<section class="status-panel" aria-labelledby="create-heading"><h2 id="create-heading">Create workspace</h2>
|
|
19
|
+
<p>Pick an existing branch, a PR number, or a new branch. Each submission creates its own managed worktree.</p>
|
|
19
20
|
<form method="post" action="/workspaces/create" class="stack">
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
<div class="create-fields">
|
|
22
|
+
<div class="field"><label for="create-branch">Existing branch</label><input id="create-branch" name="branch" placeholder="main" autocomplete="off" spellcheck="false"></div>
|
|
23
|
+
<div class="field"><label for="create-pr">PR number</label><input id="create-pr" name="pr" inputmode="numeric" placeholder="43828" autocomplete="off"></div>
|
|
24
|
+
<div class="field"><label for="create-new-branch">New branch</label><input id="create-new-branch" name="new_branch" placeholder="agent/fix-checkout" autocomplete="off" spellcheck="false"></div>
|
|
25
|
+
<div class="field"><label for="create-from">Start new branch from</label><input id="create-from" name="from" placeholder="HEAD" autocomplete="off" spellcheck="false"></div>
|
|
26
|
+
</div>
|
|
27
|
+
<button type="submit" class="button button--primary">Create workspace</button>
|
|
25
28
|
</form></section>
|
|
26
|
-
<section class="status-panel"><h2>Managed workspaces</h2>
|
|
29
|
+
<section class="status-panel" aria-labelledby="inventory-heading"><h2 id="inventory-heading">Managed workspaces</h2>
|
|
27
30
|
#{view.inventory_table(workspaces)}
|
|
28
31
|
</section></main>
|
|
29
32
|
HTML
|
|
30
33
|
end
|
|
31
34
|
|
|
35
|
+
# The default page for a workspace: one small card with the headline, progress and the single
|
|
36
|
+
# next action. Everything else lives on the settings page.
|
|
37
|
+
def self.card(snapshot, preview: false)
|
|
38
|
+
new(snapshot, preview: preview).render_card
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
PREVIEW_STATUS_KEYS = %w(state busy ready headline summary progress lead_action current_preset sleep open).freeze
|
|
42
|
+
PREVIEW_ERROR = 'Setup failed. Open settings for the full log.'.freeze
|
|
43
|
+
|
|
44
|
+
# What the card polls for on a preview host, where the workspace's own pages share the origin.
|
|
45
|
+
# Only what the card draws: no log, no steps, no environment and no error text.
|
|
46
|
+
def self.preview_status(snapshot)
|
|
47
|
+
view = Presentation.new(snapshot).to_h
|
|
48
|
+
slim = view.slice(*PREVIEW_STATUS_KEYS).merge('error' => view['error'] ? PREVIEW_ERROR : '')
|
|
49
|
+
{ 'presentation' => slim, 'prepare_started_at' => snapshot['prepare_started_at'],
|
|
50
|
+
'completed_at' => snapshot['completed_at'] }
|
|
51
|
+
end
|
|
52
|
+
|
|
32
53
|
def self.pull_request(number, workspaces)
|
|
33
54
|
new({}).render_pull_request(number, workspaces)
|
|
34
55
|
end
|
|
@@ -51,8 +72,9 @@ module Workspaces
|
|
|
51
72
|
SVG
|
|
52
73
|
end
|
|
53
74
|
|
|
54
|
-
def initialize(snapshot)
|
|
75
|
+
def initialize(snapshot, preview: false)
|
|
55
76
|
@snapshot = snapshot
|
|
77
|
+
@preview = preview
|
|
56
78
|
@presentation = Presentation.new(snapshot).to_h
|
|
57
79
|
end
|
|
58
80
|
|
|
@@ -63,6 +85,17 @@ module Workspaces
|
|
|
63
85
|
encoding: 'UTF-8')).result(binding))
|
|
64
86
|
end
|
|
65
87
|
|
|
88
|
+
# On a preview host the card is served from the workspace's own origin, so its controls go to the
|
|
89
|
+
# front door's reserved /__workspaces/ endpoints, it never shows error text, and it reloads the
|
|
90
|
+
# page the visitor asked for once the workspace is ready.
|
|
91
|
+
def render_card
|
|
92
|
+
@id = Config.validate_id!(@snapshot.fetch('workspace_id'))
|
|
93
|
+
@presentation = @presentation.merge('error' => PREVIEW_ERROR) if @preview && @presentation['error']
|
|
94
|
+
document("Workspace #{@id}",
|
|
95
|
+
ERB.new(File.read(File.join(__dir__, 'dashboard/card.html.erb'),
|
|
96
|
+
encoding: 'UTF-8')).result(binding))
|
|
97
|
+
end
|
|
98
|
+
|
|
66
99
|
def render_pull_request(number, workspaces)
|
|
67
100
|
@number = number
|
|
68
101
|
@workspaces = workspaces
|
|
@@ -98,25 +131,74 @@ module Workspaces
|
|
|
98
131
|
return '<p class="muted">No workspaces yet.</p>' if workspaces.empty?
|
|
99
132
|
|
|
100
133
|
<<~HTML
|
|
134
|
+
<div class="table-scroll">
|
|
101
135
|
<table class="workspace-table">
|
|
102
|
-
<thead><tr><th scope="col">Workspace</th><th scope="col">Status</th><th scope="col" class="workspace-table__date">Created</th><th scope="col" class="workspace-table__date">Last startup</th></tr></thead>
|
|
136
|
+
<thead><tr><th scope="col">Workspace</th><th scope="col">Status</th><th scope="col" class="workspace-table__date">Created (UTC)</th><th scope="col" class="workspace-table__date">Last startup (UTC)</th></tr></thead>
|
|
103
137
|
<tbody>
|
|
104
|
-
#{workspaces.map { |workspace| inventory_row(workspace) }.join}
|
|
138
|
+
#{by_last_startup(workspaces).map { |workspace| inventory_row(workspace) }.join}
|
|
105
139
|
</tbody>
|
|
106
140
|
</table>
|
|
141
|
+
</div>
|
|
107
142
|
HTML
|
|
108
143
|
end
|
|
109
144
|
|
|
145
|
+
# Most recently started first; workspaces that have never started (or whose start time cannot be read)
|
|
146
|
+
# come last. Moments are compared as moments, not as text, so a different UTC offset or fraction cannot
|
|
147
|
+
# misorder rows, and ties fall back to the id so the list never shuffles between loads.
|
|
148
|
+
def by_last_startup(workspaces)
|
|
149
|
+
workspaces.sort_by do |workspace|
|
|
150
|
+
started = startup_moment(workspace['started_at'])
|
|
151
|
+
[started ? 0 : 1, started ? -started.to_r : 0, workspace['id'].to_s]
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def startup_moment(value)
|
|
156
|
+
return nil if value.nil? || value.to_s.empty?
|
|
157
|
+
|
|
158
|
+
Time.iso8601(value.to_s)
|
|
159
|
+
rescue ArgumentError
|
|
160
|
+
nil
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# "8 managed worktrees · none running", counted from the data on the page.
|
|
164
|
+
def inventory_summary(workspaces)
|
|
165
|
+
total = workspaces.length
|
|
166
|
+
running = workspaces.count { |workspace| workspace['running'] }
|
|
167
|
+
noun = total == 1 ? 'managed worktree' : 'managed worktrees'
|
|
168
|
+
"#{total} #{noun} · #{running.zero? ? 'none running' : "#{running} running"}"
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# "Oct 27, 10:48" in UTC, with the full value kept in the title. Anything that is not a timestamp is
|
|
172
|
+
# shown as it came rather than guessed at.
|
|
173
|
+
def short_time(value)
|
|
174
|
+
Time.iso8601(value.to_s).utc.strftime('%b %-d, %H:%M')
|
|
175
|
+
rescue ArgumentError
|
|
176
|
+
value.to_s
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def time_cell(value, empty)
|
|
180
|
+
return "<span class=\"never\">#{empty}</span>" if value.nil? || value.to_s.empty?
|
|
181
|
+
|
|
182
|
+
"<time datetime=\"#{escape(value)}\" title=\"#{escape(value)}\">#{escape(short_time(value))}</time>"
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# The word shown in a status pill. What the workspace is doing is the word; whether a server is
|
|
186
|
+
# up is the dot's job elsewhere, so there is no repeated "Not running ·" prefix.
|
|
187
|
+
def status_text(workspace)
|
|
188
|
+
status = (workspace['status'] || 'idle').to_s
|
|
189
|
+
status = status.capitalize
|
|
190
|
+
workspace['active'] ? "#{status} (busy)" : status
|
|
191
|
+
end
|
|
192
|
+
|
|
110
193
|
def inventory_row(workspace)
|
|
111
194
|
id = escape(Config.validate_id!(workspace.fetch('id')))
|
|
112
195
|
status = escape(workspace['status'] || 'idle')
|
|
113
|
-
running = workspace['running'] ? 'Running' : 'Not running'
|
|
114
196
|
<<~HTML
|
|
115
197
|
<tr>
|
|
116
198
|
<th scope="row"><a href="/workspaces/#{id}">#{id}</a></th>
|
|
117
|
-
<td><span class="status-pill" data-status="#{status}"><span class="status-dot" aria-hidden="true"></span>#{
|
|
118
|
-
<td class="workspace-table__date"
|
|
119
|
-
<td class="workspace-table__date"
|
|
199
|
+
<td><span class="status-pill" data-status="#{status}" data-busy="#{workspace['active'] ? 'true' : 'false'}"><span class="status-dot" aria-hidden="true"></span>#{escape(status_text(workspace))}</span></td>
|
|
200
|
+
<td class="workspace-table__date">#{time_cell(workspace['created_at'], 'Unavailable')}</td>
|
|
201
|
+
<td class="workspace-table__date">#{time_cell(workspace['started_at'], 'Never')}</td>
|
|
120
202
|
</tr>
|
|
121
203
|
HTML
|
|
122
204
|
end
|
|
@@ -225,10 +307,26 @@ module Workspaces
|
|
|
225
307
|
def lead_action_form(action)
|
|
226
308
|
return '' unless action && action['kind'] == 'post'
|
|
227
309
|
|
|
228
|
-
"<form method=\"post\" action=\"
|
|
310
|
+
"<form method=\"post\" action=\"#{action_base}/#{action.fetch('key')}\">" \
|
|
229
311
|
"<button class=\"button button--primary button--large\">#{escape(action.fetch('label'))}</button></form>"
|
|
230
312
|
end
|
|
231
313
|
|
|
314
|
+
def action_base
|
|
315
|
+
@preview ? '/__workspaces' : "/workspaces/#{@id}"
|
|
316
|
+
end
|
|
317
|
+
|
|
318
|
+
def settings_href
|
|
319
|
+
@preview ? Config.settings_url(@id) : "/workspaces/#{@id}/settings"
|
|
320
|
+
end
|
|
321
|
+
|
|
322
|
+
# Where the card's start form posts. A shared card with presets saves the chosen one through the
|
|
323
|
+
# environment form; a preview card starts through its own origin.
|
|
324
|
+
def start_form_action
|
|
325
|
+
return "#{action_base}/start" if @preview || environment_presets.empty?
|
|
326
|
+
|
|
327
|
+
"/workspaces/#{@id}/environment"
|
|
328
|
+
end
|
|
329
|
+
|
|
232
330
|
def action_form(action)
|
|
233
331
|
style = action['primary'] ? 'button--primary' : 'button--subtle'
|
|
234
332
|
"<form method=\"post\" action=\"/workspaces/#{@id}/#{action.fetch('key')}\">" \
|
|
@@ -12,13 +12,19 @@ require_relative 'sleep_policy'
|
|
|
12
12
|
module Workspaces
|
|
13
13
|
class FrontDoor
|
|
14
14
|
WORKSPACE_ROUTE = %r{\A/workspaces/([a-z0-9]+(?:-[a-z0-9]+)*)
|
|
15
|
-
(?:/(status|start|prepare|restart|resume|stop|remove|update-pr|environment|keep-awake|allow-sleep))?\z}x
|
|
15
|
+
(?:/(status|start|prepare|restart|resume|stop|remove|update-pr|environment|keep-awake|allow-sleep|settings))?\z}x
|
|
16
16
|
|
|
17
17
|
# Rack env keys set on requests that reach a ready workspace backend, for use by
|
|
18
18
|
# middleware registered with Workspaces.configure_proxy.
|
|
19
19
|
WORKSPACE_ID_ENV = 'workspaces.workspace_id'.freeze
|
|
20
20
|
WORKSPACE_ENV = 'workspaces.workspace'.freeze
|
|
21
21
|
|
|
22
|
+
# Paths under this prefix on a preview host belong to the front door, never to the workspace's app.
|
|
23
|
+
# They serve the waiting card's status and its few lifecycle posts (see DashboardView.card).
|
|
24
|
+
RESERVED_PREFIX = '/__workspaces/'.freeze
|
|
25
|
+
RESERVED_ROUTE = %r{\A/__workspaces/(status|start|prepare|restart|resume)\z}
|
|
26
|
+
private_constant :RESERVED_PREFIX, :RESERVED_ROUTE
|
|
27
|
+
|
|
22
28
|
WAKE_POLL_SECONDS = 0.25
|
|
23
29
|
RETRY_AFTER_SECONDS = 5
|
|
24
30
|
private_constant :WAKE_POLL_SECONDS, :RETRY_AFTER_SECONDS
|
|
@@ -99,7 +105,7 @@ module Workspaces
|
|
|
99
105
|
|
|
100
106
|
def action_request(request, id, action)
|
|
101
107
|
return update_environment(request, id) if action == 'environment'
|
|
102
|
-
return status_response(request, id, action) if action.nil? || action
|
|
108
|
+
return status_response(request, id, action) if action.nil? || %w(status settings).include?(action)
|
|
103
109
|
return response(405, 'Use POST') unless request.post?
|
|
104
110
|
return response(403, 'Actions require the configured dashboard origin') unless same_origin?(request)
|
|
105
111
|
return remove(request, id) if action == 'remove'
|
|
@@ -116,8 +122,10 @@ module Workspaces
|
|
|
116
122
|
return response(400, 'Unknown workspace log') unless %w(setup backend).include?(source)
|
|
117
123
|
|
|
118
124
|
snapshot = @coordinator.snapshot(id, log: source)
|
|
119
|
-
|
|
120
|
-
|
|
125
|
+
return response(200, JSON.generate(snapshot), type: 'application/json', head: request.head?) if action == 'status'
|
|
126
|
+
|
|
127
|
+
page = action == 'settings' ? DashboardView.render(snapshot) : DashboardView.card(snapshot)
|
|
128
|
+
response(200, page, type: 'text/html', head: request.head?)
|
|
121
129
|
end
|
|
122
130
|
|
|
123
131
|
# Retries from the first unfinished step by default; `from=<step>` re-runs that step and every
|
|
@@ -148,7 +156,9 @@ module Workspaces
|
|
|
148
156
|
return response(403, 'Actions require the configured dashboard origin') unless same_origin?(request)
|
|
149
157
|
|
|
150
158
|
params = environment_params(request)
|
|
151
|
-
updated = if params.key?('
|
|
159
|
+
updated = if params.key?('preset')
|
|
160
|
+
start_with_preset(id, params['preset'])
|
|
161
|
+
elsif params.key?('env')
|
|
152
162
|
@coordinator.replace_environment_rows(id, rows: parse_environment_rows(params))
|
|
153
163
|
elsif params.key?('editable_env')
|
|
154
164
|
@coordinator.replace_editable_environment(id, text: parse_editable_environment(params))
|
|
@@ -164,6 +174,14 @@ module Workspaces
|
|
|
164
174
|
response(422, e.message)
|
|
165
175
|
end
|
|
166
176
|
|
|
177
|
+
# The card's start form for a new workspace: one preset (or the defaults, when left blank).
|
|
178
|
+
def start_with_preset(id, preset)
|
|
179
|
+
raise EnvironmentOverrides::Invalid, 'Choose a preset by name' unless preset.is_a?(String)
|
|
180
|
+
return @coordinator.apply_environment_preset(id, name: preset) unless preset.empty?
|
|
181
|
+
|
|
182
|
+
@coordinator.start(id)
|
|
183
|
+
end
|
|
184
|
+
|
|
167
185
|
def remove(request, id)
|
|
168
186
|
unless request.media_type == 'application/x-www-form-urlencoded'
|
|
169
187
|
return response(415, 'Deletion requires a form-encoded confirmation')
|
|
@@ -182,11 +200,12 @@ module Workspaces
|
|
|
182
200
|
response(409, 'Workspace was not removed. Check the server logs and retry when safe.')
|
|
183
201
|
end
|
|
184
202
|
|
|
203
|
+
# Update from PR is a settings-page control and reports its outcome there.
|
|
185
204
|
def update_pr(id)
|
|
186
205
|
@registry.update_pr(id)
|
|
187
|
-
redirect(Config.
|
|
206
|
+
redirect(Config.settings_url(id))
|
|
188
207
|
rescue Worktree::UpdateError
|
|
189
|
-
redirect(Config.
|
|
208
|
+
redirect(Config.settings_url(id))
|
|
190
209
|
end
|
|
191
210
|
|
|
192
211
|
def create(request)
|
|
@@ -278,6 +297,7 @@ module Workspaces
|
|
|
278
297
|
|
|
279
298
|
def proxy(id, request)
|
|
280
299
|
return response(404, 'Unknown managed workspace') unless Worktree.new(id).exists?
|
|
300
|
+
return reserved(id, request) if request.path_info.start_with?(RESERVED_PREFIX)
|
|
281
301
|
|
|
282
302
|
counted = !@sleep_policy.ignored?(request.path_info)
|
|
283
303
|
lease = acquire_lease(id, counted)
|
|
@@ -298,6 +318,7 @@ module Workspaces
|
|
|
298
318
|
phase = @coordinator.sleep_phase(id)
|
|
299
319
|
if phase
|
|
300
320
|
return sleeping_unavailable(id) unless counted
|
|
321
|
+
return waiting_card(id, phase) if navigation?(request)
|
|
301
322
|
|
|
302
323
|
outcome = await_wake(id, phase)
|
|
303
324
|
return wake_failed(id) if outcome == :failed
|
|
@@ -382,11 +403,85 @@ module Workspaces
|
|
|
382
403
|
end
|
|
383
404
|
|
|
384
405
|
def unavailable(id, request)
|
|
406
|
+
return card_response(@coordinator.snapshot(id, include_log: false)) if navigation?(request)
|
|
385
407
|
return redirect(Config.dashboard_url(id)) if safe?(request)
|
|
386
408
|
|
|
387
409
|
response(503, "Workspace not ready. Visit #{Config.dashboard_url(id)}")
|
|
388
410
|
end
|
|
389
411
|
|
|
412
|
+
# A person opening a page in a browser, as opposed to the app's own fetches, assets and API calls.
|
|
413
|
+
# Only they are shown the card; everything else keeps the plain behaviour.
|
|
414
|
+
def navigation?(request)
|
|
415
|
+
return false unless request.get?
|
|
416
|
+
return false unless request.get_header('HTTP_ACCEPT').to_s.include?('text/html')
|
|
417
|
+
return false if request.get_header('HTTP_X_REQUESTED_WITH')
|
|
418
|
+
|
|
419
|
+
mode = request.get_header('HTTP_SEC_FETCH_MODE')
|
|
420
|
+
mode.nil? || mode == 'navigate'
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
# A sleeping workspace is woken at once and the visitor sees the card, not a held request, so the
|
|
424
|
+
# address they asked for stays in the bar and the card reloads it when the workspace is ready.
|
|
425
|
+
def waiting_card(id, phase)
|
|
426
|
+
@coordinator.wake(id) if phase == :sleeping
|
|
427
|
+
card_response(@coordinator.snapshot(id, include_log: false))
|
|
428
|
+
end
|
|
429
|
+
|
|
430
|
+
def card_response(snapshot)
|
|
431
|
+
response(200, DashboardView.card(snapshot, preview: true), type: 'text/html')
|
|
432
|
+
end
|
|
433
|
+
|
|
434
|
+
# The waiting card's own endpoints. Not counted as activity (polling must not keep a workspace awake),
|
|
435
|
+
# never forwarded, and limited to what the card does: report status and start, retry or continue.
|
|
436
|
+
def reserved(id, request)
|
|
437
|
+
match = RESERVED_ROUTE.match(request.path_info)
|
|
438
|
+
return response(404, 'Not found') unless match
|
|
439
|
+
|
|
440
|
+
action = match[1]
|
|
441
|
+
return preview_status(id, request) if action == 'status'
|
|
442
|
+
return response(405, 'Use POST') unless request.post?
|
|
443
|
+
return response(403, 'Actions require this workspace origin') unless preview_same_origin?(request, id)
|
|
444
|
+
|
|
445
|
+
preview_action(id, action, request)
|
|
446
|
+
redirect(preview_return_url(request, id))
|
|
447
|
+
end
|
|
448
|
+
|
|
449
|
+
def preview_status(id, request)
|
|
450
|
+
return response(405, 'Use GET or HEAD') unless safe?(request)
|
|
451
|
+
|
|
452
|
+
body = JSON.generate(DashboardView.preview_status(@coordinator.snapshot(id, include_log: false)))
|
|
453
|
+
response(200, body, type: 'application/json', head: request.head?)
|
|
454
|
+
end
|
|
455
|
+
|
|
456
|
+
def preview_action(id, action, request)
|
|
457
|
+
preset = request.POST['preset'] if action == 'start' && request.media_type == 'application/x-www-form-urlencoded'
|
|
458
|
+
return start_with_preset(id, preset) if preset.is_a?(String)
|
|
459
|
+
|
|
460
|
+
perform_action(id, action, request)
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
def preview_same_origin?(request, id)
|
|
464
|
+
expected = Config.preview_url(id).chomp('/')
|
|
465
|
+
origin = request.get_header('HTTP_ORIGIN')
|
|
466
|
+
return origin == expected if origin
|
|
467
|
+
|
|
468
|
+
uri = URI.parse(request.referer.to_s)
|
|
469
|
+
uri.is_a?(URI::HTTP) && uri.userinfo.nil? && "#{uri.scheme}://#{uri.authority}" == expected
|
|
470
|
+
rescue URI::InvalidURIError
|
|
471
|
+
false
|
|
472
|
+
end
|
|
473
|
+
|
|
474
|
+
# Back to the page the visitor was on, so a start or retry does not lose their place.
|
|
475
|
+
def preview_return_url(request, id)
|
|
476
|
+
base = Config.preview_url(id).chomp('/')
|
|
477
|
+
uri = URI.parse(request.referer.to_s)
|
|
478
|
+
path = uri.request_uri if uri.is_a?(URI::HTTP) && "#{uri.scheme}://#{uri.authority}" == base
|
|
479
|
+
path = '/' if path.nil? || path.start_with?(RESERVED_PREFIX)
|
|
480
|
+
"#{base}#{path}"
|
|
481
|
+
rescue URI::InvalidURIError
|
|
482
|
+
"#{base}/"
|
|
483
|
+
end
|
|
484
|
+
|
|
390
485
|
# Innermost app of the proxy stack: sends the request to the workspace backend.
|
|
391
486
|
def forward_to_backend(env)
|
|
392
487
|
forward(env.fetch(WORKSPACE_ID_ENV), Rack::Request.new(env))
|
|
@@ -11,12 +11,12 @@ module Workspaces
|
|
|
11
11
|
'resume' => 'Retry failed step', 'keep-awake' => 'Keep awake',
|
|
12
12
|
'allow-sleep' => 'Allow sleep' }.freeze
|
|
13
13
|
|
|
14
|
-
#
|
|
15
|
-
# most one primary action. `environment` (presets and variables) is the area for
|
|
16
|
-
# deliberately changing something. `technical`
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
# not a section of their own: each
|
|
14
|
+
# The sections of the settings page, from friendly to technical. `lead` is the headline, one
|
|
15
|
+
# sentence and at most one primary action. `environment` (presets and variables) is the area for
|
|
16
|
+
# deliberately changing something. `technical` holds setup steps, logs, workspace details,
|
|
17
|
+
# lifecycle controls and deletion. All of them are plain sections, always open when shown: the
|
|
18
|
+
# card at /workspaces/ID is what keeps the details out of the way, so this page has nothing to
|
|
19
|
+
# fold. Setup steps are not a section of their own: each has its own log row inside `log`.
|
|
20
20
|
SECTIONS = %w(lead actions environment technical log details danger).freeze
|
|
21
21
|
TECHNICAL = %w(technical actions log details danger).freeze
|
|
22
22
|
|
|
@@ -32,66 +32,57 @@ module Workspaces
|
|
|
32
32
|
# `environment_submit` labels the single environment-form button, which saves the
|
|
33
33
|
# settings and (re)starts the workspace, so a brand new workspace needs only that.
|
|
34
34
|
#
|
|
35
|
-
# Per state: `headline` and `summary` are plain language
|
|
36
|
-
# `
|
|
37
|
-
# technical section so the cause is visible without hunting for it.
|
|
35
|
+
# Per state: `headline` and `summary` are plain language, `sections` says which sections are
|
|
36
|
+
# shown, and `environment_submit` / `environment_title` word the settings form.
|
|
38
37
|
STATES = {
|
|
39
38
|
'idle' => {
|
|
40
39
|
sections: %w(lead environment),
|
|
41
40
|
headline: "Let's get your workspace running",
|
|
42
41
|
summary: 'Pick the version of the site you want to preview, then start. Setup usually takes a few minutes.',
|
|
43
|
-
environment_submit: 'Start workspace', environment_title: 'Choose what to preview'
|
|
44
|
-
open_environment: true, open_technical: false
|
|
42
|
+
environment_submit: 'Start workspace', environment_title: 'Choose what to preview'
|
|
45
43
|
},
|
|
46
44
|
'busy' => {
|
|
47
45
|
sections: %w(lead technical log),
|
|
48
46
|
headline: 'Setting things up…',
|
|
49
|
-
summary:
|
|
50
|
-
environment_submit: 'Save & restart', environment_title: 'Change settings'
|
|
51
|
-
open_environment: false, open_technical: true
|
|
47
|
+
summary: 'This page keeps itself up to date. Open the preview once it is ready.',
|
|
48
|
+
environment_submit: 'Save & restart', environment_title: 'Change settings'
|
|
52
49
|
},
|
|
53
50
|
'ready' => {
|
|
54
51
|
sections: %w(lead environment) + TECHNICAL,
|
|
55
52
|
headline: 'Your workspace is ready',
|
|
56
53
|
summary: 'Everything is set up and running. Open it to see your changes.',
|
|
57
|
-
environment_submit: 'Save & restart', environment_title: 'Change settings'
|
|
58
|
-
open_environment: false, open_technical: false
|
|
54
|
+
environment_submit: 'Save & restart', environment_title: 'Change settings'
|
|
59
55
|
},
|
|
60
56
|
'sleeping' => {
|
|
61
57
|
sections: %w(lead environment) + TECHNICAL,
|
|
62
58
|
headline: 'Your workspace is asleep',
|
|
63
59
|
summary: 'It went quiet, so its server was stopped to free up resources. Your files and data are kept. ' \
|
|
64
60
|
'Opening the preview wakes it in a few seconds.',
|
|
65
|
-
environment_submit: 'Save & start', environment_title: 'Change settings'
|
|
66
|
-
open_environment: false, open_technical: false
|
|
61
|
+
environment_submit: 'Save & start', environment_title: 'Change settings'
|
|
67
62
|
},
|
|
68
63
|
'stopped' => {
|
|
69
64
|
sections: %w(lead environment) + TECHNICAL,
|
|
70
65
|
headline: 'Your workspace is paused',
|
|
71
66
|
summary: 'Start it again to pick up where you left off.',
|
|
72
|
-
environment_submit: 'Save & start', environment_title: 'Change settings'
|
|
73
|
-
open_environment: false, open_technical: false
|
|
67
|
+
environment_submit: 'Save & start', environment_title: 'Change settings'
|
|
74
68
|
},
|
|
75
69
|
'error' => {
|
|
76
70
|
sections: %w(lead environment) + TECHNICAL,
|
|
77
71
|
headline: "Something didn't go to plan",
|
|
78
72
|
summary: 'Setup stopped before it finished. You can try again, or change settings first.',
|
|
79
|
-
environment_submit: 'Save & retry', environment_title: 'Change settings'
|
|
80
|
-
open_environment: false, open_technical: true
|
|
73
|
+
environment_submit: 'Save & retry', environment_title: 'Change settings'
|
|
81
74
|
},
|
|
82
75
|
'interrupted' => {
|
|
83
76
|
sections: %w(lead environment) + TECHNICAL,
|
|
84
77
|
headline: 'Setup was interrupted',
|
|
85
78
|
summary: 'It stopped before it finished. Try again to pick up from the start.',
|
|
86
|
-
environment_submit: 'Save & retry', environment_title: 'Change settings'
|
|
87
|
-
open_environment: false, open_technical: true
|
|
79
|
+
environment_submit: 'Save & retry', environment_title: 'Change settings'
|
|
88
80
|
},
|
|
89
81
|
'unknown' => {
|
|
90
82
|
sections: %w(lead technical log details),
|
|
91
83
|
headline: 'Workspace status unknown',
|
|
92
84
|
summary: 'Open the technical details to see what the workspace is doing.',
|
|
93
|
-
environment_submit: 'Save & restart', environment_title: 'Change settings'
|
|
94
|
-
open_environment: false, open_technical: true
|
|
85
|
+
environment_submit: 'Save & restart', environment_title: 'Change settings'
|
|
95
86
|
}
|
|
96
87
|
}.freeze
|
|
97
88
|
|
|
@@ -107,8 +98,7 @@ module Workspaces
|
|
|
107
98
|
'lead_action' => lead_action, 'total' => total, 'progress' => progress,
|
|
108
99
|
'current_preset' => current_preset, 'sleep' => sleep_info,
|
|
109
100
|
'environment_title' => definition[:environment_title],
|
|
110
|
-
'environment_submit' => definition[:environment_submit]
|
|
111
|
-
'open' => { 'environment' => definition[:open_environment], 'technical' => definition[:open_technical] } }
|
|
101
|
+
'environment_submit' => definition[:environment_submit] }
|
|
112
102
|
end
|
|
113
103
|
|
|
114
104
|
private
|
data/lib/workspaces/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: workspaces
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.20
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Workspaces contributors
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rack
|
|
@@ -79,6 +79,7 @@ files:
|
|
|
79
79
|
- lib/workspaces/config.rb
|
|
80
80
|
- lib/workspaces/coordinator.rb
|
|
81
81
|
- lib/workspaces/dashboard/app.js
|
|
82
|
+
- lib/workspaces/dashboard/card.html.erb
|
|
82
83
|
- lib/workspaces/dashboard/checkout_authentication_error.html.erb
|
|
83
84
|
- lib/workspaces/dashboard/environment.js
|
|
84
85
|
- lib/workspaces/dashboard/pull_request.html.erb
|