mirror of
https://github.com/discourse/discourse.git
synced 2024-12-26 11:53:42 +08:00
f5cbc3e3b8
Followup 560e8aff75
The linked commit allowed oneboxing private GitHub PRs,
issues, commits, and so on, but it didn't actually allow
oneboxing the root repo e.g https://github.com/discourse/discourse-reactions
We didn't have an engine for this, we were relying on OpenGraph
tags on the HTML rendering of the page like we do with other
oneboxes.
To fix this, we needed a new github engine for repos specifically.
Also, this commit adds a `data-github-private-repo` attribute to
PR, issue, and repo onebox HTML so we have an indicator of
whether the repo was private, which can be used for theme components
and so on.
59 lines
1.8 KiB
Ruby
59 lines
1.8 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Onebox::Engine::GithubIssueOnebox do
|
|
let(:issue_uri) { "https://api.github.com/repos/discourse/discourse/issues/1" }
|
|
let(:repo_uri) { "https://api.github.com/repos/discourse/discourse" }
|
|
let(:repo_response) { onebox_response("githubrepo") }
|
|
|
|
before do
|
|
stub_request(:get, issue_uri).to_return(
|
|
status: 200,
|
|
body: onebox_response("github_issue_onebox"),
|
|
)
|
|
stub_request(:get, repo_uri).to_return(status: 200, body: repo_response)
|
|
end
|
|
|
|
include_context "with engines" do
|
|
let(:link) { "https://github.com/discourse/discourse/issues/1" }
|
|
end
|
|
it_behaves_like "an engine"
|
|
|
|
describe "#to_html" do
|
|
it "sanitizes the input and transform the emoji into an img tag" do
|
|
sanitized_label =
|
|
'Test <img src="/images/emoji/twitter/+1.png?v=12" title="+1" class="emoji" alt="+1" loading="lazy" width="20" height="20">'
|
|
|
|
expect(html).to include(sanitized_label)
|
|
end
|
|
|
|
it "sets the data-github-private-repo attr to false" do
|
|
expect(html).to include("data-github-private-repo=\"false\"")
|
|
end
|
|
|
|
context "when the PR is in a private repo" do
|
|
let(:repo_response) do
|
|
resp = MultiJson.load(onebox_response("githubrepo"))
|
|
resp["private"] = true
|
|
MultiJson.dump(resp)
|
|
end
|
|
|
|
it "sets the data-github-private-repo attr to true" do
|
|
expect(html).to include("data-github-private-repo=\"true\"")
|
|
end
|
|
end
|
|
|
|
context "when github_onebox_access_token is configured" do
|
|
before { SiteSetting.github_onebox_access_tokens = "discourse|github_pat_1234" }
|
|
|
|
it "sends it as part of the request" do
|
|
html
|
|
expect(WebMock).to have_requested(:get, issue_uri).with(
|
|
headers: {
|
|
"Authorization" => "Bearer github_pat_1234",
|
|
},
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|