@@ -7,14 +7,17 @@ module Oracle.Validate.DownloadAssets
7
7
)
8
8
where
9
9
10
- import Control.Monad (filterM , forM_ )
10
+ import Control.Monad (filterM )
11
11
import Control.Monad.Trans.Class (lift )
12
- import Core.Types.Basic (Directory (.. ), FileName ( .. ) )
12
+ import Core.Types.Basic (Directory (.. ))
13
13
import Core.Types.Fact
14
14
( Fact (.. )
15
15
, keyHash
16
16
)
17
- import Lib.GitHub (GithubResponseStatusCodeError )
17
+ import Lib.GitHub
18
+ ( GetGithubFileFailure
19
+ , GithubResponseStatusCodeError
20
+ )
18
21
import Lib.JSON.Canonical.Extra (object , (.=) )
19
22
import Oracle.Validate.Types
20
23
( Validate
@@ -42,34 +45,30 @@ import Validation
42
45
( Validation (.. )
43
46
, hoistValidation
44
47
)
45
- import Validation.DownloadFile
46
- ( DownloadedFileFailure (.. )
47
- , renderDownloadedFileFailure
48
- )
49
48
50
49
data AssetValidationFailure
51
50
= AssetValidationSourceFailure SourceDirFailure
52
- | AssetValidationParseError DownloadedFileFailure
53
51
| DownloadAssetsTargetDirNotFound
54
52
| DownloadAssetsTargetDirNotWritable
53
+ | DownloadAssetsGithubError GetGithubFileFailure
55
54
deriving (Show , Eq )
56
55
57
56
instance Monad m => ToJSON m AssetValidationFailure where
58
57
toJSON (AssetValidationSourceFailure failure) =
59
58
object
60
59
[" error" .= (" Source directory validation failed: " <> show failure)]
61
- toJSON (AssetValidationParseError failure) =
62
- object
63
- [ " error"
64
- .= ( " Downloaded file validation failed: "
65
- <> renderDownloadedFileFailure failure
66
- )
67
- ]
68
60
toJSON DownloadAssetsTargetDirNotFound =
69
61
object [" error" .= (" There is no target local directory" :: String )]
70
62
toJSON DownloadAssetsTargetDirNotWritable =
71
63
object
72
64
[" error" .= (" The target local directory is not writable" :: String )]
65
+ toJSON (DownloadAssetsGithubError failure) =
66
+ object
67
+ [ " error"
68
+ .= ( " GitHub error when downloading directory: "
69
+ <> show failure
70
+ )
71
+ ]
73
72
74
73
data DownloadAssetsFailure
75
74
= DownloadAssetsTestRunIdNotFound TestRunId
@@ -113,30 +112,26 @@ checkSourceDirectory
113
112
then Nothing
114
113
else Just SourceDirFailureDirAbsent
115
114
116
- downloadFileAndWriteLocally
115
+ downloadAssetsDirectory
117
116
:: Monad m
118
117
=> Validation m
119
118
-> TestRun
120
119
-> Directory
121
- -> FileName
122
- -> m (Maybe AssetValidationFailure )
123
- downloadFileAndWriteLocally
124
- Validation {githubGetFile, withCurrentDirectory, writeTextFile}
125
- testRun
126
- (Directory targetDir)
127
- (FileName filename) = do
128
- let (Directory sourceDir) = directory testRun
129
- contentE <-
130
- githubGetFile
131
- (repository testRun)
132
- (Just $ commitId testRun)
133
- (FileName $ sourceDir <> " /" <> filename)
134
- case contentE of
135
- Left err -> pure $ Just $ AssetValidationParseError err
136
- Right txt -> do
137
- withCurrentDirectory targetDir
138
- $ writeTextFile filename txt
139
- pure Nothing
120
+ -> m (Maybe GetGithubFileFailure )
121
+ downloadAssetsDirectory validation testRun dir = do
122
+ let sourceDir = directory testRun
123
+ commit = commitId testRun
124
+ repository' = repository testRun
125
+ r <-
126
+ githubDownloadDirectory
127
+ validation
128
+ repository'
129
+ (Just commit)
130
+ sourceDir
131
+ dir
132
+ pure $ case r of
133
+ Left err -> Just err
134
+ Right () -> Nothing
140
135
141
136
validateDownloadAssets
142
137
:: Monad m
@@ -190,15 +185,5 @@ validateAssets dir validation testRun = do
190
185
liftMaybe DownloadAssetsTargetDirNotFound targetDirValidation
191
186
Validated <-
192
187
throwFalse (writable permissions) DownloadAssetsTargetDirNotWritable
193
-
194
- forM_ [" README.md" , " docker-compose.yaml" , " testnet.yaml" ] $ \ filename -> do
195
- fileValidation <-
196
- lift
197
- $ downloadFileAndWriteLocally
198
- validation
199
- testRun
200
- dir
201
- (FileName filename)
202
- throwJusts fileValidation
203
-
204
- pure Validated
188
+ downloadTry <- lift $ downloadAssetsDirectory validation testRun dir
189
+ mapFailure DownloadAssetsGithubError $ throwJusts downloadTry
0 commit comments