Skip to content

Commit 2e51137

Browse files
authored
Normalize file URIs which start with './'. (#24)
1 parent 7912380 commit 2e51137

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

hlint-scan.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ library
3535
exposed-modules:
3636
Arguments
3737
AutomationDetails
38+
FilePath
3839
Fingerprint
3940
Scan
4041
Upload

src/FilePath.hs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

src/Scan.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import AutomationDetails qualified
3535
import Data.Aeson (Value, decode, encode)
3636
import Data.ByteString.Lazy
3737
import Data.String
38+
import FilePath qualified
3839
import Fingerprint qualified
3940
import GitHub.REST
4041
import System.Environment (getEnvironment)
@@ -72,7 +73,7 @@ annotate :: Context -> ByteString -> IO ()
7273
annotate 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'

0 commit comments

Comments
 (0)