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
35
35
exposed-modules :
36
36
Arguments
37
37
AutomationDetails
38
+ FilePath
38
39
Fingerprint
39
40
Scan
40
41
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
35
35
import Data.Aeson (Value , decode , encode )
36
36
import Data.ByteString.Lazy
37
37
import Data.String
38
+ import FilePath qualified
38
39
import Fingerprint qualified
39
40
import GitHub.REST
40
41
import System.Environment (getEnvironment )
@@ -72,7 +73,7 @@ annotate :: Context -> ByteString -> IO ()
72
73
annotate context output = do
73
74
env <- getEnvironment
74
75
let annotated = AutomationDetails. add env (category context) <$> value
75
- let annotated' = Fingerprint. fill <$> annotated
76
+ let annotated' = FilePath. normalize . Fingerprint. fill <$> annotated
76
77
case annotated' of
77
78
Nothing -> die $ " invalid encoding\n " <> show output <> " \n "
78
79
Just output' -> send context $ encode output'
You can’t perform that action at this time.
0 commit comments