1
1
mirror of https://github.com/github/semantic.git synced 2024-12-23 06:41:45 +03:00

Return Output from json, split, summary, and patch

This commit is contained in:
joshvera 2016-08-09 18:51:44 -04:00
parent 11863b8748
commit 2933a24d45
4 changed files with 5 additions and 6 deletions

View File

@ -9,7 +9,6 @@ import Alignment
import Category import Category
import Data.Aeson as A hiding (json) import Data.Aeson as A hiding (json)
import Data.Bifunctor.Join import Data.Bifunctor.Join
import Data.ByteString.Builder
import Data.Record import Data.Record
import qualified Data.Text as T import qualified Data.Text as T
import Data.These import Data.These
@ -23,7 +22,7 @@ import Term
-- | Render a diff to a string representing its JSON. -- | Render a diff to a string representing its JSON.
json :: (HasField fields Category, HasField fields Range) => Renderer (Record fields) json :: (HasField fields Category, HasField fields Range) => Renderer (Record fields)
json blobs diff = toS . toLazyByteString . fromEncoding . pairs $ "rows" .= annotateRows (alignDiff (source <$> blobs) diff) <> "oids" .= (oid <$> blobs) <> "paths" .= (path <$> blobs) json blobs diff = JSONOutput $ "rows" .= annotateRows (alignDiff (source <$> blobs) diff) <> "oids" .= (oid <$> blobs) <> "paths" .= (path <$> blobs)
where annotateRows = fmap (fmap NumberedLine) . numberedRows where annotateRows = fmap (fmap NumberedLine) . numberedRows
newtype NumberedLine a = NumberedLine (Int, a) newtype NumberedLine a = NumberedLine (Int, a)

View File

@ -27,7 +27,7 @@ truncatePatch _ blobs = pack $ header blobs <> "#timed_out\nTruncating diff: tim
-- | Render a diff in the traditional patch format. -- | Render a diff in the traditional patch format.
patch :: HasField fields Range => Renderer (Record fields) patch :: HasField fields Range => Renderer (Record fields)
patch blobs diff = pack $ case getLast (foldMap (Last . Just) string) of patch blobs diff = PatchOutput . pack $ case getLast (foldMap (Last . Just) string) of
Just c | c /= '\n' -> string <> "\n\\ No newline at end of file\n" Just c | c /= '\n' -> string <> "\n\\ No newline at end of file\n"
_ -> string _ -> string
where string = header blobs <> mconcat (showHunk blobs <$> hunks diff blobs) where string = header blobs <> mconcat (showHunk blobs <$> hunks diff blobs)

View File

@ -83,7 +83,7 @@ splitPatchToClassName patch = stringValue $ "patch " <> case patch of
-- | Render a diff as an HTML split diff. -- | Render a diff as an HTML split diff.
split :: (HasField fields Category, HasField fields Cost, HasField fields Range) => Renderer (Record fields) split :: (HasField fields Category, HasField fields Cost, HasField fields Range) => Renderer (Record fields)
split blobs diff = TL.toStrict . renderHtml split blobs diff = SplitOutput $ TL.toStrict . renderHtml
. docTypeHtml . docTypeHtml
. ((head $ link ! A.rel "stylesheet" ! A.href "style.css") <>) . ((head $ link ! A.rel "stylesheet" ! A.href "style.css") <>)
. body . body

View File

@ -3,12 +3,12 @@ module Renderer.Summary where
import Category import Category
import Prologue import Prologue
import Renderer import Renderer
import Data.Aeson
import Data.Record import Data.Record
import Range import Range
import DiffSummary import DiffSummary
import Source import Source
import Data.Aeson
summary :: (HasField fields Category, HasField fields Range) => Renderer (Record fields) summary :: (HasField fields Category, HasField fields Range) => Renderer (Record fields)
summary blobs diff = toS . encode $ summaries >>= annotatedSummaries summary blobs diff = SummaryOutput $ "summaries" .= (summaries >>= annotatedSummaries)
where summaries = diffSummaries (source <$> blobs) diff where summaries = diffSummaries (source <$> blobs) diff