diff --git a/plugins/discourse-github/app/jobs/regular/rebake_github_pr_posts.rb b/plugins/discourse-github/app/jobs/regular/rebake_github_pr_posts.rb index 527536cbace..a01f0bc813c 100644 --- a/plugins/discourse-github/app/jobs/regular/rebake_github_pr_posts.rb +++ b/plugins/discourse-github/app/jobs/regular/rebake_github_pr_posts.rb @@ -46,7 +46,7 @@ module Jobs def has_github_pr_onebox?(cooked, pr_url) # quick & dirty check to avoid doing unnecessary rebakes - cooked.present? && cooked.include?("onebox") && cooked.include?(pr_url) + cooked.present? && cooked.include?("githubpullrequest") && cooked.include?(pr_url) end end end diff --git a/plugins/discourse-github/spec/jobs/rebake_github_pr_posts_spec.rb b/plugins/discourse-github/spec/jobs/rebake_github_pr_posts_spec.rb index fd0fa444f9d..a67ab65cb75 100644 --- a/plugins/discourse-github/spec/jobs/rebake_github_pr_posts_spec.rb +++ b/plugins/discourse-github/spec/jobs/rebake_github_pr_posts_spec.rb @@ -4,94 +4,57 @@ RSpec.describe Jobs::RebakeGithubPrPosts do fab!(:user) fab!(:topic) let(:pr_url) { "https://github.com/discourse/discourse/pull/123" } + let(:domain) { "github.com" } before { enable_current_plugin } + def create_post_with_link(cooked) + Fabricate(:post, topic:, user:, cooked:).tap do |post| + TopicLink.create!(topic:, post:, user:, url: pr_url, domain:) + end + end + describe "#execute" do - it "does nothing with blank pr_url" do + it "does nothing with blank or missing pr_url" do expect { described_class.new.execute(pr_url: nil) }.not_to raise_error expect { described_class.new.execute(pr_url: "") }.not_to raise_error end - context "with oneboxed PR link" do - fab!(:post) { Fabricate(:post, topic: topic, user: user) } + it "rebakes posts with full GitHub PR oneboxes" do + create_post_with_link(<<~HTML) + + HTML - before do - post.update!(cooked: <<~HTML) -
Check out this PR:
- - HTML + expect_any_instance_of(Post).to receive(:rebake!).with( + invalidate_oneboxes: true, + priority: :low, + ) - TopicLink.create!( - topic_id: topic.id, - post_id: post.id, - user_id: user.id, - url: pr_url, - domain: "github.com", - ) - end - - it "rebakes posts with oneboxed PR links" do - expect_any_instance_of(Post).to receive(:rebake!).with( - invalidate_oneboxes: true, - priority: :low, - ) - described_class.new.execute(pr_url: pr_url) - end - - it "matches URLs with path suffixes" do - TopicLink.create!( - topic_id: topic.id, - post_id: post.id, - user_id: user.id, - url: "#{pr_url}/files", - domain: "github.com", - ) - - post_ids = - TopicLink - .where(url: pr_url) - .or(TopicLink.where("url LIKE ?", "#{pr_url}%")) - .pluck(:post_id) - - expect(post_ids).to include(post.id) - end + described_class.new.execute(pr_url:) end - context "with inline PR link (not oneboxed)" do - fab!(:post) { Fabricate(:post, topic: topic, user: user) } + it "does not rebake posts with plain links or inline oneboxes" do + create_post_with_link(%(plain link)) + create_post_with_link(%(inline onebox)) - before do - post.update!(cooked: <<~HTML) -Check out this PR for details.
- HTML + expect_any_instance_of(Post).not_to receive(:rebake!) - TopicLink.create!( - topic_id: topic.id, - post_id: post.id, - user_id: user.id, - url: pr_url, - domain: "github.com", - ) - end - - it "does not rebake posts with only inline links" do - expect_any_instance_of(Post).not_to receive(:rebake!) - described_class.new.execute(pr_url: pr_url) - end + described_class.new.execute(pr_url:) end - context "with no matching posts" do - it "completes without error" do - expect { described_class.new.execute(pr_url: pr_url) }.not_to raise_error - end + it "matches PR URLs with path suffixes like /files or /commits" do + post = create_post_with_link(<<~HTML) + + HTML + + TopicLink.create!(topic:, post:, user:, url: "#{pr_url}/files", domain:) + + expect_any_instance_of(Post).to receive(:rebake!).with( + invalidate_oneboxes: true, + priority: :low, + ) + + described_class.new.execute(pr_url:) end end end