From 085d62e25feec1b1411f05036bd1788fc2949749 Mon Sep 17 00:00:00 2001 From: Adam Mills Date: Tue, 22 Aug 2023 14:59:19 +1000 Subject: [PATCH] feat: json serialize severity as string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit e488880d6d427ac282aceca51667a4882bb20b6b Author: Kevin Tarhan Date: Wed Aug 9 15:01:19 2023 -0700 Pass linting check commit 997e7efc896e5aaa8b2033018ca6e4ea45233d2d Author: Kevin Tarhan Date: Wed Aug 9 10:26:16 2023 -0700 Overrides severity Marshalling commit 5086d2c9a780f392cdfdb6e9a54a54394e7aad4a Author: Adam Date: Mon Jul 10 08:53:17 2023 +1000 Revert "ci: testing push" This reverts commit b0f98609764c5ebf8d26346e9b1806d6ca9f5d1b. commit b0f98609764c5ebf8d26346e9b1806d6ca9f5d1b Author: Adam Date: Mon Jul 10 08:49:40 2023 +1000 ci: testing push commit f69aa5bd847a3463820606afe35dd4d2085c20f3 Merge: e3d60bc 8b33e69 Author: Adam Mills Date: Mon Jul 10 07:51:54 2023 +1000 Merge branch 'cloudflare:main' into main commit e3d60bc1913b5fe94aa1880ad59c224d9bcefc2a Merge: 9bf8f28 1873dac Author: Adam Mills Date: Mon Jul 10 07:51:06 2023 +1000 Merge pull request #1 from thetradedesk/feature/aam-json-reporter feat: JSON Reporter commit 1873dac33a826984c475672eca610b685dfe6fe1 Author: Adam Date: Fri Jul 7 11:59:29 2023 +1000 PR Fixes commit fea883d4f24744fe0cea304130ff1f32d017eb81 Author: Adam Mills Date: Fri Jul 7 11:51:33 2023 +1000 Apply suggestions from code review Co-authored-by: Mohak Kataria commit 8b33e695f23fbb776faee668242a485e04577ac5 Merge: 9bf8f28 5342d45 Author: Ɓukasz Mierzwa Date: Wed Jul 5 17:51:48 2023 +0100 Merge pull request #669 from cloudflare/dependabot/docker/debian-stable-20230703 Bump debian from stable-20230612 to stable-20230703 commit 5342d4590056b7cd576fab77bbbfa9fc3a782e0f Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed Jul 5 16:15:08 2023 +0000 Bump debian from stable-20230612 to stable-20230703 Bumps debian from stable-20230612 to stable-20230703. --- updated-dependencies: - dependency-name: debian dependency-type: direct:production ... Signed-off-by: dependabot[bot] commit 5d249c71511007a2c31968638425f42ab516a484 Author: Adam Mills Date: Wed Jul 5 12:35:17 2023 +1000 re-disabling code coverage failing build commit 43b226e305bf041611d27e862f9c1cf8284f2be0 Author: Adam Mills Date: Wed Jul 5 12:22:12 2023 +1000 undo ci cahnge commit 9b8cf7e877009f6df1758124bdb8f9512dc0eb68 Author: Adam Mills Date: Wed Jul 5 12:04:42 2023 +1000 ignoring code-coverage failure commit 5e17eb1042d6bc7b433622c7bff29306a684343d Author: Adam Mills Date: Wed Jul 5 11:41:24 2023 +1000 fixing nil check commit d11d70705e9b3040871e8e5e1aa91e8fd7205cc3 Author: Adam Mills Date: Wed Jul 5 11:32:54 2023 +1000 lint commit aae8df0d32ec27bc8266a0f93f91c8306c629323 Author: adam.mills Date: Wed Jul 5 11:14:03 2023 +1000 lint commit 1340dfc098c0b03725e0eed1dbaee562593955f9 Author: adam.mills Date: Wed Jul 5 10:28:00 2023 +1000 added tests commit 6d27461069fb5df0ad0d0f1b302b057da8564bd3 Author: adam.mills Date: Wed Jul 5 09:09:50 2023 +1000 stash: need to do json marshalling --- Dockerfile | 2 +- internal/checks/base.go | 5 +++++ internal/reporter/json_test.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 91213152..4bd0886e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ WORKDIR /src RUN apk add make git RUN make -FROM debian:stable-20230612 +FROM debian:stable-20230703 RUN apt-get update --yes && \ apt-get install --no-install-recommends --yes git ca-certificates && \ rm -rf /var/lib/apt/lists/* diff --git a/internal/checks/base.go b/internal/checks/base.go index 4d7c183e..d51f49d2 100644 --- a/internal/checks/base.go +++ b/internal/checks/base.go @@ -2,6 +2,7 @@ package checks import ( "context" + "encoding/json" "errors" "fmt" @@ -78,6 +79,10 @@ func ParseSeverity(s string) (Severity, error) { } } +func (s Severity) MarshalJSON() ([]byte, error) { + return json.Marshal(s.String()) +} + const ( // Information doesn't count as a problem, it's a comment Information Severity = iota diff --git a/internal/reporter/json_test.go b/internal/reporter/json_test.go index 59040436..7a30b33d 100644 --- a/internal/reporter/json_test.go +++ b/internal/reporter/json_test.go @@ -44,6 +44,6 @@ func TestJSONReporter(t *testing.T) { defer jsonFile.Close() byteValue, err := io.ReadAll(jsonFile) require.NoError(t, err, "Error reading json") - expected := "[{\"reportedPath\":\"\",\"sourcePath\":\"foo.txt\",\"rule\":{\"name\":\"sum errors\",\"type\":\"recording\"},\"problem\":{\"Fragment\":\"syntax error\",\"Lines\":[2],\"Reporter\":\"mock\",\"Text\":\"syntax error\",\"Severity\":3},\"owner\":\"\"}]" + expected := "[{\"reportedPath\":\"\",\"sourcePath\":\"foo.txt\",\"rule\":{\"name\":\"sum errors\",\"type\":\"recording\"},\"problem\":{\"Fragment\":\"syntax error\",\"Lines\":[2],\"Reporter\":\"mock\",\"Text\":\"syntax error\",\"Severity\":\"Fatal\"},\"owner\":\"\"}]" require.Equal(t, expected, string(byteValue)) }