2021-05-26 05:41:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Onebox::Engine::GithubPullRequestOnebox do
|
2024-07-11 06:15:48 -04:00
|
|
|
let(:gh_link) { "https://github.com/discourse/discourse/pull/1253/" }
|
|
|
|
let(:api_uri) { "https://api.github.com/repos/discourse/discourse/pulls/1253" }
|
FEATURE: Allow oneboxing private GitHub repo URLs and add private indicator to HTML (#27947)
Followup 560e8aff75e4bde67bb162e8fdea52e704a19f81
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.
2024-07-18 22:21:45 -04:00
|
|
|
let(:response) { onebox_response(described_class.onebox_name) }
|
2021-05-26 05:41:35 -04:00
|
|
|
|
FEATURE: Allow oneboxing private GitHub repo URLs and add private indicator to HTML (#27947)
Followup 560e8aff75e4bde67bb162e8fdea52e704a19f81
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.
2024-07-18 22:21:45 -04:00
|
|
|
before { stub_request(:get, api_uri).to_return(status: 200, body: response) }
|
2021-05-26 05:41:35 -04:00
|
|
|
|
2024-07-11 06:15:48 -04:00
|
|
|
include_context "with engines" do
|
|
|
|
let(:link) { gh_link }
|
|
|
|
end
|
2021-05-26 05:41:35 -04:00
|
|
|
it_behaves_like "an engine"
|
|
|
|
|
|
|
|
describe "#to_html" do
|
|
|
|
it "includes pull request author" do
|
|
|
|
expect(html).to include("jamesaanderson")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes repository name" do
|
|
|
|
expect(html).to include("discourse")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes commit author gravatar" do
|
|
|
|
expect(html).to include("b3e9977094ce189bbb493cf7f9adea21")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes commit time and date" do
|
|
|
|
expect(html).to include("02:05AM - 26 Jul 13")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes number of commits" do
|
|
|
|
expect(html).to include("1")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes number of files changed" do
|
|
|
|
expect(html).to include("4")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes number of additions" do
|
|
|
|
expect(html).to include("19")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "includes number of deletions" do
|
2023-12-04 07:45:19 -05:00
|
|
|
expect(html).to include("5")
|
2021-05-26 05:41:35 -04:00
|
|
|
end
|
|
|
|
|
2021-05-27 05:38:42 -04:00
|
|
|
it "includes the body without comments" do
|
2021-05-26 05:41:35 -04:00
|
|
|
expect(html).to include("http://meta.discourse.org/t/audio-html5-tag/8168")
|
2021-05-27 05:38:42 -04:00
|
|
|
expect(html).not_to include("test comment")
|
2021-05-26 05:41:35 -04:00
|
|
|
end
|
FEATURE: Allow oneboxing private GitHub repo URLs and add private indicator to HTML (#27947)
Followup 560e8aff75e4bde67bb162e8fdea52e704a19f81
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.
2024-07-18 22:21:45 -04:00
|
|
|
|
|
|
|
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(:response) do
|
|
|
|
resp = MultiJson.load(onebox_response(described_class.onebox_name))
|
|
|
|
resp["base"]["repo"]["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
|
2021-05-26 05:41:35 -04:00
|
|
|
end
|
2022-10-06 13:26:04 -04:00
|
|
|
|
|
|
|
context "with commit links" do
|
2024-07-11 06:15:48 -04:00
|
|
|
let(:gh_link) do
|
|
|
|
"https://github.com/discourse/discourse/pull/1253/commits/d7d3be1130c665cc7fab9f05dbf32335229137a6"
|
|
|
|
end
|
FEATURE: Allow oneboxing private GitHub repo URLs and add private indicator to HTML (#27947)
Followup 560e8aff75e4bde67bb162e8fdea52e704a19f81
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.
2024-07-18 22:21:45 -04:00
|
|
|
let(:pr_commit_url) do
|
|
|
|
"https://api.github.com/repos/discourse/discourse/commits/d7d3be1130c665cc7fab9f05dbf32335229137a6"
|
|
|
|
end
|
2024-07-11 06:15:48 -04:00
|
|
|
|
2022-10-06 13:26:04 -04:00
|
|
|
before do
|
FEATURE: Allow oneboxing private GitHub repo URLs and add private indicator to HTML (#27947)
Followup 560e8aff75e4bde67bb162e8fdea52e704a19f81
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.
2024-07-18 22:21:45 -04:00
|
|
|
stub_request(:get, pr_commit_url).to_return(
|
|
|
|
status: 200,
|
|
|
|
body: onebox_response(described_class.onebox_name + "_commit"),
|
|
|
|
)
|
2022-10-06 13:26:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes commit name" do
|
2022-10-24 15:26:48 -04:00
|
|
|
doc = Nokogiri.HTML5(html)
|
|
|
|
expect(doc.css("h4").text.strip).to eq("Add audio onebox")
|
|
|
|
expect(doc.css(".github-body-container").text).to include(
|
|
|
|
"http://meta.discourse.org/t/audio-html5-tag/8168",
|
|
|
|
)
|
2022-10-06 13:26:04 -04:00
|
|
|
end
|
FEATURE: Allow oneboxing private GitHub repo URLs and add private indicator to HTML (#27947)
Followup 560e8aff75e4bde67bb162e8fdea52e704a19f81
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.
2024-07-18 22:21:45 -04:00
|
|
|
|
|
|
|
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_commit_url).with(
|
|
|
|
headers: {
|
|
|
|
"Authorization" => "Bearer github_pat_1234",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2022-10-06 13:26:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "with comment links" do
|
2024-07-11 06:15:48 -04:00
|
|
|
let(:gh_link) { "https://github.com/discourse/discourse/pull/1253/#issuecomment-21597425" }
|
FEATURE: Allow oneboxing private GitHub repo URLs and add private indicator to HTML (#27947)
Followup 560e8aff75e4bde67bb162e8fdea52e704a19f81
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.
2024-07-18 22:21:45 -04:00
|
|
|
let(:comment_api_url) do
|
|
|
|
"https://api.github.com/repos/discourse/discourse/issues/comments/21597425"
|
|
|
|
end
|
2022-10-06 13:26:04 -04:00
|
|
|
|
2024-07-11 06:15:48 -04:00
|
|
|
before do
|
FEATURE: Allow oneboxing private GitHub repo URLs and add private indicator to HTML (#27947)
Followup 560e8aff75e4bde67bb162e8fdea52e704a19f81
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.
2024-07-18 22:21:45 -04:00
|
|
|
stub_request(:get, comment_api_url).to_return(
|
|
|
|
status: 200,
|
|
|
|
body: onebox_response(described_class.onebox_name + "_comment"),
|
|
|
|
)
|
2022-10-06 13:26:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "includes comment" do
|
|
|
|
expect(html).to include("You've signed the CLA")
|
|
|
|
end
|
FEATURE: Allow oneboxing private GitHub repo URLs and add private indicator to HTML (#27947)
Followup 560e8aff75e4bde67bb162e8fdea52e704a19f81
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.
2024-07-18 22:21:45 -04:00
|
|
|
|
|
|
|
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, api_uri).with(
|
|
|
|
headers: {
|
|
|
|
"Authorization" => "Bearer github_pat_1234",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2022-10-06 13:26:04 -04:00
|
|
|
end
|
2024-07-09 19:39:31 -04:00
|
|
|
|
|
|
|
context "when github_onebox_access_token is configured" do
|
2024-07-14 23:07:36 -04:00
|
|
|
before { SiteSetting.github_onebox_access_tokens = "discourse|github_pat_1234" }
|
2024-07-09 19:39:31 -04:00
|
|
|
|
|
|
|
it "sends it as part of the request" do
|
|
|
|
html
|
2024-07-11 06:15:48 -04:00
|
|
|
expect(WebMock).to have_requested(:get, api_uri).with(
|
2024-07-09 19:39:31 -04:00
|
|
|
headers: {
|
2024-07-14 23:07:36 -04:00
|
|
|
"Authorization" => "Bearer github_pat_1234",
|
2024-07-09 19:39:31 -04:00
|
|
|
},
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2021-05-26 05:41:35 -04:00
|
|
|
end
|