A platform for community discussion. Free, open, simple.
UX: Give GitHub oneboxes consistent status headers (#44624)
Alan Guo Xiang Tand1a61ada9089
diff --git a/app/assets/stylesheets/common/base/onebox.scss b/app/assets/stylesheets/common/base/onebox.scssindex a6b48771ec5..9d1e4c0572f 100644--- a/app/assets/stylesheets/common/base/onebox.scss+++ b/app/assets/stylesheets/common/base/onebox.scss@@ -545,6 +545,119 @@ pre.onebox code ol.lines li.selected {}}+aside.onebox.github-onebox {+ --github-onebox-status-color: var(--primary-high);+ --github-onebox-header-background: var(--primary-very-low);+ --onebox-border-color: light-dark(#d1d9e0, #3d444d);+ --onebox-shadow-color: transparent;+ container: github-onebox / inline-size;+ padding: 0;+ overflow: hidden;++ &.--github-open,+ &.--github-approved,+ &.--github-success {+ --github-onebox-status-color: light-dark(#1a7f37, #3fb950);+ --github-onebox-header-background: light-dark(#dafbe1, #183c26);+ }++ &.--github-draft,+ &.--github-unknown {+ --github-onebox-status-color: light-dark(#59636e, #9198a1);+ --github-onebox-header-background: light-dark(#818b981f, #292e36);+ }++ &.--github-changes_requested,+ &.--github-pending {+ --github-onebox-status-color: light-dark(#9a6700, #d29922);+ --github-onebox-header-background: light-dark(#fff8c5, #3d2f12);+ }++ &.--github-merged {+ --github-onebox-status-color: light-dark(#8250df, #a371f7);+ --github-onebox-header-background: light-dark(#fbefff, #2e1b47);+ }++ &.--github-closed,+ &.--github-failure {+ --github-onebox-status-color: light-dark(#d1242f, #f85149);+ --github-onebox-header-background: light-dark(#ffebe9, #3e191c);+ }++ &[class*="--github-"] {+ --onebox-border-color: color-mix(+ in srgb,+ var(--github-onebox-status-color) 35%,+ var(--secondary)+ );+ }++ > .source.github-onebox__header {+ flex-wrap: wrap;+ gap: 0.5em 1em;+ margin: 0;+ padding: 0.5em 1em;+ background: var(--github-onebox-header-background);+ font-size: var(--font-down-1);++ svg {+ flex-shrink: 0;+ fill: currentcolor;+ }+ }++ .github-onebox__label,+ .github-onebox__repo {+ display: flex;+ align-items: center;+ gap: 0.5em;+ min-width: 0;+ overflow-wrap: anywhere;+ }++ .github-onebox__label {+ color: var(--github-onebox-status-color);+ font-weight: var(--token-font-weight-semibold);+ }++ .github-onebox__repo[href] {+ max-width: min(20rem, 50%);+ margin-inline-start: auto;+ color: var(--primary);++ > span {+ @include ellipsis;+ }+ }++ > .onebox-body {+ padding: 0.8em 1em 1em;+ }++ &:is(.githubpullrequest, .githubissue, .githubcommit) > .onebox-body {+ grid-template-columns: minmax(0, 1fr);+ grid-template-areas: "title" "branches" "info" "body";+ }++ &.githubactions .github-row {+ display: block;+ }++ @container github-onebox (width < 28rem) {+ .github-onebox__repo {+ gap: 0;++ > span {+ position: absolute;+ width: 1px;+ height: 1px;+ overflow: hidden;+ clip-path: inset(50%);+ }+ }+ }+}+// Onebox - Github - PR, Commit & Issue.onebox.githubpullrequest,.onebox.githubcommit,diff --git a/config/locales/server.en.yml b/config/locales/server.en.ymlindex 6a57bd7178d..125ec66ba63 100644--- a/config/locales/server.en.yml+++ b/config/locales/server.en.yml@@ -6411,6 +6411,23 @@ en:truncated_file: "This file has been truncated."show_original: "show original"github:+ header:+ repository: "Repository"+ folder: "Folder"+ file: "File"+ binary_file: "Binary file"+ gist: "Gist"+ open_issue: "Open issue"+ closed_issue: "Closed issue"+ commit: "Commit"+ comment: "Comment"+ review: "Review comment"+ pull_request: "Pull request"+ success: "Success"+ failure: "Failure"+ pending: "In progress"+ unknown: "Unknown or queued"+ check_run: "Check run"binary_file: "This file is binary."truncated_file: "This file has been truncated."show_original: "show original"@@ -6424,21 +6441,13 @@ en:review_by: "Review by"pr_summary: "%{commits} commits changed %{changed_files} files with %{additions} additions and %{deletions} deletions"no_description: "Contribute to %{repo} development by creating an account on GitHub."- pr_title:- default: "Pull Request"- draft: "Draft Pull Request"- open: "Open Pull Request"- approved: "Approved Pull Request"- changes_requested: "Changes Requested"- merged: "Merged Pull Request"- closed: "Closed Pull Request"- status_date:- open: "opened"- draft: "drafted"- approved: "approved"- changes_requested: "changes requested"- merged: "merged"- closed: "closed"+ pr_status:+ draft: "Draft"+ open: "Open"+ approved: "Approved"+ changes_requested: "Changes requested"+ merged: "Merged"+ closed: "Closed"discourse_push_notifications:popup:diff --git a/frontend/discourse/app/instance-initializers/post-decorations.js b/frontend/discourse/app/instance-initializers/post-decorations.jsindex 5b1f7d8cb07..92c71285326 100644--- a/frontend/discourse/app/instance-initializers/post-decorations.js+++ b/frontend/discourse/app/instance-initializers/post-decorations.js@@ -87,11 +87,14 @@ export default {api.decorateCookedElement((elem) => {elem.querySelectorAll(".onebox").forEach((onebox) => {+ const source = onebox.querySelector(".source");+ if (!source || source.querySelector("svg, .site-icon")) {+ return;+ }+Object.entries(oneboxTypes).forEach(([key, value]) => {if (onebox.classList.contains(key)) {- onebox- .querySelector(".source")- .insertAdjacentHTML("afterbegin", iconHTML(value));+ source.insertAdjacentHTML("afterbegin", iconHTML(value));}});});diff --git a/lib/excerpt_parser.rb b/lib/excerpt_parser.rbindex ecec99517f5..e3c990ab2a7 100644--- a/lib/excerpt_parser.rb+++ b/lib/excerpt_parser.rb@@ -122,7 +122,8 @@ class ExcerptParser < Nokogiri::XML::SAX::Documentwhen "article"@in_quote = !@keep_onebox_body if attributes.include?(%w[class onebox-body])when "header"- @in_quote = !@keep_onebox_source if attributes.include?(%w[class source])+ classes = attributes.to_h["class"].to_s.split+ @in_quote = !@keep_onebox_source if classes.include?("source")when "div", "span"attributes = Hash[*attributes.flatten]diff --git a/lib/onebox/engine/github_actions_onebox.rb b/lib/onebox/engine/github_actions_onebox.rbindex 0ca0d26482b..7cfe590e098 100644--- a/lib/onebox/engine/github_actions_onebox.rb+++ b/lib/onebox/engine/github_actions_onebox.rb@@ -89,6 +89,17 @@ module Onebox{:link => @url,+ :layout_class => "github-onebox --github-#{status}",+ :repository => "#{match[:org]}/#{match[:repo]}",+ :i18n => {+ header: {+ success: I18n.t("onebox.github.header.success"),+ failure: I18n.t("onebox.github.header.failure"),+ pending: I18n.t("onebox.github.header.pending"),+ unknown: I18n.t("onebox.github.header.unknown"),+ check_run: I18n.t("onebox.github.header.check_run"),+ },+ },:title => title,:name => result["name"],:run_number => result["run_number"],diff --git a/lib/onebox/engine/github_blob_onebox.rb b/lib/onebox/engine/github_blob_onebox.rbindex e876d11d920..108b1fffc13 100644--- a/lib/onebox/engine/github_blob_onebox.rb+++ b/lib/onebox/engine/github_blob_onebox.rb@@ -18,6 +18,10 @@ module Oneboxdef i18n{+ header: {+ binary_file: I18n.t("onebox.github.header.binary_file"),+ file: I18n.t("onebox.github.header.file"),+ },binary_file: I18n.t("onebox.github.binary_file"),truncated_file: I18n.t("onebox.github.truncated_file"),show_original: I18n.t("onebox.github.show_original"),@@ -46,7 +50,11 @@ module Oneboxprivatedef data- super.merge({ domain: "github.com/#{match[:org]}/#{match[:repo]}" })+ super.merge(+ domain: "github.com/#{match[:org]}/#{match[:repo]}",+ repository: "#{match[:org]}/#{match[:repo]}",+ layout_class: "github-onebox",+ )endendenddiff --git a/lib/onebox/engine/github_commit_onebox.rb b/lib/onebox/engine/github_commit_onebox.rbindex 02a0d2e9df9..45d2e472854 100644--- a/lib/onebox/engine/github_commit_onebox.rb+++ b/lib/onebox/engine/github_commit_onebox.rb@@ -64,9 +64,16 @@ module Oneboxresult["committed_at_time"] = committed_at.strftime("%T")result["link"] = link+ result["layout_class"] = "github-onebox"+ result["repository"] = "#{match[:org]}/#{match[:repository]}"ulink = URI(link)result["domain"] = "#{ulink.host}/#{ulink.path.split("/")[1]}/#{ulink.path.split("/")[2]}"- result["i18n"] = { committed: I18n.t("onebox.github.committed") }+ result["i18n"] = {+ committed: I18n.t("onebox.github.committed"),+ header: {+ commit: I18n.t("onebox.github.header.commit"),+ },+ }resultenddiff --git a/lib/onebox/engine/github_folder_onebox.rb b/lib/onebox/engine/github_folder_onebox.rbindex 99471e30163..da655dbc6e1 100644--- a/lib/onebox/engine/github_folder_onebox.rb+++ b/lib/onebox/engine/github_folder_onebox.rb@@ -41,6 +41,13 @@ module Onebox{link: url,+ layout_class: "github-onebox",+ repository: URI(url).path.split("/")[1, 2].join("/"),+ i18n: {+ header: {+ folder: I18n.t("onebox.github.header.folder"),+ },+ },title: Onebox::Helpers.truncate(title, 250),path: display_path,description: display_description,diff --git a/lib/onebox/engine/github_gist_onebox.rb b/lib/onebox/engine/github_gist_onebox.rbindex 65af85b2e30..4231df39cf9 100644--- a/lib/onebox/engine/github_gist_onebox.rb+++ b/lib/onebox/engine/github_gist_onebox.rb@@ -33,6 +33,8 @@ module Onebox@data ||= {title: "gist.github.com",link: link,+ repository: "gist.github.com/#{URI(link).path.split("/")[1]}",+ layout_class: "github-onebox",gist_files: gist_files.take(MAX_FILES),truncated_files?: truncated_files?,i18n: i18n,@@ -41,6 +43,9 @@ module Oneboxdef i18n{+ header: {+ gist: I18n.t("onebox.github.header.gist"),+ },truncated_file: I18n.t("onebox.github.truncated_file"),more_than_three_files: I18n.t("onebox.github.more_than_three_files"),show_original: I18n.t("onebox.github.show_original"),diff --git a/lib/onebox/engine/github_issue_onebox.rb b/lib/onebox/engine/github_issue_onebox.rbindex 23472e352c5..9f9fa2b6358 100644--- a/lib/onebox/engine/github_issue_onebox.rb+++ b/lib/onebox/engine/github_issue_onebox.rb@@ -46,7 +46,14 @@ module Oneboxenddef i18n- { opened: I18n.t("onebox.github.opened"), closed: I18n.t("onebox.github.closed") }+ {+ opened: I18n.t("onebox.github.opened"),+ closed: I18n.t("onebox.github.closed"),+ header: {+ open_issue: I18n.t("onebox.github.header.open_issue"),+ closed_issue: I18n.t("onebox.github.header.closed_issue"),+ },+ }enddef data@@ -64,6 +71,8 @@ module Onebox{link: @url,+ layout_class: "github-onebox",+ repository: "#{ulink.path.split("/")[1]}/#{ulink.path.split("/")[2]}",title: result["title"],body: body,excerpt: excerpt,diff --git a/lib/onebox/engine/github_pull_request_onebox.rb b/lib/onebox/engine/github_pull_request_onebox.rbindex 18ef1aa4f20..7351609071e 100644--- a/lib/onebox/engine/github_pull_request_onebox.rb+++ b/lib/onebox/engine/github_pull_request_onebox.rb@@ -70,7 +70,6 @@ module Oneboxstatus_data = fetch_pr_status(result)result["pr_status"] = status_data&.dig(:status)- result["pr_status_title"] = pr_status_title(result["pr_status"])status_timestamp = status_data&.dig(:timestamp) || result["created_at"]status_date = Time.parse(status_timestamp)@@ -95,9 +94,18 @@ module Oneboxresult["pr"] = trueend+ result["layout_class"] = "github-onebox"+ result["repository"] = "#{org}/#{repo}"+ if result["pr"] && result["pr_status"]+ result["layout_class"] += " --github-#{result["pr_status"]}"+ result["pr_status_data"] = {+ result["pr_status"] => true,+ :label => I18n.t("onebox.github.pr_status.#{result["pr_status"]}"),+ }+ end+result["number"] = match[:number]result["i18n"] = i18n- result["i18n"]["status_date_label"] = status_date_label(result["pr_status"])result["i18n"]["pr_summary"] = I18n.t("onebox.github.pr_summary",{@@ -117,6 +125,12 @@ module Oneboxdef i18n{+ header: {+ pull_request: I18n.t("onebox.github.header.pull_request"),+ comment: I18n.t("onebox.github.header.comment"),+ review: I18n.t("onebox.github.header.review"),+ commit: I18n.t("onebox.github.header.commit"),+ },opened: I18n.t("onebox.github.opened"),commit_by: I18n.t("onebox.github.commit_by"),comment_by: I18n.t("onebox.github.comment_by"),@@ -124,16 +138,6 @@ module Onebox}end- def status_date_label(status)- key = status.presence || "open"- I18n.t("onebox.github.status_date.#{key}")- end-- def pr_status_title(status)- key = status.presence || "default"- I18n.t("onebox.github.pr_title.#{key}")- end-def load_commit(link)if commit_match = link.match(%r{commits/(\h+)})load_json(diff --git a/lib/onebox/engine/github_repo_onebox.rb b/lib/onebox/engine/github_repo_onebox.rbindex db81ca7be51..f35954f0c06 100644--- a/lib/onebox/engine/github_repo_onebox.rb+++ b/lib/onebox/engine/github_repo_onebox.rb@@ -45,6 +45,9 @@ module Oneboxdef dataresult = raw.cloneresult["link"] = link+ result["layout_class"] = "github-onebox"+ result["repository"] = URI(link).path.split("/")[1, 2].join("/")+ result["i18n"] = { header: { repository: I18n.t("onebox.github.header.repository") } }description = result["description"]title = "GitHub - #{result["full_name"]}"diff --git a/lib/onebox/layout.rb b/lib/onebox/layout.rbindex 3e1a1f380c9..bb72579b2e1 100644--- a/lib/onebox/layout.rb+++ b/lib/onebox/layout.rb@@ -35,6 +35,13 @@ module Onebox@uri ||= URI(::Onebox::Helpers.normalize_url_for_output(record[:link]))end+ def header+ name = "#{view.template_name}_header"+ return unless Onebox.options.load_paths.any? { |path| template?(path, name) }++ View.new(name, record).to_html+ end+def details{link: record[:link],@@ -48,6 +55,8 @@ module Oneboxmetadata_2_label: record[:metadata_2_label],metadata_2_value: record[:metadata_2_value],subname: view.template_name,+ header: header,+ layout_class: record[:layout_class],view: view.to_html,}enddiff --git a/lib/onebox/template_support.rb b/lib/onebox/template_support.rbindex 4e09d41103e..f4e4fd82b99 100644--- a/lib/onebox/template_support.rb+++ b/lib/onebox/template_support.rb@@ -6,8 +6,8 @@ module OneboxOnebox.options.load_paths.select(&method(:template?))end- def template?(path)- File.exist?(File.join(path, "#{template_name}.#{template_extension}"))+ def template?(path, name = template_name)+ File.exist?(File.join(path, "#{name}.#{template_extension}"))endendenddiff --git a/lib/onebox/templates/_layout.mustache b/lib/onebox/templates/_layout.mustacheindex 78c4b4650a0..774e5ab2e30 100644--- a/lib/onebox/templates/_layout.mustache+++ b/lib/onebox/templates/_layout.mustache@@ -1,4 +1,8 @@-<aside class="onebox {{subname}}" data-onebox-src="{{link}}">+<aside class="onebox {{subname}}{{#layout_class}} {{layout_class}}{{/layout_class}}" data-onebox-src="{{link}}">+ {{#header}}+ {{{header}}}+ {{/header}}+ {{^header}}<header class="source">{{#favicon}}<img src="{{favicon}}" class="site-icon" alt=""/>@@ -11,6 +15,7 @@<a href="{{link}}" target="_blank" rel="noopener">{{domain}}</a>{{/article_published_time}}</header>+ {{/header}}<article class="onebox-body">{{{view}}}diff --git a/lib/onebox/templates/github/repository.mustache b/lib/onebox/templates/github/repository.mustachenew file mode 100644index 00000000000..e6a8f9ad7e6--- /dev/null+++ b/lib/onebox/templates/github/repository.mustache@@ -0,0 +1,4 @@+ <a class="github-onebox__repo" href="{{link}}" target="_blank" rel="noopener">+ <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path d="M6.766 11.328c-2.063-.25-3.516-1.734-3.516-3.656 0-.781.281-1.625.75-2.188-.203-.515-.172-1.609.063-2.062.625-.078 1.468.25 1.968.703.594-.187 1.219-.281 1.985-.281.765 0 1.39.094 1.953.265.484-.437 1.344-.765 1.969-.687.218.422.25 1.515.046 2.047.5.593.766 1.39.766 2.203 0 1.922-1.453 3.375-3.547 3.64.531.344.89 1.094.89 1.954v1.625c0 .468.391.734.86.547C13.781 14.359 16 11.53 16 8.03 16 3.61 12.406 0 7.984 0 3.563 0 0 3.61 0 8.031a7.88 7.88 0 0 0 5.172 7.422c.422.156.828-.125.828-.547v-1.25c-.219.094-.5.156-.75.156-1.031 0-1.64-.562-2.078-1.609-.172-.422-.36-.672-.719-.719-.187-.015-.25-.093-.25-.187 0-.188.313-.328.625-.328.453 0 .844.281 1.25.86.313.452.64.655 1.031.655s.641-.14 1-.5c.266-.265.47-.5.657-.656"></path></svg>+ <span>{{repository}}</span>+ </a>diff --git a/lib/onebox/templates/githubactions.mustache b/lib/onebox/templates/githubactions.mustacheindex e8ddaaae2ec..de1801de0f3 100644--- a/lib/onebox/templates/githubactions.mustache+++ b/lib/onebox/templates/githubactions.mustache@@ -1,22 +1,4 @@<div class="github-row">- <div class="github-icon-container" title="Commit">- {{#success}}- <svg width="24" height="24" class="github-icon github-icon-success" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M1 12C1 5.925 5.925 1 12 1s11 4.925 11 11-4.925 11-11 11S1 18.075 1 12zm16.28-2.72a.75.75 0 00-1.06-1.06l-5.97 5.97-2.47-2.47a.75.75 0 00-1.06 1.06l3 3a.75.75 0 001.06 0l6.5-6.5z"></path></svg>- {{/success}}-- {{#pending}}- <svg width="24" height="24" class="github-icon github-icon-pending" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 18a6 6 0 100-12 6 6 0 000 12z"></path></svg>- {{/pending}}-- {{#failure}}- <svg width="24" height="24" class="github-icon github-icon-failure" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M1 12C1 5.925 5.925 1 12 1s11 4.925 11 11-4.925 11-11 11S1 18.075 1 12zm8.036-4.024a.75.75 0 00-1.06 1.06L10.939 12l-2.963 2.963a.75.75 0 101.06 1.06L12 13.06l2.963 2.964a.75.75 0 001.061-1.06L13.061 12l2.963-2.964a.75.75 0 10-1.06-1.06L12 10.939 9.036 7.976z"></path></svg>- {{/failure}}-- {{#unknown}}- <svg width="24" height="24" class="github-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M12 18a6 6 0 100-12 6 6 0 000 12z"></path></svg>- {{/unknown}}- </div>-<div class="github-info-container"><h4><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>diff --git a/lib/onebox/templates/githubactions_header.mustache b/lib/onebox/templates/githubactions_header.mustachenew file mode 100644index 00000000000..3ebf965ddad--- /dev/null+++ b/lib/onebox/templates/githubactions_header.mustache@@ -0,0 +1,20 @@+<header class="source github-onebox__header">+ <span class="github-onebox__label">+ <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">+ {{#success}}+ <path fill-rule="evenodd" d="M8 16A8 8 0 1 1 8 0a8 8 0 0 1 0 16Zm3.78-9.72a.751.751 0 0 0-.018-1.042.751.751 0 0 0-1.042-.018L6.75 9.19 5.28 7.72a.751.751 0 0 0-1.042.018.751.751 0 0 0-.018 1.042l2 2a.75.75 0 0 0 1.06 0Z"></path>+ {{/success}}+ {{#failure}}+ <path fill-rule="evenodd" d="M2.343 13.657A8 8 0 1 1 13.658 2.343 8 8 0 0 1 2.343 13.657ZM6.03 4.97a.751.751 0 0 0-1.042.018.751.751 0 0 0-.018 1.042L6.94 8 4.97 9.97a.749.749 0 0 0 .326 1.275.749.749 0 0 0 .734-.215L8 9.06l1.97 1.97a.749.749 0 0 0 1.275-.326.749.749 0 0 0-.215-.734L9.06 8l1.97-1.97a.749.749 0 0 0-.326-1.275.749.749 0 0 0-.734.215L8 6.94Z"></path>+ {{/failure}}+ {{#pending}}+ <path fill-rule="evenodd" d="M8 4a4 4 0 1 1 0 8 4 4 0 0 1 0-8Z"></path>+ {{/pending}}+ {{#unknown}}+ <path fill-rule="evenodd" d="M8 4a4 4 0 1 1 0 8 4 4 0 0 1 0-8Z"></path>+ {{/unknown}}+ </svg>+ <span>{{#run_number}}{{#success}}{{i18n.header.success}}{{/success}}{{#failure}}{{i18n.header.failure}}{{/failure}}{{#pending}}{{i18n.header.pending}}{{/pending}}{{#unknown}}{{i18n.header.unknown}}{{/unknown}}{{/run_number}}{{^run_number}}{{i18n.header.check_run}}{{/run_number}}</span>+ </span>+ {{> github/repository}}+</header>diff --git a/lib/onebox/templates/githubblob_header.mustache b/lib/onebox/templates/githubblob_header.mustachenew file mode 100644index 00000000000..79735a9c1d5--- /dev/null+++ b/lib/onebox/templates/githubblob_header.mustache@@ -0,0 +1,14 @@+<header class="source github-onebox__header">+ <span class="github-onebox__label">+ <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">+ {{#binary}}+ <path fill-rule="evenodd" d="M4 1.75C4 .784 4.784 0 5.75 0h5.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v8.586A1.75 1.75 0 0 1 14.25 15h-9a.75.75 0 0 1 0-1.5h9a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 10 4.25V1.5H5.75a.25.25 0 0 0-.25.25v2a.75.75 0 0 1-1.5 0Zm-4 6C0 6.784.784 6 1.75 6h1.5C4.216 6 5 6.784 5 7.75v2.5A1.75 1.75 0 0 1 3.25 12h-1.5A1.75 1.75 0 0 1 0 10.25ZM6.75 6h1.5a.75.75 0 0 1 .75.75v3.75h.75a.75.75 0 0 1 0 1.5h-3a.75.75 0 0 1 0-1.5h.75v-3h-.75a.75.75 0 0 1 0-1.5Zm-5 1.5a.25.25 0 0 0-.25.25v2.5c0 .138.112.25.25.25h1.5a.25.25 0 0 0 .25-.25v-2.5a.25.25 0 0 0-.25-.25Zm9.75-5.938V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path>+ {{/binary}}+ {{^binary}}+ <path fill-rule="evenodd" d="M4 1.75C4 .784 4.784 0 5.75 0h5.586c.464 0 .909.184 1.237.513l2.914 2.914c.329.328.513.773.513 1.237v8.586A1.75 1.75 0 0 1 14.25 15h-9a.75.75 0 0 1 0-1.5h9a.25.25 0 0 0 .25-.25V6h-2.75A1.75 1.75 0 0 1 10 4.25V1.5H5.75a.25.25 0 0 0-.25.25v2.5a.75.75 0 0 1-1.5 0Zm1.72 4.97a.75.75 0 0 1 1.06 0l2 2a.75.75 0 0 1 0 1.06l-2 2a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l1.47-1.47-1.47-1.47a.75.75 0 0 1 0-1.06ZM3.28 7.78 1.81 9.25l1.47 1.47a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-2-2a.75.75 0 0 1 0-1.06l2-2a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042Zm8.22-6.218V4.25c0 .138.112.25.25.25h2.688l-.011-.013-2.914-2.914-.013-.011Z"></path>+ {{/binary}}+ </svg>+ <span>{{#binary}}{{i18n.header.binary_file}}{{/binary}}{{^binary}}{{i18n.header.file}}{{/binary}}</span>+ </span>+ {{> github/repository}}+</header>diff --git a/lib/onebox/templates/githubcommit.mustache b/lib/onebox/templates/githubcommit.mustacheindex 5bac6c27123..6f858cbfa1a 100644--- a/lib/onebox/templates/githubcommit.mustache+++ b/lib/onebox/templates/githubcommit.mustache@@ -1,8 +1,4 @@<div class="github-row">- <div class="github-icon-container" title="Commit">- <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M10.86 7c-.45-1.72-2-3-3.86-3-1.86 0-3.41 1.28-3.86 3H0v2h3.14c.45 1.72 2 3 3.86 3 1.86 0 3.41-1.28 3.86-3H14V7h-3.14zM7 10.2c-1.22 0-2.2-.98-2.2-2.2 0-1.22.98-2.2 2.2-2.2 1.22 0 2.2.98 2.2 2.2 0 1.22-.98 2.2-2.2 2.2z"></path></svg>- </div>-<div class="github-info-container"><h4><a href="{{html_url}}" target="_blank" rel="noopener">{{title}}</a>diff --git a/lib/onebox/templates/githubcommit_header.mustache b/lib/onebox/templates/githubcommit_header.mustachenew file mode 100644index 00000000000..6f296d2bae3--- /dev/null+++ b/lib/onebox/templates/githubcommit_header.mustache@@ -0,0 +1,7 @@+<header class="source github-onebox__header">+ <span class="github-onebox__label">+ <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M11.93 8.5a4.002 4.002 0 0 1-7.86 0H.75a.75.75 0 0 1 0-1.5h3.32a4.002 4.002 0 0 1 7.86 0h3.32a.75.75 0 0 1 0 1.5Zm-1.43-.75a2.5 2.5 0 1 0-5 0 2.5 2.5 0 0 0 5 0Z"></path></svg>+ <span>{{i18n.header.commit}}</span>+ </span>+ {{> github/repository}}+</header>diff --git a/lib/onebox/templates/githubfolder_header.mustache b/lib/onebox/templates/githubfolder_header.mustachenew file mode 100644index 00000000000..e400f9c68b7--- /dev/null+++ b/lib/onebox/templates/githubfolder_header.mustache@@ -0,0 +1,7 @@+<header class="source github-onebox__header">+ <span class="github-onebox__label">+ <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M1.75 1A1.75 1.75 0 0 0 0 2.75v10.5C0 14.216.784 15 1.75 15h12.5A1.75 1.75 0 0 0 16 13.25v-8.5A1.75 1.75 0 0 0 14.25 3H7.5a.25.25 0 0 1-.2-.1l-.9-1.2C6.07 1.26 5.55 1 5 1H1.75Z"></path></svg>+ <span>{{i18n.header.folder}}</span>+ </span>+ {{> github/repository}}+</header>diff --git a/lib/onebox/templates/githubgist_header.mustache b/lib/onebox/templates/githubgist_header.mustachenew file mode 100644index 00000000000..4f6386e8f00--- /dev/null+++ b/lib/onebox/templates/githubgist_header.mustache@@ -0,0 +1,7 @@+<header class="source github-onebox__header">+ <span class="github-onebox__label">+ <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M5.97 5.72a.75.75 0 1 1 1.06 1.06L5.81 8l1.22 1.22a.75.75 0 1 1-1.06 1.06L4.22 8.53a.75.75 0 0 1 0-1.06zm3 0a.75.75 0 0 1 1.06 0l1.75 1.75a.75.75 0 0 1 0 1.06l-1.75 1.75a.75.75 0 1 1-1.06-1.06L10.19 8 8.97 6.78a.75.75 0 0 1 0-1.06 M13.25 1c.966 0 1.75.784 1.75 1.75v10.5A1.75 1.75 0 0 1 13.25 15H2.75A1.75 1.75 0 0 1 1 13.25V2.75C1 1.784 1.784 1 2.75 1zM2.75 2.5a.25.25 0 0 0-.25.25v10.5c0 .138.112.25.25.25h10.5a.25.25 0 0 0 .25-.25V2.75a.25.25 0 0 0-.25-.25z"></path></svg>+ <span>{{i18n.header.gist}}</span>+ </span>+ {{> github/repository}}+</header>diff --git a/lib/onebox/templates/githubissue.mustache b/lib/onebox/templates/githubissue.mustacheindex 8f10f8b4cc0..e677b84345b 100644--- a/lib/onebox/templates/githubissue.mustache+++ b/lib/onebox/templates/githubissue.mustache@@ -1,8 +1,4 @@-<div class="github-row">- <div class="github-icon-container" title="Issue" data-github-private-repo="{{is_private}}">- <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>- </div>-+<div class="github-row" data-github-private-repo="{{is_private}}"><div class="github-info-container"><h4><a href="{{link}}" target="_blank" rel="noopener">{{title}}</a>diff --git a/lib/onebox/templates/githubissue_header.mustache b/lib/onebox/templates/githubissue_header.mustachenew file mode 100644index 00000000000..6afdded7c69--- /dev/null+++ b/lib/onebox/templates/githubissue_header.mustache@@ -0,0 +1,7 @@+<header class="source github-onebox__header">+ <span class="github-onebox__label">+ <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M8 9.5a1.5 1.5 0 1 0 0-3 1.5 1.5 0 0 0 0 3Z M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0ZM1.5 8a6.5 6.5 0 1 0 13 0 6.5 6.5 0 0 0-13 0Z"></path></svg>+ <span>{{#closed_at}}{{i18n.header.closed_issue}}{{/closed_at}}{{^closed_at}}{{i18n.header.open_issue}}{{/closed_at}}</span>+ </span>+ {{> github/repository}}+</header>diff --git a/lib/onebox/templates/githubpullrequest.mustache b/lib/onebox/templates/githubpullrequest.mustacheindex d6561c1260f..da83d3fdff9 100644--- a/lib/onebox/templates/githubpullrequest.mustache+++ b/lib/onebox/templates/githubpullrequest.mustache@@ -1,28 +1,4 @@<div class="github-row{{#pr_status}} --gh-status-{{pr_status}}{{/pr_status}}" data-github-private-repo="{{is_private}}">- {{#commit}}- <div class="github-icon-container" title="Commit">- <svg width="60" height="60" class="github-icon" viewBox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M10.5 7.75a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0zm1.43.75a4.002 4.002 0 01-7.86 0H.75a.75.75 0 110-1.5h3.32a4.001 4.001 0 017.86 0h3.32a.75.75 0 110 1.5h-3.32z"></path></svg>- </div>- {{/commit}}-- {{#comment}}- <div class="github-icon-container" title="Comment">- <svg width="60" height="60" class="github-icon" viewBox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M1.5 2.75a.25.25 0 01.25-.25h8.5a.25.25 0 01.25.25v5.5a.25.25 0 01-.25.25h-3.5a.75.75 0 00-.53.22L3.5 11.44V9.25a.75.75 0 00-.75-.75h-1a.25.25 0 01-.25-.25v-5.5zM1.75 1A1.75 1.75 0 000 2.75v5.5C0 9.216.784 10 1.75 10H2v1.543a1.457 1.457 0 002.487 1.03L7.061 10h3.189A1.75 1.75 0 0012 8.25v-5.5A1.75 1.75 0 0010.25 1h-8.5zM14.5 4.75a.25.25 0 00-.25-.25h-.5a.75.75 0 110-1.5h.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0114.25 12H14v1.543a1.457 1.457 0 01-2.487 1.03L9.22 12.28a.75.75 0 111.06-1.06l2.22 2.22v-2.19a.75.75 0 01.75-.75h1a.25.25 0 00.25-.25v-5.5z"></path></svg>- </div>- {{/comment}}-- {{#discussion}}- <div class="github-icon-container" title="Discussion">- <svg width="60" height="60" class="github-icon" viewBox="0 0 16 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M1.679 7.932c.412-.621 1.242-1.75 2.366-2.717C5.175 4.242 6.527 3.5 8 3.5c1.473 0 2.824.742 3.955 1.715 1.124.967 1.954 2.096 2.366 2.717a.119.119 0 010 .136c-.412.621-1.242 1.75-2.366 2.717C10.825 11.758 9.473 12.5 8 12.5c-1.473 0-2.824-.742-3.955-1.715C2.92 9.818 2.09 8.69 1.679 8.068a.119.119 0 010-.136zM8 2c-1.981 0-3.67.992-4.933 2.078C1.797 5.169.88 6.423.43 7.1a1.619 1.619 0 000 1.798c.45.678 1.367 1.932 2.637 3.024C4.329 13.008 6.019 14 8 14c1.981 0 3.67-.992 4.933-2.078 1.27-1.091 2.187-2.345 2.637-3.023a1.619 1.619 0 000-1.798c-.45-.678-1.367-1.932-2.637-3.023C11.671 2.992 9.981 2 8 2zm0 8a2 2 0 100-4 2 2 0 000 4z"></path></svg>- </div>- {{/discussion}}-- {{#pr}}- <div class="github-icon-container" title="{{pr_status_title}}">- <svg width="60" height="60" class="github-icon" viewBox="0 0 12 16" version="1.1" aria-hidden="true"><path fill-rule="evenodd" d="M11 11.28V5c-.03-.78-.34-1.47-.94-2.06C9.46 2.35 8.78 2.03 8 2H7V0L4 3l3 3V4h1c.27.02.48.11.69.31.21.2.3.42.31.69v6.28A1.993 1.993 0 0 0 10 15a1.993 1.993 0 0 0 1-3.72zm-1 2.92c-.66 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2zM4 3c0-1.11-.89-2-2-2a1.993 1.993 0 0 0-1 3.72v6.56A1.993 1.993 0 0 0 2 15a1.993 1.993 0 0 0 1-3.72V4.72c.59-.34 1-.98 1-1.72zm-.8 10c0 .66-.55 1.2-1.2 1.2-.65 0-1.2-.55-1.2-1.2 0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2zM2 4.2C1.34 4.2.8 3.65.8 3c0-.65.55-1.2 1.2-1.2.65 0 1.2.55 1.2 1.2 0 .65-.55 1.2-1.2 1.2z"></path></svg>- </div>- {{/pr}}-<div class="github-info-container">{{#commit}}<h4>@@ -72,10 +48,6 @@{{#pr}}<div class="github-info">- <div class="date">- {{i18n.status_date_label}} <span class="discourse-local-date" data-format="ll" data-date="{{status_date_date}}" data-time="{{status_date_time}}" data-timezone="UTC">{{status_date}}</span>- </div>-<div class="user"><a href="{{user.html_url}}" target="_blank" rel="noopener"><img alt="" src="{{user.avatar_url}}" class="onebox-avatar-inline" width="20" height="20">@@ -83,6 +55,10 @@</a></div>+ <div class="date">+ {{^pr_status}}{{i18n.opened}} {{/pr_status}}<span class="discourse-local-date" data-format="ll" data-date="{{status_date_date}}" data-time="{{status_date_time}}" data-timezone="UTC">{{status_date}}</span>+ </div>+<div class="lines" title="{{i18n.pr_summary}}"><a href="{{html_url}}/files" target="_blank" rel="noopener"><span class="added">+{{additions}}</span>diff --git a/lib/onebox/templates/githubpullrequest_header.mustache b/lib/onebox/templates/githubpullrequest_header.mustachenew file mode 100644index 00000000000..55fdad362c2--- /dev/null+++ b/lib/onebox/templates/githubpullrequest_header.mustache@@ -0,0 +1,35 @@+<header class="source github-onebox__header">+ <span class="github-onebox__label">+ <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true">+ {{#comment}}+ <path fill-rule="evenodd" d="M1.75 1h8.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0 1 10.25 10H7.061l-2.574 2.573A1.458 1.458 0 0 1 2 11.543V10h-.25A1.75 1.75 0 0 1 0 8.25v-5.5C0 1.784.784 1 1.75 1ZM1.5 2.75v5.5c0 .138.112.25.25.25h1a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h3.5a.25.25 0 0 0 .25-.25v-5.5a.25.25 0 0 0-.25-.25h-8.5a.25.25 0 0 0-.25.25Zm13 2a.25.25 0 0 0-.25-.25h-.5a.75.75 0 0 1 0-1.5h.5c.966 0 1.75.784 1.75 1.75v5.5A1.75 1.75 0 0 1 14.25 12H14v1.543a1.458 1.458 0 0 1-2.487 1.03L9.22 12.28a.749.749 0 0 1 .326-1.275.749.749 0 0 1 .734.215l2.22 2.22v-2.19a.75.75 0 0 1 .75-.75h1a.25.25 0 0 0 .25-.25Z"></path>+ {{/comment}}+ {{#discussion}}+ <path fill-rule="evenodd" d="M8 2c1.981 0 3.671.992 4.933 2.078 1.27 1.091 2.187 2.345 2.637 3.023a1.62 1.62 0 0 1 0 1.798c-.45.678-1.367 1.932-2.637 3.023C11.67 13.008 9.981 14 8 14c-1.981 0-3.671-.992-4.933-2.078C1.797 10.83.88 9.576.43 8.898a1.62 1.62 0 0 1 0-1.798c.45-.677 1.367-1.931 2.637-3.022C4.33 2.992 6.019 2 8 2ZM1.679 7.932a.12.12 0 0 0 0 .136c.411.622 1.241 1.75 2.366 2.717C5.176 11.758 6.527 12.5 8 12.5c1.473 0 2.825-.742 3.955-1.715 1.124-.967 1.954-2.096 2.366-2.717a.12.12 0 0 0 0-.136c-.412-.621-1.242-1.75-2.366-2.717C10.824 4.242 9.473 3.5 8 3.5c-1.473 0-2.825.742-3.955 1.715-1.124.967-1.954 2.096-2.366 2.717ZM8 10a2 2 0 1 1-.001-3.999A2 2 0 0 1 8 10Z"></path>+ {{/discussion}}+ {{#commit}}+ <path fill-rule="evenodd" d="M11.93 8.5a4.002 4.002 0 0 1-7.86 0H.75a.75.75 0 0 1 0-1.5h3.32a4.002 4.002 0 0 1 7.86 0h3.32a.75.75 0 0 1 0 1.5Zm-1.43-.75a2.5 2.5 0 1 0-5 0 2.5 2.5 0 0 0 5 0Z"></path>+ {{/commit}}+ {{#pr}}+ {{#pr_status_data.draft}}+ <path fill-rule="evenodd" d="M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1Zm9.5 14a2.25 2.25 0 1 1 0-4.5 2.25 2.25 0 0 1 0 4.5ZM2.5 3.25a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0ZM3.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm9.5 0a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5ZM14 7.5a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Zm0-4.25a1.25 1.25 0 1 1-2.5 0 1.25 1.25 0 0 1 2.5 0Z"></path>+ {{/pr_status_data.draft}}+ {{#pr_status_data.merged}}+ <path fill-rule="evenodd" d="M5.45 5.154A4.25 4.25 0 0 0 9.25 7.5h1.378a2.251 2.251 0 1 1 0 1.5H9.25A5.734 5.734 0 0 1 5 7.123v3.505a2.25 2.25 0 1 1-1.5 0V5.372a2.25 2.25 0 1 1 1.95-.218ZM4.25 13.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm8.5-4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5ZM5 3.25a.75.75 0 1 0 0 .005V3.25Z"></path>+ {{/pr_status_data.merged}}+ {{#pr_status_data.closed}}+ <path fill-rule="evenodd" d="M3.25 1A2.25 2.25 0 0 1 4 5.372v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.251 2.251 0 0 1 3.25 1Zm9.5 5.5a.75.75 0 0 1 .75.75v3.378a2.251 2.251 0 1 1-1.5 0V7.25a.75.75 0 0 1 .75-.75Zm-2.03-5.273a.75.75 0 0 1 1.06 0l.97.97.97-.97a.748.748 0 0 1 1.265.332.75.75 0 0 1-.205.729l-.97.97.97.97a.751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018l-.97-.97-.97.97a.749.749 0 0 1-1.275-.326.749.749 0 0 1 .215-.734l.97-.97-.97-.97a.75.75 0 0 1 0-1.06ZM2.5 3.25a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0ZM3.25 12a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm9.5 0a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Z"></path>+ {{/pr_status_data.closed}}+ {{^pr_status_data.draft}}+ {{^pr_status_data.merged}}+ {{^pr_status_data.closed}}+ <path fill-rule="evenodd" d="M1.5 3.25a2.25 2.25 0 1 1 3 2.122v5.256a2.251 2.251 0 1 1-1.5 0V5.372A2.25 2.25 0 0 1 1.5 3.25Zm5.677-.177L9.573.677A.25.25 0 0 1 10 .854V2.5h1A2.5 2.5 0 0 1 13.5 5v5.628a2.251 2.251 0 1 1-1.5 0V5a1 1 0 0 0-1-1h-1v1.646a.25.25 0 0 1-.427.177L7.177 3.427a.25.25 0 0 1 0-.354ZM3.75 2.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm0 9.5a.75.75 0 1 0 0 1.5.75.75 0 0 0 0-1.5Zm8.25.75a.75.75 0 1 0 1.5 0 .75.75 0 0 0-1.5 0Z"></path>+ {{/pr_status_data.closed}}+ {{/pr_status_data.merged}}+ {{/pr_status_data.draft}}+ {{/pr}}+ </svg>+ <span>{{#comment}}{{i18n.header.comment}}{{/comment}}{{#discussion}}{{i18n.header.review}}{{/discussion}}{{#commit}}{{i18n.header.commit}}{{/commit}}{{#pr}}{{#pr_status_data}}{{label}}{{/pr_status_data}}{{^pr_status_data}}{{i18n.header.pull_request}}{{/pr_status_data}}{{/pr}}</span>+ </span>+ {{> github/repository}}+</header>diff --git a/lib/onebox/templates/githubrepo_header.mustache b/lib/onebox/templates/githubrepo_header.mustachenew file mode 100644index 00000000000..05835e80ee3--- /dev/null+++ b/lib/onebox/templates/githubrepo_header.mustache@@ -0,0 +1,7 @@+<header class="source github-onebox__header">+ <span class="github-onebox__label">+ <svg width="16" height="16" viewBox="0 0 16 16" aria-hidden="true"><path fill-rule="evenodd" d="M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z"></path></svg>+ <span>{{i18n.header.repository}}</span>+ </span>+ {{> github/repository}}+</header>diff --git a/plugins/discourse-github/spec/lib/github_pr_onebox_status_spec.rb b/plugins/discourse-github/spec/lib/github_pr_onebox_status_spec.rbdeleted file mode 100644index b4ec6fc60e2..00000000000--- a/plugins/discourse-github/spec/lib/github_pr_onebox_status_spec.rb+++ /dev/null@@ -1,304 +0,0 @@-# frozen_string_literal: true--RSpec.describe Onebox::Engine::GithubPullRequestOnebox do- let(:gh_link) { "https://github.com/discourse/discourse/pull/1253/" }- let(:api_uri) { "https://api.github.com/repos/discourse/discourse/pulls/1253" }- let(:reviews_api_uri) { "#{api_uri}/reviews" }-- def open_pr_response- resp = MultiJson.load(onebox_response("githubpullrequest"))- resp["state"] = "open"- resp["merged"] = false- resp["draft"] = false- resp- end-- before { enable_current_plugin }-- def onebox_html- Onebox::Engine::GithubPullRequestOnebox.new(gh_link).to_html- end-- describe "PR status" do- context "when github_pr_status_enabled is false" do- before do- SiteSetting.github_pr_status_enabled = false- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(open_pr_response))- end-- it "does not include status class" do- expect(onebox_html).not_to include("--gh-status-")- end- end-- context "when github_pr_status_enabled is true" do- before { SiteSetting.github_pr_status_enabled = true }-- context "with open PR" do- before do- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(open_pr_response))- stub_request(:get, reviews_api_uri).to_return(status: 200, body: "[]")- end-- it "includes open status and shows created_at date" do- html = onebox_html- expect(html).to include("--gh-status-open")- expect(html).to include(I18n.t("onebox.github.status_date.open"))- expect(html).to include('data-date="2013-07-26"')- end- end-- context "when PR is merged" do- before do- resp = open_pr_response- resp["merged"] = true- resp["merged_at"] = "2024-02-15T10:30:00Z"- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(resp))- end-- it "includes merged status and shows merged_at date" do- html = onebox_html- expect(html).to include("--gh-status-merged")- expect(html).to include(I18n.t("onebox.github.status_date.merged"))- expect(html).to include('data-date="2024-02-15"')- end- end-- context "when PR is closed" do- before do- resp = open_pr_response- resp["state"] = "closed"- resp["closed_at"] = "2024-03-20T14:45:00Z"- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(resp))- end-- it "includes closed status and shows closed_at date" do- html = onebox_html- expect(html).to include("--gh-status-closed")- expect(html).to include(I18n.t("onebox.github.status_date.closed"))- expect(html).to include('data-date="2024-03-20"')- end- end-- context "when PR is draft" do- before do- resp = open_pr_response- resp["draft"] = true- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(resp))- end-- it "includes draft status and shows created_at date" do- html = onebox_html- expect(html).to include("--gh-status-draft")- expect(html).to include(I18n.t("onebox.github.status_date.draft"))- expect(html).to include('data-date="2013-07-26"')- end- end-- context "when PR is approved" do- before do- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(open_pr_response))- reviews = [- {- "user" => {- "id" => 1,- },- "state" => "APPROVED",- "submitted_at" => "2024-04-10T09:15:00Z",- },- ]- stub_request(:get, reviews_api_uri).to_return(status: 200, body: MultiJson.dump(reviews))- end-- it "includes approved status and shows review submitted_at date" do- html = onebox_html- expect(html).to include("--gh-status-approved")- expect(html).to include(I18n.t("onebox.github.status_date.approved"))- expect(html).to include('data-date="2024-04-10"')- end- end-- context "when PR has changes requested" do- before do- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(open_pr_response))- reviews = [- {- "user" => {- "id" => 1,- },- "state" => "CHANGES_REQUESTED",- "submitted_at" => "2024-05-05T16:20:00Z",- },- ]- stub_request(:get, reviews_api_uri).to_return(status: 200, body: MultiJson.dump(reviews))- end-- it "includes changes_requested status and shows review submitted_at date" do- html = onebox_html- expect(html).to include("--gh-status-changes_requested")- expect(html).to include(I18n.t("onebox.github.status_date.changes_requested"))- expect(html).to include('data-date="2024-05-05"')- end- end-- context "when PR has both approval and changes requested from different reviewers" do- before do- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(open_pr_response))- reviews = [- {- "user" => {- "id" => 1,- },- "state" => "APPROVED",- "submitted_at" => "2024-05-30T12:00:00Z",- },- {- "user" => {- "id" => 2,- },- "state" => "CHANGES_REQUESTED",- "submitted_at" => "2024-06-01T12:00:00Z",- },- ]- stub_request(:get, reviews_api_uri).to_return(status: 200, body: MultiJson.dump(reviews))- end-- it "shows changes_requested status with its date (takes priority over approved)" do- html = onebox_html- expect(html).to include("--gh-status-changes_requested")- expect(html).not_to include("--gh-status-approved")- expect(html).to include(I18n.t("onebox.github.status_date.changes_requested"))- expect(html).to include('data-date="2024-06-01"')- end- end-- context "when reviewer first requests changes then approves" do- before do- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(open_pr_response))- reviews = [- {- "user" => {- "id" => 1,- },- "state" => "CHANGES_REQUESTED",- "submitted_at" => "2024-01-01T00:00:00Z",- },- {- "user" => {- "id" => 1,- },- "state" => "APPROVED",- "submitted_at" => "2024-01-02T00:00:00Z",- },- ]- stub_request(:get, reviews_api_uri).to_return(status: 200, body: MultiJson.dump(reviews))- end-- it "shows approved status with latest review date (latest review wins)" do- html = onebox_html- expect(html).to include("--gh-status-approved")- expect(html).not_to include("--gh-status-changes_requested")- expect(html).to include(I18n.t("onebox.github.status_date.approved"))- expect(html).to include('data-date="2024-01-02"')- end- end-- context "when reviews API fails" do- before do- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(open_pr_response))- stub_request(:get, reviews_api_uri).to_return(status: 500, body: "error")- end-- it "falls back gracefully without status class and shows opened with created_at date" do- html = onebox_html- expect(html).not_to include("--gh-status-")- expect(html).to include(I18n.t("onebox.github.status_date.open"))- expect(html).to include('data-date="2013-07-26"')- end- end- end- end-- describe "#inline_data" do- let(:onebox) { Onebox::Engine::GithubPullRequestOnebox.new(gh_link) }-- it "returns nil when no token is configured and github_pr_status_enabled is false" do- SiteSetting.github_pr_status_enabled = false- expect(onebox.inline_data).to be_nil- end-- it "returns the title for a private repo when a token is configured and status is disabled" do- SiteSetting.github_pr_status_enabled = false- SiteSetting.github_onebox_access_tokens = "discourse|github_pat_1234"- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(open_pr_response))-- expect(onebox.inline_data).to eq(- title: "Add audio onebox - Pull Request #1253 - discourse/discourse - GitHub",- )- end-- it "returns the commit title when the URL links to a specific commit in the PR" do- SiteSetting.github_onebox_access_tokens = "discourse|github_pat_1234"- sha = "803d023e2307309f8b776ab3b8b7e38ba91c0919"- commit_onebox =- Onebox::Engine::GithubPullRequestOnebox.new(- "https://github.com/discourse/discourse/pull/1253/commits/#{sha}",- )- stub_request(- :get,- "https://api.github.com/repos/discourse/discourse/commits/#{sha}",- ).to_return(- status: 200,- body: MultiJson.dump("sha" => sha, "commit" => { "message" => "Add audio onebox" }),- )-- expect(commit_onebox.inline_data).to eq(- title: "Add audio onebox - discourse/discourse@803d023 - GitHub",- )- end-- context "when github_pr_status_enabled is true" do- before { SiteSetting.github_pr_status_enabled = true }-- it "returns a title with repo and PR number plus a status css class" do- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(open_pr_response))- stub_request(:get, reviews_api_uri).to_return(status: 200, body: "[]")-- expect(onebox.inline_data).to eq(- title: "Add audio onebox - Pull Request #1253 - discourse/discourse - GitHub",- css_class: "--gh-status-open",- )- end-- it "returns the title without a status css class when the status fetch fails" do- stub_request(:get, api_uri).to_return(status: 200, body: MultiJson.dump(open_pr_response))- stub_request(:get, reviews_api_uri).to_return(status: 500, body: "error")-- expect(onebox.inline_data).to eq(- title: "Add audio onebox - Pull Request #1253 - discourse/discourse - GitHub",- )- end- end- end-- describe "#status_date_label" do- let(:onebox) { Onebox::Engine::GithubPullRequestOnebox.new(gh_link) }-- it "returns the 'open' translation for nil status" do- result = onebox.send(:status_date_label, nil)- expect(result).to eq(I18n.t("onebox.github.status_date.open"))- end-- it "returns the 'open' translation for empty status" do- result = onebox.send(:status_date_label, "")- expect(result).to eq(I18n.t("onebox.github.status_date.open"))- end-- it "returns the correct translation for each status" do- %w[open draft approved changes_requested merged closed].each do |status|- result = onebox.send(:status_date_label, status)- expect(result).to eq(I18n.t("onebox.github.status_date.#{status}"))- end- end- end-enddiff --git a/spec/lib/excerpt_parser_spec.rb b/spec/lib/excerpt_parser_spec.rbindex ea7833ad08d..8263e90a1a2 100644--- a/spec/lib/excerpt_parser_spec.rb+++ b/spec/lib/excerpt_parser_spec.rb@@ -40,6 +40,27 @@ RSpec.describe ExcerptParser do)end+ describe ".get_excerpt" do+ let(:html) { <<~HTML }+ <aside class="onebox">+ <header class="custom-header source">Merged discourse/discourse</header>+ <article class="onebox-body">Add audio onebox #5</article>+ </aside>+ HTML++ it "returns only the body text when keep_onebox_body is true and the header has other classes" do+ expect(ExcerptParser.get_excerpt(html, 200, keep_onebox_body: true)).to eq(+ "Add audio onebox #5",+ )+ end++ it "returns only the header text when keep_onebox_source is true and the header has other classes" do+ expect(ExcerptParser.get_excerpt(html, 200, keep_onebox_source: true)).to eq(+ "Merged discourse/discourse",+ )+ end+ end+describe "keep_onebox_body parameter" doit "keeps the body content for external oneboxes" dohtml = <<~HTML.stripdiff --git a/spec/lib/onebox/engine/github_actions_onebox_spec.rb b/spec/lib/onebox/engine/github_actions_onebox_spec.rbindex f3997a525eb..59da5e0d810 100644--- a/spec/lib/onebox/engine/github_actions_onebox_spec.rb+++ b/spec/lib/onebox/engine/github_actions_onebox_spec.rb@@ -25,8 +25,14 @@ RSpec.describe Onebox::Engine::GithubActionsOnebox doit_behaves_like "an engine"describe "#to_html" do- it "includes status" do- expect(html).to include("success")+ it "shows the check type, result and repository in the header" do+ preview = Nokogiri::HTML5.fragment(html)+ header = preview.at_css("aside > header")++ expect(header.at_css(".github-onebox__label").text.strip).to eq("Check run")+ expect(header.at_css("a").text.strip).to eq("discourse/discourse")+ expect(header.at_css("a")["href"]).to eq(link)+ expect(preview.at_css("aside")["class"].split).to include("--github-success")endit "includes title" do@@ -51,12 +57,9 @@ RSpec.describe Onebox::Engine::GithubActionsOnebox dodescribe "GitHub Actions run" dolet(: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+ let(:run_response) { onebox_response("githubactions_actions_run") }++ before { stub_request(:get, pr_run_uri).to_return(status: 200, body: run_response) }include_context "with engines" dolet(:link) { "https://github.com/discourse/discourse/actions/runs/873214216" }@@ -64,14 +67,59 @@ RSpec.describe Onebox::Engine::GithubActionsOnebox doit_behaves_like "an engine"describe "#to_html" do- it "includes status" do- expect(html).to include("success")+ it "shows the workflow result and repository in the header" do+ preview = Nokogiri::HTML5.fragment(html)+ header = preview.at_css("aside > header")++ expect(header.at_css(".github-onebox__label").text.strip).to eq("Success")+ expect(header.at_css("a").text.strip).to eq("discourse/discourse")+ expect(header.at_css("a")["href"]).to eq(link)+ expect(preview.at_css("aside")["class"].split).to include("--github-success")endit "includes title" doexpect(html).to include("Remove deleted_by_author key")end+ it "shows Failure for a failed workflow" do+ run = MultiJson.load(run_response)+ run.merge!("status" => "completed", "conclusion" => "failure")+ stub_request(:get, pr_run_uri).to_return(body: MultiJson.dump(run))++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Failure")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq(+ ["--github-failure"],+ )+ end++ it "shows In progress for a running workflow" do+ run = MultiJson.load(run_response)+ run.merge!("status" => "in_progress", "conclusion" => nil)+ stub_request(:get, pr_run_uri).to_return(body: MultiJson.dump(run))++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("In progress")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq(+ ["--github-pending"],+ )+ end++ it "shows Unknown or queued for a queued workflow" do+ run = MultiJson.load(run_response)+ run.merge!("status" => "queued", "conclusion" => nil)+ stub_request(:get, pr_run_uri).to_return(body: MultiJson.dump(run))++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Unknown or queued")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq(+ ["--github-unknown"],+ )+ end+it "includes action name" doexpect(html).to include("Linting")enddiff --git a/spec/lib/onebox/engine/github_blob_onebox_spec.rb b/spec/lib/onebox/engine/github_blob_onebox_spec.rbindex 3147d76de41..4259de811fd 100644--- a/spec/lib/onebox/engine/github_blob_onebox_spec.rb+++ b/spec/lib/onebox/engine/github_blob_onebox_spec.rb@@ -21,6 +21,14 @@ RSpec.describe Onebox::Engine::GithubBlobOnebox doit_behaves_like "an engine"describe "#to_html" do+ it "shows the preview type and repository in the header" do+ header = Nokogiri::HTML5.fragment(html).at_css("aside > header")++ expect(header.at_css(".github-onebox__label").text.strip).to eq("File")+ expect(header.at_css("a").text.strip).to eq("discourse/onebox")+ expect(header.at_css("a")["href"]).to eq(link)+ end+it "includes file name" doexpect(html).to include("github_blob_onebox.rb")end@@ -37,6 +45,9 @@ RSpec.describe Onebox::Engine::GithubBlobOnebox doexpect(html).not_to include("module Oneboxer")expect(html).to include("This file is binary.")+ expect(Nokogiri::HTML5.fragment(html).at_css(".github-onebox__label").text.strip).to eq(+ "Binary file",+ )endcontext "when github_onebox_access_token is configured" dodiff --git a/spec/lib/onebox/engine/github_commit_onebox_spec.rb b/spec/lib/onebox/engine/github_commit_onebox_spec.rbindex b6eb0e38ebc..ddead50138b 100644--- a/spec/lib/onebox/engine/github_commit_onebox_spec.rb+++ b/spec/lib/onebox/engine/github_commit_onebox_spec.rb@@ -17,6 +17,14 @@ RSpec.describe Onebox::Engine::GithubCommitOnebox doit_behaves_like "an engine"describe "#to_html" do+ it "shows the preview type and repository in the header" do+ header = Nokogiri::HTML5.fragment(html).at_css("aside > header")++ expect(header.at_css(".github-onebox__label").text.strip).to eq("Commit")+ expect(header.at_css("a").text.strip).to eq("discourse/discourse")+ expect(header.at_css("a")["href"]).to eq(link)+ end+it "includes repository name" doexpect(html).to include("discourse/discourse")enddiff --git a/spec/lib/onebox/engine/github_folder_onebox_spec.rb b/spec/lib/onebox/engine/github_folder_onebox_spec.rbindex 65cdcbddb33..a8c9706d01e 100644--- a/spec/lib/onebox/engine/github_folder_onebox_spec.rb+++ b/spec/lib/onebox/engine/github_folder_onebox_spec.rb@@ -16,6 +16,14 @@ RSpec.describe Onebox::Engine::GithubFolderOnebox doit_behaves_like "an engine"describe "#to_html" do+ it "shows the preview type and repository in the header" do+ header = Nokogiri::HTML5.fragment(html).at_css("aside > header")++ expect(header.at_css(".github-onebox__label").text.strip).to eq("Folder")+ expect(header.at_css("a").text.strip).to eq("discourse/discourse")+ expect(header.at_css("a")["href"]).to eq(link)+ end+it "includes link to folder with truncated display path" doexpect(html).to include('<a href="https://github.com/discourse/discourse/tree/main/spec/fixtures" target="_blank" rel="noopener">main/spec/fixtures</a>',diff --git a/spec/lib/onebox/engine/github_gist_onebox_spec.rb b/spec/lib/onebox/engine/github_gist_onebox_spec.rbindex beaee3e8181..5a62f931c33 100644--- a/spec/lib/onebox/engine/github_gist_onebox_spec.rb+++ b/spec/lib/onebox/engine/github_gist_onebox_spec.rb@@ -25,6 +25,14 @@ RSpec.describe Onebox::Engine::GithubGistOnebox doenddescribe "#to_html" do+ it "shows the preview type and repository in the header" do+ header = Nokogiri::HTML5.fragment(html).at_css("aside > header")++ expect(header.at_css(".github-onebox__label").text.strip).to eq("Gist")+ expect(header.at_css("a").text.strip).to eq("gist.github.com/karreiro")+ expect(header.at_css("a")["href"]).to eq(link)+ end+describe "when Gist API responds correctly" doit "includes the link to original page" doexpect(html).to include("https://gist.github.com/karreiro/208fdd59fc4b4c39283b")diff --git a/spec/lib/onebox/engine/github_issue_onebox_spec.rb b/spec/lib/onebox/engine/github_issue_onebox_spec.rbindex 5925e7cadec..875742a87b1 100644--- a/spec/lib/onebox/engine/github_issue_onebox_spec.rb+++ b/spec/lib/onebox/engine/github_issue_onebox_spec.rb@@ -19,6 +19,14 @@ RSpec.describe Onebox::Engine::GithubIssueOnebox doit_behaves_like "an engine"describe "#to_html" do+ it "shows the preview type and repository in the header" do+ header = Nokogiri::HTML5.fragment(html).at_css("aside > header")++ expect(header.at_css(".github-onebox__label").text.strip).to eq("Open issue")+ expect(header.at_css("a").text.strip).to eq("discourse/discourse")+ expect(header.at_css("a")["href"]).to eq(link)+ end+it "sanitizes the input and transform the emoji into an img tag" dosanitized_label ="Test <img src=\"/images/emoji/twitter/+1.png?v=#{Emoji::EMOJI_VERSION}\" title=\"+1\" class=\"emoji\" alt=\"+1\" loading=\"lazy\" width=\"20\" height=\"20\">"@@ -29,6 +37,17 @@ RSpec.describe Onebox::Engine::GithubIssueOnebox doexpect(html).to include("data-github-private-repo=\"false\"")end+ it "shows a closed issue header when the issue has been closed" do+ response = MultiJson.load(onebox_response("github_issue_onebox"))+ response["closed_at"] = "2026-10-15T06:00:00Z"+ response["closed_by"] = response["user"]+ stub_request(:get, issue_uri).to_return(body: MultiJson.dump(response))++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Closed issue")+ end+context "when the PR is in a private repo" dolet(:repo_response) doresp = MultiJson.load(onebox_response("githubrepo"))diff --git a/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb b/spec/lib/onebox/engine/github_pull_request_onebox_spec.rbindex a5063188e17..deeb60c1dd2 100644--- a/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb+++ b/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb@@ -5,7 +5,10 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox dolet(:api_uri) { "https://api.github.com/repos/discourse/discourse/pulls/1253" }let(:response) { onebox_response(described_class.onebox_name) }- before { stub_request(:get, api_uri).to_return(status: 200, body: response) }+ before do+ SiteSetting.stubs(:github_pr_status_enabled).returns(false)+ stub_request(:get, api_uri).to_return(status: 200, body: response)+ endinclude_context "with engines" dolet(:link) { gh_link }@@ -13,16 +16,27 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox doit_behaves_like "an engine"describe "#to_html" do- it "includes pull request title with number" do- expect(html).to include("Add audio onebox (#1253)")+ it "shows a neutral pull request header when PR status is disabled" do+ preview = Nokogiri::HTML5.fragment(html)+ header = preview.at_css("aside > header")++ expect(preview.css("aside > header").size).to eq(1)+ expect(header.at_css(".github-onebox__label").text.strip).to eq("Pull request")+ expect(header.at_css(".github-onebox__label svg")).to be_present+ expect(header.at_css("a").text.strip).to eq("discourse/discourse")+ expect(header.at_css("a")["href"]).to eq(gh_link)+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq([])end- it "includes pull request author" do- expect(html).to include("jamesaanderson")+ it "links the title and parenthesized pull request number together" do+ title_link = Nokogiri::HTML5.fragment(html).at_css("h4 a")++ expect(title_link.text).to eq("Add audio onebox (#1253)")+ expect(title_link["href"]).to eq(gh_link)end- it "includes repository name" do- expect(html).to include("discourse")+ it "includes pull request author" do+ expect(html).to include("jamesaanderson")endit "includes branch names" do@@ -37,20 +51,12 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox doexpect(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 "shows the additions, deletions and change summary" do+ lines = Nokogiri::HTML5.fragment(html).at_css(".lines")- it "includes number of additions" do- expect(html).to include("19")- end-- it "includes number of deletions" do- expect(html).to include("5")+ expect(lines.at_css(".added").text).to eq("+19")+ expect(lines.at_css(".removed").text).to eq("-5")+ expect(lines["title"]).to eq("1 commits changed 4 files with 19 additions and 5 deletions")endit "includes the body without comments" do@@ -73,6 +79,181 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox doexpect(html).to include("data-github-private-repo=\"true\"")endend++ it "shows the review comment header and body for a discussion link" do+ review_link = "#{gh_link}#discussion_r123"+ stub_request(+ :get,+ "https://api.github.com/repos/discourse/discourse/pulls/comments/123",+ ).to_return(body: MultiJson.dump("body" => "Please rename this method."))++ preview = Nokogiri::HTML5.fragment(described_class.new(review_link).to_html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Review comment")+ expect(preview.at_css(".github-body-container").text.strip).to eq(+ "Please rename this method.",+ )+ end++ context "when PR status is enabled" do+ let(:pr_response) do+ MultiJson.load(response).merge("state" => "open", "merged" => false, "draft" => false)+ end++ before do+ SiteSetting.stubs(:github_pr_status_enabled).returns(true)+ stub_request(:get, api_uri).to_return { { body: MultiJson.dump(pr_response) } }+ stub_request(:get, "#{api_uri}/reviews").to_return(body: "[]")+ end++ it "shows Open with the creation date for an unreviewed PR" do+ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Open")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq(["--github-open"])+ expect(preview.at_css(".discourse-local-date")["data-date"]).to eq("2013-07-26")+ end++ it "shows Draft with the creation date for a draft PR" do+ pr_response["draft"] = true++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Draft")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq(["--github-draft"])+ expect(preview.at_css(".discourse-local-date")["data-date"]).to eq("2013-07-26")+ end++ it "shows Merged with the merge date for a merged PR" do+ pr_response.merge!(+ "merged" => true,+ "state" => "closed",+ "merged_at" => "2024-02-15T10:30:00Z",+ )++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Merged")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq(+ ["--github-merged"],+ )+ expect(preview.at_css(".discourse-local-date")["data-date"]).to eq("2024-02-15")+ end++ it "shows Closed with the closing date for an unmerged closed PR" do+ pr_response.merge!("state" => "closed", "closed_at" => "2024-03-20T14:45:00Z")++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Closed")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq(+ ["--github-closed"],+ )+ expect(preview.at_css(".discourse-local-date")["data-date"]).to eq("2024-03-20")+ end++ it "shows Approved with the approval date" do+ reviews = [+ {+ "user" => {+ "id" => 1,+ },+ "state" => "APPROVED",+ "submitted_at" => "2024-04-10T09:15:00Z",+ },+ ]+ stub_request(:get, "#{api_uri}/reviews").to_return(body: MultiJson.dump(reviews))++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Approved")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq(+ ["--github-approved"],+ )+ expect(preview.at_css(".discourse-local-date")["data-date"]).to eq("2024-04-10")+ end++ it "shows Changes requested with the review date" do+ reviews = [+ {+ "user" => {+ "id" => 1,+ },+ "state" => "CHANGES_REQUESTED",+ "submitted_at" => "2024-05-05T16:20:00Z",+ },+ ]+ stub_request(:get, "#{api_uri}/reviews").to_return(body: MultiJson.dump(reviews))++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Changes requested")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq(+ ["--github-changes_requested"],+ )+ expect(preview.at_css(".discourse-local-date")["data-date"]).to eq("2024-05-05")+ end++ it "prioritizes a change request over another reviewer's approval" do+ reviews = [+ {+ "user" => {+ "id" => 1,+ },+ "state" => "CHANGES_REQUESTED",+ "submitted_at" => "2024-06-01T12:00:00Z",+ },+ {+ "user" => {+ "id" => 2,+ },+ "state" => "APPROVED",+ "submitted_at" => "2024-06-02T12:00:00Z",+ },+ ]+ stub_request(:get, "#{api_uri}/reviews").to_return(body: MultiJson.dump(reviews))++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Changes requested")+ expect(preview.at_css(".discourse-local-date")["data-date"]).to eq("2024-06-01")+ end++ it "uses each reviewer's latest review even when API results arrive out of order" do+ reviews = [+ {+ "user" => {+ "id" => 1,+ },+ "state" => "APPROVED",+ "submitted_at" => "2024-01-02T00:00:00Z",+ },+ {+ "user" => {+ "id" => 1,+ },+ "state" => "CHANGES_REQUESTED",+ "submitted_at" => "2024-01-01T00:00:00Z",+ },+ ]+ stub_request(:get, "#{api_uri}/reviews").to_return(body: MultiJson.dump(reviews))++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Approved")+ expect(preview.at_css(".discourse-local-date")["data-date"]).to eq("2024-01-02")+ end++ it "keeps a neutral header and creation date when the reviews API fails" do+ stub_request(:get, "#{api_uri}/reviews").to_return(status: 500, body: "error")++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Pull request")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq([])+ expect(preview.at_css(".discourse-local-date")["data-date"]).to eq("2013-07-26")+ end+ endendcontext "with commit links" do@@ -92,6 +273,7 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox doit "includes commit name" dodoc = Nokogiri.HTML5(html)+ expect(doc.at_css(".github-onebox__label").text.strip).to eq("Commit")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",@@ -125,8 +307,14 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox do)end- it "includes comment" do- expect(html).to include("You've signed the CLA")+ it "keeps the comment header and body when the parent PR is merged" do+ SiteSetting.stubs(:github_pr_status_enabled).returns(true)++ preview = Nokogiri::HTML5.fragment(html)++ expect(preview.at_css(".github-onebox__label").text.strip).to eq("Comment")+ expect(preview.at_css("aside")["class"].split.grep(/\A--github-/)).to eq([])+ expect(preview.at_css(".github-body-container").text).to include("You've signed the CLA")endcontext "when github_onebox_access_token is configured" do@@ -156,6 +344,67 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox doendend+ describe "#inline_data" do+ it "returns nil when no token is configured and github_pr_status_enabled is false" do+ SiteSetting.stubs(:github_pr_status_enabled).returns(false)+ expect(onebox.inline_data).to be_nil+ end++ it "returns the title when a token is configured and PR status is disabled" do+ SiteSetting.stubs(:github_pr_status_enabled).returns(false)+ SiteSetting.github_onebox_access_tokens = "discourse|github_pat_1234"++ expect(onebox.inline_data).to eq(+ title: "Add audio onebox - Pull Request #1253 - discourse/discourse - GitHub",+ )+ end++ it "returns the commit title when the URL links to a specific commit in the PR" do+ SiteSetting.github_onebox_access_tokens = "discourse|github_pat_1234"+ sha = "803d023e2307309f8b776ab3b8b7e38ba91c0919"+ commit_onebox =+ Onebox::Engine::GithubPullRequestOnebox.new(+ "https://github.com/discourse/discourse/pull/1253/commits/#{sha}",+ )+ stub_request(+ :get,+ "https://api.github.com/repos/discourse/discourse/commits/#{sha}",+ ).to_return(+ status: 200,+ body: MultiJson.dump("sha" => sha, "commit" => { "message" => "Add audio onebox" }),+ )++ expect(commit_onebox.inline_data).to eq(+ title: "Add audio onebox - discourse/discourse@803d023 - GitHub",+ )+ end++ context "when github_pr_status_enabled is true" do+ before { SiteSetting.stubs(:github_pr_status_enabled).returns(true) }++ it "returns a title with repo and PR number plus a status css class" do+ pr_response = MultiJson.load(response).merge("state" => "open", "merged" => false)+ stub_request(:get, api_uri).to_return(body: MultiJson.dump(pr_response))+ stub_request(:get, "#{api_uri}/reviews").to_return(status: 200, body: "[]")++ expect(onebox.inline_data).to eq(+ title: "Add audio onebox - Pull Request #1253 - discourse/discourse - GitHub",+ css_class: "--gh-status-open",+ )+ end++ it "returns the title without a status css class when the status fetch fails" do+ pr_response = MultiJson.load(response).merge("state" => "open", "merged" => false)+ stub_request(:get, api_uri).to_return(body: MultiJson.dump(pr_response))+ stub_request(:get, "#{api_uri}/reviews").to_return(status: 500, body: "error")++ expect(onebox.inline_data).to eq(+ title: "Add audio onebox - Pull Request #1253 - discourse/discourse - GitHub",+ )+ end+ end+ end+describe ".===" doit "matches valid GitHub Pull Request URL" dovalid_url = URI("https://github.com/username/repository/pull/123")diff --git a/spec/lib/onebox/engine/github_repo_onebox_spec.rb b/spec/lib/onebox/engine/github_repo_onebox_spec.rbindex da14397d363..0486258c413 100644--- a/spec/lib/onebox/engine/github_repo_onebox_spec.rb+++ b/spec/lib/onebox/engine/github_repo_onebox_spec.rb@@ -13,6 +13,14 @@ RSpec.describe Onebox::Engine::GithubRepoOnebox doit_behaves_like "an engine"describe "#to_html" do+ it "shows the preview type and repository in the header" do+ header = Nokogiri::HTML5.fragment(html).at_css("aside > header")++ expect(header.at_css(".github-onebox__label").text.strip).to eq("Repository")+ expect(header.at_css("a").text.strip).to eq("discourse/discourse")+ expect(header.at_css("a")["href"]).to eq(link)+ end+it "includes the description of the repo" doexpect(html).to include("A platform for community discussion. Free, open, simple.")end@@ -32,6 +40,51 @@ RSpec.describe Onebox::Engine::GithubRepoOnebox doexpect(html).to include("data-github-private-repo=\"false\"")end+ it "respects a customized repository header label" do+ TranslationOverride.upsert!(I18n.locale, "onebox.github.header.repository", "Project")++ expect(Nokogiri::HTML5.fragment(html).at_css(".github-onebox__label").text.strip).to eq(+ "Project",+ )+ end++ context "when header labels are only partially translated" do+ before do+ I18n.backend.store_translations(+ :de,+ onebox: {+ github: {+ header: {+ file: "Datei",+ repository: nil,+ },+ },+ },+ )+ end++ after { I18n.backend.reload! }++ it "falls back for the untranslated repository label" do+ I18n.with_locale(:de) do+ expect(Nokogiri::HTML5.fragment(html).at_css(".github-onebox__label").text.strip).to eq(+ "Repository",+ )+ end+ end+ end++ it "keeps query and fragment parameters out of the displayed repository name" do+ repository_link = "https://github.com/discourse/discourse?tab=readme-ov-file#readme"+ stub_request(:get, %r{\Ahttps://api.github.com/repos/discourse/discourse}).to_return(+ body: response,+ )++ preview = Nokogiri::HTML5.fragment(Onebox::Preview.new(repository_link).to_s)++ expect(preview.at_css(".github-onebox__repo").text.strip).to eq("discourse/discourse")+ end+context "when the PR is in a private repo" dolet(:response) doresp = MultiJson.load(onebox_response(described_class.onebox_name))diff --git a/spec/lib/onebox/layout_spec.rb b/spec/lib/onebox/layout_spec.rbindex ae44df231da..3ae86ad012b 100644--- a/spec/lib/onebox/layout_spec.rb+++ b/spec/lib/onebox/layout_spec.rb@@ -21,5 +21,46 @@ RSpec.describe Onebox::Layout doklass = described_class.new("allowlistedgeneric", record)expect(klass.view.record[:image]).to include("https://discourse.org")end++ it "uses a matching header template in place of the default source header" do+ Dir.mktmpdir do |directory|+ original_options = Onebox.options.to_h+ File.write(+ File.join(directory, "amazon_header.mustache"),+ '<header class="custom-header">{{title}}</header>',+ )+ Onebox.options =+ original_options.merge(load_paths: original_options[:load_paths] + [directory])++ preview =+ Nokogiri::HTML5.fragment(+ described_class.new(+ "amazon",+ { link: "https://example.com", title: "Custom <header>" },+ ).to_html,+ )++ expect(preview.css("aside > header").size).to eq(1)+ expect(preview.at_css(".custom-header").text).to eq("Custom <header>")+ expect(preview.at_css(".source")).to be_nil+ expect(preview.at_css(".onebox-body")).to be_present+ ensure+ Onebox.options = original_options+ end+ end++ it "keeps the default source header when there is no matching header template" do+ preview =+ Nokogiri::HTML5.fragment(+ described_class.new(+ "amazon",+ { link: "https://example.com", favicon: "https://example.com/favicon.png" },+ ).to_html,+ )++ expect(preview.css("aside > header").size).to eq(1)+ expect(preview.at_css(".source a").text).to eq("example.com")+ expect(preview.at_css(".source .site-icon")["src"]).to eq("https://example.com/favicon.png")+ endendend