discourse/plugins/discourse-github/app/jobs/regular/rebake_github_pr_posts.rb
Jarek Radosz 6db2c7696f
FEATURE: Add PR status icon to inline oneboxes (#39649)
Extends the live PR status indicator (#36313) to inline oneboxes

<img width="759" height="308" alt="image"
src="https://github.com/user-attachments/assets/10a379d2-78a9-4987-8f56-1df854fe33fa"
/>
2026-05-04 18:15:14 +02:00

48 lines
1.3 KiB
Ruby
Vendored

# frozen_string_literal: true
module Jobs
class RebakeGithubPrPosts < ::Jobs::Base
sidekiq_options queue: "low"
def execute(args)
url = args[:pr_url]
return if url.blank?
Oneboxer.preview(url, invalidate_oneboxes: true)
InlineOneboxer.invalidate(url)
rebake_posts(url)
rebake_chat_messages(url) if SiteSetting.chat_enabled
end
private
def rebake_posts(url)
post_ids = TopicLink.where(url:).or(TopicLink.where("url LIKE ?", "#{url}%")).select(:post_id)
Post
.where(id: post_ids)
.where(
"cooked LIKE :pattern AND (cooked LIKE '%githubpullrequest%' OR cooked LIKE '%inline-onebox%')",
pattern: "%#{url}%",
)
.find_each { |post| post.rebake!(priority: :low, skip_publish_rebaked_changes: true) }
end
def rebake_chat_messages(url)
message_ids =
::Chat::MessageLink
.where(url:)
.or(::Chat::MessageLink.where("url LIKE ?", "#{url}%"))
.select(:chat_message_id)
::Chat::Message
.where(id: message_ids)
.where(
"cooked LIKE :pattern AND (cooked LIKE '%githubpullrequest%' OR cooked LIKE '%inline-onebox%')",
pattern: "%#{url}%",
)
.find_each { |message| message.rebake!(priority: :low, skip_notifications: true) }
end
end
end