From 266e165885523cd0834d33abd7b38495515e6e1b Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Mon, 24 Oct 2022 22:26:48 +0300 Subject: [PATCH] FIX: Use only first line from commit message (#18724) Linking a commit from a GitHub pull request included the complete commit message, instead of just the first line. The rest of the commit message will be added to the body of the Onebox. --- lib/onebox/engine/github_pull_request_onebox.rb | 2 +- lib/onebox/templates/githubpullrequest.mustache | 2 +- spec/lib/onebox/engine/github_pull_request_onebox_spec.rb | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/onebox/engine/github_pull_request_onebox.rb b/lib/onebox/engine/github_pull_request_onebox.rb index 403c62f4b2c..1ef23815cc9 100644 --- a/lib/onebox/engine/github_pull_request_onebox.rb +++ b/lib/onebox/engine/github_pull_request_onebox.rb @@ -40,7 +40,7 @@ module Onebox result['body'], result['excerpt'] = compute_body(result['body']) if result['commit'] = load_commit(link) - result['body'], result['excerpt'] = compute_body(result['commit']['body']) + result['body'], result['excerpt'] = compute_body(result['commit']['commit']['message'].lines[1..].join) elsif result['comment'] = load_comment(link) result['body'], result['excerpt'] = compute_body(result['comment']['body']) elsif result['discussion'] = load_review(link) diff --git a/lib/onebox/templates/githubpullrequest.mustache b/lib/onebox/templates/githubpullrequest.mustache index 8b0ee6378a7..5868ba2e823 100644 --- a/lib/onebox/templates/githubpullrequest.mustache +++ b/lib/onebox/templates/githubpullrequest.mustache @@ -26,7 +26,7 @@
{{#commit}}

- {{commit.message}} + {{commit.message.lines.first}}

diff --git a/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb b/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb index c6ab147da4c..24f62fe08bd 100644 --- a/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb +++ b/spec/lib/onebox/engine/github_pull_request_onebox_spec.rb @@ -59,7 +59,9 @@ RSpec.describe Onebox::Engine::GithubPullRequestOnebox do end it "includes commit name" do - expect(html).to include("Add audio onebox") + 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") end end