1
1
mirror of https://github.com/github/semantic.git synced 2024-12-24 15:35:14 +03:00

++proto-lens-jsonpb to handle excluding default fields

This commit is contained in:
Timothy Clem 2019-10-03 08:41:30 -07:00
parent 54eb044136
commit 32f6e9dfb9
7 changed files with 18 additions and 18 deletions

View File

@ -12,7 +12,7 @@ RUN wget "https://github.com/protocolbuffers/protobuf/releases/download/v3.7.1/p
RUN go get github.com/golang/protobuf/proto && \
go get github.com/twitchtv/protogen/typemap && \
GO111MODULE=on go get github.com/tclem/proto-lens-jsonpb/protoc-gen-jsonpb_haskell@master
GO111MODULE=on go get github.com/tclem/proto-lens-jsonpb/protoc-gen-jsonpb_haskell@e4d10b77f57ee25beb759a33e63e2061420d3dc2
COPY --from=haskell /root/.cabal/bin/proto-lens-protoc /usr/local/bin/proto-lens-protoc

View File

@ -5,4 +5,4 @@ jobs: $ncpus
source-repository-package
type: git
location: https://github.com/tclem/proto-lens-jsonpb
tag: 2b4cd579144ea10c3bd36bd05122c233dc5334d7
tag: e4d10b77f57ee25beb759a33e63e2061420d3dc2

View File

@ -2,7 +2,7 @@
{-# OPTIONS_GHC -Wno-orphans -Wno-unused-imports -Wno-missing-export-lists #-}
module Proto.Semantic_JSON where
import Prelude(($), (.), (<$>), pure, show)
import Prelude(($), (.), (<$>), pure, show, Maybe(..))
import Data.ProtoLens.Runtime.Lens.Family2 ((^.), (.~), (&))
import Data.Monoid (mconcat)
@ -471,14 +471,14 @@ instance FromJSONPB DiffTreeVertex'DiffTerm where
]
instance ToJSONPB DiffTreeVertex'DiffTerm where
toJSONPB (DiffTreeVertex'Deleted x) = object [ "deleted" .= x ]
toJSONPB (DiffTreeVertex'Inserted x) = object [ "inserted" .= x ]
toJSONPB (DiffTreeVertex'Replaced x) = object [ "replaced" .= x ]
toJSONPB (DiffTreeVertex'Merged x) = object [ "merged" .= x ]
toEncodingPB (DiffTreeVertex'Deleted x) = pairs [ "deleted" .= x ]
toEncodingPB (DiffTreeVertex'Inserted x) = pairs [ "inserted" .= x ]
toEncodingPB (DiffTreeVertex'Replaced x) = pairs [ "replaced" .= x ]
toEncodingPB (DiffTreeVertex'Merged x) = pairs [ "merged" .= x ]
toJSONPB (DiffTreeVertex'Deleted x) = object [ "deleted" .= Just x ]
toJSONPB (DiffTreeVertex'Inserted x) = object [ "inserted" .= Just x ]
toJSONPB (DiffTreeVertex'Replaced x) = object [ "replaced" .= Just x ]
toJSONPB (DiffTreeVertex'Merged x) = object [ "merged" .= Just x ]
toEncodingPB (DiffTreeVertex'Deleted x) = pairs [ "deleted" .= Just x ]
toEncodingPB (DiffTreeVertex'Inserted x) = pairs [ "inserted" .= Just x ]
toEncodingPB (DiffTreeVertex'Replaced x) = pairs [ "replaced" .= Just x ]
toEncodingPB (DiffTreeVertex'Merged x) = pairs [ "merged" .= Just x ]
instance FromJSON DiffTreeVertex'DiffTerm where
parseJSON = parseJSONPB

View File

@ -99,8 +99,8 @@ parseSymbols blobs = do
& P.maybe'span .~ converting #? span
& P.maybe'docs .~ fmap (flip (set P.docstring) defMessage) docs
symbolsToSummarize :: [Text]
symbolsToSummarize = ["Function", "Method", "Class", "Module", "Call", "Send"]
symbolsToSummarize :: [Text]
symbolsToSummarize = ["Function", "Method", "Class", "Module", "Call", "Send"]
data ALaCarteTerm syntax ann = ALaCarteTerm Language [Text] (Term syntax ann)

View File

@ -150,7 +150,7 @@ spec = do
it "produces JSON output" $ do
blobs <- blobsForPaths (Both (Path.relFile "ruby/toc/methods.A.rb") (Path.relFile "ruby/toc/methods.B.rb"))
output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs])
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.B.rb\",\"language\":\"Ruby\",\"changes\":[{\"category\":\"Method\",\"term\":\"self.foo\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":4}},\"changeType\":\"ADDED\"},{\"category\":\"Method\",\"term\":\"bar\",\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":6,\"column\":4}},\"changeType\":\"MODIFIED\"},{\"category\":\"Method\",\"term\":\"baz\",\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":5,\"column\":4}},\"changeType\":\"REMOVED\"}],\"errors\":[]}]}\n" :: ByteString)
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/methods.A.rb -> test/fixtures/ruby/toc/methods.B.rb\",\"language\":\"Ruby\",\"changes\":[{\"category\":\"Method\",\"term\":\"self.foo\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":2,\"column\":4}},\"changeType\":\"ADDED\"},{\"category\":\"Method\",\"term\":\"bar\",\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":6,\"column\":4}},\"changeType\":\"MODIFIED\"},{\"category\":\"Method\",\"term\":\"baz\",\"span\":{\"start\":{\"line\":4,\"column\":1},\"end\":{\"line\":5,\"column\":4}},\"changeType\":\"REMOVED\"}]}]}\n" :: ByteString)
it "produces JSON output if there are parse errors" $ do
blobs <- blobsForPaths (Both (Path.relFile "ruby/toc/methods.A.rb") (Path.relFile "ruby/toc/methods.X.rb"))
@ -160,12 +160,12 @@ spec = do
it "ignores anonymous functions" $ do
blobs <- blobsForPaths (Both (Path.relFile "ruby/toc/lambda.A.rb") (Path.relFile "ruby/toc/lambda.B.rb"))
output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs])
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/lambda.A.rb -> test/fixtures/ruby/toc/lambda.B.rb\",\"language\":\"Ruby\",\"changes\":[],\"errors\":[]}]}\n" :: ByteString)
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/ruby/toc/lambda.A.rb -> test/fixtures/ruby/toc/lambda.B.rb\",\"language\":\"Ruby\"}]}\n" :: ByteString)
it "summarizes Markdown headings" $ do
blobs <- blobsForPaths (Both (Path.relFile "markdown/toc/headings.A.md") (Path.relFile "markdown/toc/headings.B.md"))
output <- runTaskOrDie (diffSummaryBuilder Format.JSON [blobs])
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/markdown/toc/headings.A.md -> test/fixtures/markdown/toc/headings.B.md\",\"language\":\"Markdown\",\"changes\":[{\"category\":\"Heading 1\",\"term\":\"Introduction\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":3,\"column\":16}},\"changeType\":\"REMOVED\"},{\"category\":\"Heading 2\",\"term\":\"Two\",\"span\":{\"start\":{\"line\":5,\"column\":1},\"end\":{\"line\":7,\"column\":4}},\"changeType\":\"MODIFIED\"},{\"category\":\"Heading 3\",\"term\":\"This heading is new\",\"span\":{\"start\":{\"line\":9,\"column\":1},\"end\":{\"line\":11,\"column\":10}},\"changeType\":\"ADDED\"},{\"category\":\"Heading 1\",\"term\":\"Final\",\"span\":{\"start\":{\"line\":13,\"column\":1},\"end\":{\"line\":14,\"column\":4}},\"changeType\":\"ADDED\"}],\"errors\":[]}]}\n" :: ByteString)
runBuilder output `shouldBe` ("{\"files\":[{\"path\":\"test/fixtures/markdown/toc/headings.A.md -> test/fixtures/markdown/toc/headings.B.md\",\"language\":\"Markdown\",\"changes\":[{\"category\":\"Heading 1\",\"term\":\"Introduction\",\"span\":{\"start\":{\"line\":1,\"column\":1},\"end\":{\"line\":3,\"column\":16}},\"changeType\":\"REMOVED\"},{\"category\":\"Heading 2\",\"term\":\"Two\",\"span\":{\"start\":{\"line\":5,\"column\":1},\"end\":{\"line\":7,\"column\":4}},\"changeType\":\"MODIFIED\"},{\"category\":\"Heading 3\",\"term\":\"This heading is new\",\"span\":{\"start\":{\"line\":9,\"column\":1},\"end\":{\"line\":11,\"column\":10}},\"changeType\":\"ADDED\"},{\"category\":\"Heading 1\",\"term\":\"Final\",\"span\":{\"start\":{\"line\":13,\"column\":1},\"end\":{\"line\":14,\"column\":4}},\"changeType\":\"ADDED\"}]}]}\n" :: ByteString)
type Diff' = Diff ListableSyntax (Maybe Declaration) (Maybe Declaration)

View File

@ -1 +1 @@
{"files":[{"path":"test/fixtures/ruby/corpus/method-declaration.A.rb -> test/fixtures/ruby/corpus/method-declaration.B.rb","language":"Ruby","changes":[{"category":"Method","term":"bar","span":{"start":{"line":1,"column":1},"end":{"line":3,"column":4}},"changeType":"MODIFIED"}],"errors":[]}]}
{"files":[{"path":"test/fixtures/ruby/corpus/method-declaration.A.rb -> test/fixtures/ruby/corpus/method-declaration.B.rb","language":"Ruby","changes":[{"category":"Method","term":"bar","span":{"start":{"line":1,"column":1},"end":{"line":3,"column":4}},"changeType":"MODIFIED"}]}]}

View File

@ -1 +1 @@
{"files":[{"path":"test/fixtures/ruby/corpus/method-declaration.A.rb","language":"Ruby","symbols":[{"symbol":"foo","kind":"Method","line":"def foo","span":{"start":{"line":1,"column":1},"end":{"line":2,"column":4}},"docs":null}],"errors":[],"blobOid":""}]}
{"files":[{"path":"test/fixtures/ruby/corpus/method-declaration.A.rb","language":"Ruby","symbols":[{"symbol":"foo","kind":"Method","line":"def foo","span":{"start":{"line":1,"column":1},"end":{"line":2,"column":4}}}]}]}