Class: CollavreGithub::Tools::PrMonitorService
- Inherits:
-
Object
- Object
- CollavreGithub::Tools::PrMonitorService
- Extended by:
- T::Sig, ToolMeta
- Defined in:
- app/services/collavre_github/tools/pr_monitor_service.rb
Constant Summary collapse
- PR_URL_RE =
%r{\Ahttps?://github\.com/([^/]+/[^/]+)/pull/(\d+)\z}.freeze
Instance Method Summary collapse
Instance Method Details
#call(topic_id:, pr_url:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/services/collavre_github/tools/pr_monitor_service.rb', line 25 def call(topic_id:, pr_url:) m = pr_url.match(PR_URL_RE) raise ArgumentError, "Invalid PR URL: #{pr_url}" unless m # GitHub owner/repo identifiers are case-insensitive but webhook payloads # always carry the canonical case. Normalize on store so user input # like "Owner/Repo" still matches incoming events. repo = m[1].downcase pr_number = m[2].to_i topic = Collavre::Topic.find(topic_id) Collavre::Tools::TopicAuthorizer.(topic) channel, attach_status = find_or_attach_channel(topic, repo, pr_number) # Re-seed announcement on fresh attach AND on detached->active so the # chip label/link cache is repopulated after the channel was previously # auto-detached (PR closed) and the user reattached it. if attach_status == :created || attach_status == :reactivated channel.inject_into_topic!(channel.) end result = { ok: true, channel_id: channel.id, repo: repo, pr_number: pr_number } warning = ensure_webhook_events(topic, repo) result[:webhook_warning] = warning if warning result end |