If there is no body of the linked issue or PR, don't render markdown (#14804)

* If there is no body of the linked issue or PR, don't render markdown

Return a readable and actionable error to the user when they're
linking a PR that doesn't have a body (and we can't render).

This is not needed if there's a fallback path to render _something_ in
the absence of a body (or if it's safe to just skip the `body` rendered
inside the github issue liquid template partial).

* When there is no issue body to render, just show PR title and link

Set the body to an empty string and let github return an empty html
body.

It would be possible to substitute this with a conditional to only
post if a body was present, or assign processed_html directly if not.

* Don't use github api when we have an empty body

Save a network trip and just replace the processed html body with an
empty string when the issue body was nil.
This commit is contained in:
Daniel Uber 2021-09-28 09:20:49 -05:00 committed by GitHub
parent 00c5af783e
commit 32a8c39ca2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,10 +39,13 @@ class GithubIssue < ApplicationRecord
issue.category = "issue"
end
# despite the counter intuitive name `.markdown` returns HTML rendered
# from the original markdown
issue.processed_html = Github::OauthClient.new.markdown(issue.issue_serialized[:body])
issue.processed_html = if issue.issue_serialized[:body].present?
# despite the counter intuitive name `.markdown` returns HTML rendered
# from the original markdown
Github::OauthClient.new.markdown(issue.issue_serialized[:body])
else
""
end
issue.save!
issue