File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed
Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ library
3535 exposed-modules :
3636 Arguments
3737 AutomationDetails
38+ FilePath
3839 Fingerprint
3940 Scan
4041 Upload
Original file line number Diff line number Diff line change 1+ {-
2+ Copyright 2023 Google LLC
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ https://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+ -}
16+
17+ module FilePath (normalize ) where
18+
19+ import Data.Aeson
20+ import Data.Aeson.KeyMap qualified as KeyMap
21+ import Data.Text qualified as Text
22+
23+ normalize :: Value -> Value
24+ normalize (Object v) = Object $ normalizeObject v
25+ normalize (Array vs) = Array $ fmap normalize vs
26+ normalize v = v
27+
28+ normalizeObject :: Object -> Object
29+ normalizeObject m | Just v <- KeyMap. lookup " artifactLocation" m =
30+ KeyMap. insert " artifactLocation" (normalizeUri v) m
31+ | otherwise = m
32+
33+ normalizeUri :: Value -> Value
34+ normalizeUri (Object m) | Just (String s) <- KeyMap. lookup " uri" m =
35+ Object $ KeyMap. insert " uri" (String $ strip s) m
36+ where
37+ strip x | Just x' <- Text. stripPrefix " ./" x = strip x'
38+ | otherwise = x
39+ normalizeUri v = v
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import AutomationDetails qualified
3535import Data.Aeson (Value , decode , encode )
3636import Data.ByteString.Lazy
3737import Data.String
38+ import FilePath qualified
3839import Fingerprint qualified
3940import GitHub.REST
4041import System.Environment (getEnvironment )
@@ -72,7 +73,7 @@ annotate :: Context -> ByteString -> IO ()
7273annotate context output = do
7374 env <- getEnvironment
7475 let annotated = AutomationDetails. add env (category context) <$> value
75- let annotated' = Fingerprint. fill <$> annotated
76+ let annotated' = FilePath. normalize . Fingerprint. fill <$> annotated
7677 case annotated' of
7778 Nothing -> die $ " invalid encoding\n " <> show output <> " \n "
7879 Just output' -> send context $ encode output'
You can’t perform that action at this time.
0 commit comments