mirror of
https://github.com/discourse/discourse.git
synced 2024-12-19 21:04:22 +08:00
97e2b353f6
Followup 560e8aff75
GitHub auth tokens cannot be made with permissions to
access multiple organisations. This is quite limiting.
This commit changes the site setting to be a "secret list"
type, which allows for a key/value mapping where the value
is treated like a password in the UI.
Now when a GitHub URL is requested for oneboxing, the
org name from the URL is used to determine which token
to use for the request.
Just in case anyone used the old site setting already,
there is a migration to create a `default` entry
with that token in the new list setting, and for
a period of time we will consider that token valid to
use for all GitHub oneboxes as well.
94 lines
2.5 KiB
Ruby
94 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Onebox::Engine::GithubActionsOnebox do
|
|
describe "PR check run" do
|
|
let(:pr_run_uri) { "https://api.github.com/repos/discourse/discourse/pulls/13128" }
|
|
let(:run_uri) { "https://api.github.com/repos/discourse/discourse/check-runs/2660861130" }
|
|
|
|
before do
|
|
stub_request(:get, pr_run_uri).to_return(
|
|
status: 200,
|
|
body: onebox_response("githubactions_pr"),
|
|
)
|
|
|
|
stub_request(:get, run_uri).to_return(
|
|
status: 200,
|
|
body: onebox_response("githubactions_pr_run"),
|
|
)
|
|
end
|
|
|
|
include_context "with engines" do
|
|
let(:link) do
|
|
"https://github.com/discourse/discourse/pull/13128/checks?check_run_id=2660861130"
|
|
end
|
|
end
|
|
it_behaves_like "an engine"
|
|
|
|
describe "#to_html" do
|
|
it "includes status" do
|
|
expect(html).to include("success")
|
|
end
|
|
|
|
it "includes title" do
|
|
expect(html).to include("simplify post and topic deletion language")
|
|
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, run_uri).with(
|
|
headers: {
|
|
"Authorization" => "Bearer github_pat_1234",
|
|
},
|
|
)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "GitHub Actions run" do
|
|
let(:pr_run_uri) { "https://api.github.com/repos/discourse/discourse/actions/runs/873214216" }
|
|
|
|
before do
|
|
stub_request(:get, pr_run_uri).to_return(
|
|
status: 200,
|
|
body: onebox_response("githubactions_actions_run"),
|
|
)
|
|
end
|
|
|
|
include_context "with engines" do
|
|
let(:link) { "https://github.com/discourse/discourse/actions/runs/873214216" }
|
|
end
|
|
it_behaves_like "an engine"
|
|
|
|
describe "#to_html" do
|
|
it "includes status" do
|
|
expect(html).to include("success")
|
|
end
|
|
|
|
it "includes title" do
|
|
expect(html).to include("Remove deleted_by_author key")
|
|
end
|
|
|
|
it "includes action name" do
|
|
expect(html).to include("Linting")
|
|
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, pr_run_uri).with(
|
|
headers: {
|
|
"Authorization" => "Bearer github_pat_1234",
|
|
},
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|