mirror of
https://github.com/discourse/discourse.git
synced 2024-12-13 05:54:29 +08:00
723d7de18c
* FIX: Improve GitHub folder regexp in Onebox It used to match any GitHub URL that was not matched by the other GitHub Oneboxes and it did not do a good job at handling those. With this change, the generic Onebox will handle the remaining URLs. * FEATURE: Add Onebox for GitHub Actions * FEATURE: Add Onebox for PR check runs * FIX: Remove image from GitHub folder Oneboxes It is a generic, auto-generated image which does not provide any value. * DEV: Add tests * FIX: Strip HTML comments from PR body
32 lines
733 B
Ruby
32 lines
733 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Onebox
|
|
module Mixins
|
|
module GithubBody
|
|
def self.included(klass)
|
|
klass.include(Onebox::Engine)
|
|
klass.include(InstanceMethods)
|
|
end
|
|
|
|
module InstanceMethods
|
|
GITHUB_COMMENT_REGEX = /<!--.*?-->/
|
|
MAX_BODY_LENGTH = 80
|
|
|
|
def compute_body(body)
|
|
if body
|
|
body = body.gsub(GITHUB_COMMENT_REGEX, '').strip
|
|
if body.length == 0
|
|
body = nil
|
|
elsif body.length > MAX_BODY_LENGTH
|
|
excerpt = body[MAX_BODY_LENGTH..body.length].rstrip
|
|
body = body[0..MAX_BODY_LENGTH - 1]
|
|
end
|
|
end
|
|
|
|
[body, excerpt]
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|