From 32a8c39ca222a096374a1d2e13fcdb3f41e6dcba Mon Sep 17 00:00:00 2001 From: Daniel Uber Date: Tue, 28 Sep 2021 09:20:49 -0500 Subject: [PATCH] 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. --- app/models/github_issue.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/models/github_issue.rb b/app/models/github_issue.rb index 5df1940ce..a5c1c5b05 100644 --- a/app/models/github_issue.rb +++ b/app/models/github_issue.rb @@ -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