Class: Collavre::PreviewChannel
- Inherits:
-
Channel
show all
- Defined in:
- app/models/collavre/preview_channel.rb
Overview
Topic chip for a running development preview server. Unlike GithubPrChannel there is no external webhook source — the chip is populated by AI Agents (or humans) calling preview_attach/preview_detach MCP tools, one for each ./bin/dev they spin up alongside a worktree.
Constant Summary
collapse
- PREVIEW_STATES =
%w[running stopped].freeze
Constants inherited
from Channel
Channel::BOT_EMAIL, Channel::BOT_NAME
Instance Method Summary
collapse
Methods inherited from Channel
#detach!, #dismiss!, #dismissed?, #inject_into_topic!, #record_event!
Instance Method Details
#attached_message ⇒ Object
54
55
56
57
58
59
60
61
62
|
# File 'app/models/collavre/preview_channel.rb', line 54
def attached_message
Collavre::Channel::InjectedMessage.new(
speaker: channel_bot_user,
message: I18n.t("collavre.channel.preview.attached_message",
label: default_label, url: preview_url),
label: default_label,
link: preview_url
)
end
|
#badge_state ⇒ Object
35
36
37
|
# File 'app/models/collavre/preview_channel.rb', line 35
def badge_state
preview_state
end
|
#badge_title ⇒ Object
39
40
41
|
# File 'app/models/collavre/preview_channel.rb', line 39
def badge_title
I18n.t("collavre.channel.preview.badge.#{preview_state}", default: preview_state.to_s)
end
|
#custom_label ⇒ Object
19
20
21
|
# File 'app/models/collavre/preview_channel.rb', line 19
def custom_label
config["label"]
end
|
#default_label ⇒ Object
Chip fallbacks rendered immediately on attach, before the user has interacted with the chip. The label prefers the caller-supplied “Preview #42” style override and falls back to a localized default; the link is always the preview URL.
27
28
29
|
# File 'app/models/collavre/preview_channel.rb', line 27
def default_label
custom_label.presence || I18n.t("collavre.channel.preview.label_default")
end
|
#default_link ⇒ Object
31
32
33
|
# File 'app/models/collavre/preview_channel.rb', line 31
def default_link
preview_url
end
|
#handle(event:, payload:) ⇒ Object
PreviewChannel has no external event source — preview_attach/detach mutate the channel directly. The base ‘handle` would raise NotImplementedError, so override with an explicit no-op.
67
68
69
|
# File 'app/models/collavre/preview_channel.rb', line 67
def handle(event:, payload:)
nil
end
|
#preview_state ⇒ Object
43
44
45
46
|
# File 'app/models/collavre/preview_channel.rb', line 43
def preview_state
state = config["preview_state"].to_s
PREVIEW_STATES.include?(state) ? state : "running"
end
|
#preview_state=(value) ⇒ Object
48
49
50
51
52
|
# File 'app/models/collavre/preview_channel.rb', line 48
def preview_state=(value)
value = value.to_s
raise ArgumentError, "Invalid preview_state: #{value.inspect}" unless PREVIEW_STATES.include?(value)
self.config = config.merge("preview_state" => value)
end
|
#preview_url ⇒ Object
11
12
13
|
# File 'app/models/collavre/preview_channel.rb', line 11
def preview_url
config["preview_url"]
end
|
#worktree_id ⇒ Object
15
16
17
|
# File 'app/models/collavre/preview_channel.rb', line 15
def worktree_id
config["worktree_id"]
end
|