UX: Improve style of GitHub PR body in emails (#13198)

UX: Improve style of GitHub PR body in emails (#13198)

On the web, we display only an excerpt in a monospace font and the rest of the body is hidden under ellipsis. The email displayed both of them and it did not use the same style. This commit leaves only the excerpt in emails and makes it use a monospace font to display it.

diff --git a/lib/email/styles.rb b/lib/email/styles.rb
index 2c2c207..73c6e08 100644
--- a/lib/email/styles.rb
+++ b/lib/email/styles.rb
@@ -139,8 +139,11 @@ module Email
       style('.github-info div', "display: inline; margin-right: 10px;")
       style('.github-icon-container', 'float: left;')
       style('.github-icon-container *', 'fill: #646464; width: 40px; height: 40px;')
+      style('.github-body-container', 'font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; margin-top: 1em !important;')
       style('.onebox-avatar-inline', ONEBOX_INLINE_AVATAR_STYLE)
 
+      @fragment.css('.github-body-container .excerpt').remove
+
       @fragment.css('aside.quote blockquote > p').each do |p|
         p['style'] = 'padding: 0;'
       end
diff --git a/spec/components/email/styles_spec.rb b/spec/components/email/styles_spec.rb
index d576731..55fe518 100644
--- a/spec/components/email/styles_spec.rb
+++ b/spec/components/email/styles_spec.rb
@@ -185,6 +185,15 @@ describe Email::Styles do
       fragment = html_fragment('<aside class="quote"> <div class="title"> <div class="quote-controls"> <i class="fa fa-chevron-down" title="expand/collapse"></i><a href="/t/xyz/123" title="go to the quoted post" class="back"></a> </div> <img alt="" width="20" height="20" src="https://cdn-enterprise.discourse.org/boingboing/user_avatar/bbs.boingboing.net/techapj/40/54379_1.png" class="avatar">techAPJ: </div> <blockquote> <p>lorem ipsum</p> </blockquote> </aside>')
       expect(fragment.to_s.squish).to match(/^<blockquote.+<\/blockquote>$/)
     end
+
+    it "removes GitHub excerpts" do
+      stub_request(:head, "https://github.com/discourse/discourse/pull/1253").to_return(status: 200, body: "", headers: {})
+      stub_request(:get, "https://api.github.com/repos/discourse/discourse/pulls/1253").to_return(status: 200, body: onebox_response("githubpullrequest"))
+
+      onebox = Oneboxer.onebox("https://github.com/discourse/discourse/pull/1253")
+      fragment = html_fragment(onebox)
+      expect(fragment.css(".github-body-container .excerpt")).to be_empty
+    end
   end
 
   context "replace_secure_media_urls" do

GitHub sha: ccbe3bea

This commit appears in #13198 which was approved by ZogStriP. It was merged by udan11.