lib/onebox/engine/github_pullrequest_onebox.rb in onebox-2.2.12 vs lib/onebox/engine/github_pullrequest_onebox.rb in onebox-2.2.13

- old
+ new

@@ -1,15 +1,20 @@ # frozen_string_literal: true +require_relative '../mixins/github_body' + module Onebox module Engine class GithubPullRequestOnebox include Engine include LayoutSupport include JSON + include Onebox::Mixins::GithubBody - matches_regexp Regexp.new("^https?://(?:www\\.)?(?:(?:\\w)+\\.)?(github)\\.com(?:/)?(?:.)*/pull/") + GITHUB_COMMENT_REGEX = /(<!--.*?-->\r\n)/ + + matches_regexp(/^https?:\/\/(?:www\.)?(?:(?:\w)+\.)?(github)\.com(?:\/)?(?:.)*\/pull/) always_https def url "https://api.github.com/repos/#{match[:owner]}/#{match[:repository]}/pulls/#{match[:number]}" end @@ -18,11 +23,10 @@ def match @match ||= @url.match(%r{github\.com/(?<owner>[^/]+)/(?<repository>[^/]+)/pull/(?<number>[^/]+)}) end - GITHUB_COMMENT_REGEX = /(<!--.*?-->\r\n)/ def data result = raw.clone result['link'] = link created_at = Time.parse(result['created_at']) @@ -31,11 +35,10 @@ result['created_at_time'] = created_at.strftime("%T") ulink = URI(link) result['domain'] = "#{ulink.host}/#{ulink.path.split('/')[1]}/#{ulink.path.split('/')[2]}" - body = (result['body'] || '').gsub(GITHUB_COMMENT_REGEX, '') - result['body'] = body.present? ? body : nil + result['body'], result['excerpt'] = compute_body(result['body']) result end end end