From 4dfeee97b1346e72a39f4831fe0328473a4196d5 Mon Sep 17 00:00:00 2001 From: Eli Uriegas Date: Thu, 12 Dec 2019 13:07:01 -0800 Subject: [PATCH 1/2] app: Wrap build sections with details tag Allows for build sections to wrapped in a `
` tag to reduce the spam from the comment itself. Signed-off-by: Eli Uriegas --- app/fetcher/src/CommentRender.hs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/fetcher/src/CommentRender.hs b/app/fetcher/src/CommentRender.hs index be0ca35..d12d331 100644 --- a/app/fetcher/src/CommentRender.hs +++ b/app/fetcher/src/CommentRender.hs @@ -161,12 +161,15 @@ genBuildFailuresTable gen_matched_build_section idx (CommitBuilds.BuildWithLogContext (CommitBuilds.NewCommitBuild (Builds.StorableBuild (DbHelpers.WithId ubuild_id universal_build) build_obj) match_obj _ _) (CommitBuilds.LogContext _ log_lines)) = [ M.heading 4 $ T.unwords [ - circleci_image_link + "
" + , "" + , circleci_image_link , Builds.job_name build_obj , M.parens $ T.pack $ MyUtils.renderFrac idx $ length non_upstream_breakages + , "" ] , T.unwords summary_info_pieces - ] <> code_block_lines + ] <> code_block_lines <> ["
"] where -- job_name = Builds.job_name build_obj From e6865e0f301066225f0164f2f5db3455d66eb179 Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Thu, 12 Dec 2019 15:51:12 -0800 Subject: [PATCH 2/2] refactor details expander --- app/fetcher/src/CommentRender.hs | 16 +++++++--------- app/markdown-dsl/src/Markdown.hs | 33 ++++++++++++++++++++++++++++++-- app/static/index.html | 2 +- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/app/fetcher/src/CommentRender.hs b/app/fetcher/src/CommentRender.hs index d12d331..1129f28 100644 --- a/app/fetcher/src/CommentRender.hs +++ b/app/fetcher/src/CommentRender.hs @@ -1,8 +1,9 @@ + {-# LANGUAGE OverloadedStrings #-} module CommentRender where -import Data.List (partition) +import Data.List (dropWhileEnd, partition) import Data.List.NonEmpty (NonEmpty ((:|))) import qualified Data.List.NonEmpty as NE import Data.Set (Set) @@ -161,17 +162,14 @@ genBuildFailuresTable gen_matched_build_section idx (CommitBuilds.BuildWithLogContext (CommitBuilds.NewCommitBuild (Builds.StorableBuild (DbHelpers.WithId ubuild_id universal_build) build_obj) match_obj _ _) (CommitBuilds.LogContext _ log_lines)) = [ M.heading 4 $ T.unwords [ - "
" - , "" - , circleci_image_link - , Builds.job_name build_obj + circleci_image_link + , job_name , M.parens $ T.pack $ MyUtils.renderFrac idx $ length non_upstream_breakages - , "" ] , T.unwords summary_info_pieces - ] <> code_block_lines <> ["
"] + ] <> M.detailsExpander (M.tagElement "code" $ MatchOccurrences._line_text match_obj) code_block_lines where --- job_name = Builds.job_name build_obj + job_name = Builds.job_name build_obj summary_info_pieces = [ M.bold "Step:" @@ -183,7 +181,7 @@ genBuildFailuresTable code_block_lines = NE.toList $ M.codeBlockFromList $ -- NOTE: this commented-out code just renders the single matched line -- pure $ MatchOccurrences._line_text match_obj - map renderLogLineTuple log_lines + dropWhileEnd T.null $ map renderLogLineTuple log_lines (Builds.NewBuildNumber provider_build_number) = Builds.provider_buildnum universal_build diff --git a/app/markdown-dsl/src/Markdown.hs b/app/markdown-dsl/src/Markdown.hs index 0fd427d..b72cf0a 100644 --- a/app/markdown-dsl/src/Markdown.hs +++ b/app/markdown-dsl/src/Markdown.hs @@ -15,7 +15,7 @@ import qualified HTMLEntities.Builder as HEB import Data.Text.Lazy.Builder (toLazyText) -surround :: [Text] -> Text -> Text +surround :: (Monoid a) => [a] -> a -> a surround brackets = mconcat . (`intersperse` brackets) @@ -40,7 +40,7 @@ codeInline = surround2 "`" sup :: Text -> Text -sup = surround ["", ""] +sup = tagElement "sup" parens :: Text -> Text @@ -51,6 +51,26 @@ bracket :: Text -> Text bracket = surround ["[", "]"] +angleBracket :: Text -> Text +angleBracket = surround ["<", ">"] + + +tagElement :: Text -> Text -> Text +tagElement tag_name = + surround [opening_tag, closing_tag] + where + opening_tag = angleBracket tag_name + closing_tag = angleBracket $ "/" <> tag_name + + +tagElementMultiline :: Text -> [Text] -> [Text] +tagElementMultiline tag_name content = + [opening_tag] ++ content ++ [closing_tag] + where + opening_tag = angleBracket tag_name + closing_tag = angleBracket $ "/" <> tag_name + + supTitle :: Text -> Text -> Text supTitle title = surround brackets where @@ -129,6 +149,15 @@ commaize :: [Text] -> Text commaize = terminate "," +-- | Note that the empty lines padding the markdown +-- inside the html tags are necessary, *as well as* +-- the trailing blank line *after* the closing html tag. +detailsExpander :: Text -> [Text] -> [Text] +detailsExpander heading details = x ++ [""] + where + x = tagElementMultiline "details" $ tagElementMultiline "summary" [heading] <> ([""] ++ details ++ [""]) + + -- | Inserts blank lines between each element paragraphs :: [Text] -> Text paragraphs = T.unlines . intersperse "" diff --git a/app/static/index.html b/app/static/index.html index ea8ba91..1303051 100644 --- a/app/static/index.html +++ b/app/static/index.html @@ -34,7 +34,7 @@

Contents

  • Viability