Skip to content

Commit e58503d

Browse files
committed
Minor updates for (String <-> Text <-> Name) changes in compiler
1 parent e26426a commit e58503d

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

Diff for: src/backend/Package/Register.hs

+9-9
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@ badNameMessage name problem =
108108
verifyVersion :: Http.Token -> Memory.Memory -> Pkg.Name -> Text -> Text -> Snap.Snap Pkg.Version
109109
verifyVersion token memory name commitHash rawVersion =
110110
case Pkg.versionFromText rawVersion of
111-
Left problem ->
111+
Nothing ->
112112
Error.string 400 $
113-
"I was given an invalid version: " ++ Text.unpack rawVersion ++ "\n\n" ++ problem
113+
"I was given an invalid version: " ++ Text.unpack rawVersion
114114

115-
Right version ->
115+
Just version ->
116116
do verifyIsNew memory name version
117117
verifyTag token name version commitHash
118118
return version
@@ -147,15 +147,15 @@ getCommitHash token name version =
147147
Error.bytestring 500 "Request to GitHub API failed."
148148

149149
Right body ->
150-
case Decode.parse tagDecoder body of
150+
case Decode.parse tagDecoder (LBS.toStrict body) of
151151
Right hash ->
152152
return hash
153153

154154
Left _ ->
155155
Error.bytestring 500 "Request to GitHub API failed due to unexpected JSON."
156156

157157

158-
tagDecoder :: Decode.Decoder Text
158+
tagDecoder :: Decode.Decoder e Text
159159
tagDecoder =
160160
Decode.at ["object","sha"] Decode.text
161161

@@ -184,7 +184,7 @@ uploadFiles name version time =
184184
if Set.fromList files /= requiredFiles then
185185
revert dir $ "Malformed request. Missing some metadata files."
186186
else
187-
do bytes <- liftIO $ LBS.readFile (dir </> "elm.json")
187+
do bytes <- liftIO $ BS.readFile (dir </> "elm.json")
188188
case Decode.parse Project.pkgDecoder bytes of
189189
Left _ ->
190190
revert dir $ "Invalid content in elm.json file."
@@ -279,13 +279,13 @@ writeEndpoint name version dir stream =
279279
Right hash ->
280280
do Encode.writeUgly (dir </> "endpoint.json") $
281281
Encode.object
282-
[ ("url", Encode.string (toGithubUrl name version))
282+
[ ("url", Encode.text (toGithubUrl name version))
283283
, ("hash", Encode.text hash)
284284
]
285285

286286
return $ Right "endpoint.json"
287287

288288

289-
toGithubUrl :: Pkg.Name -> Pkg.Version -> String
289+
toGithubUrl :: Pkg.Name -> Pkg.Version -> Text.Text
290290
toGithubUrl name version =
291-
"https://github.com/" ++ Pkg.toUrl name ++ "/zipball/temp-" ++ Pkg.versionToString version ++ "/"
291+
"https://github.com/" <> Text.pack (Pkg.toUrl name) <> "/zipball/temp-" <> Pkg.versionToText version <> "/"

Diff for: src/backend/Package/Releases.hs

+7-9
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ module Package.Releases
1111

1212
import Prelude hiding (read)
1313
import Control.Monad (forM)
14-
import qualified Data.ByteString.Lazy as BS
14+
import qualified Data.ByteString as BS
1515
import qualified Data.HashMap.Lazy as HashMap
1616
import qualified Data.List as List
17-
import Data.Monoid ((<>))
18-
import qualified Data.Text as Text
1917
import qualified Data.Time.Clock.POSIX as Time
2018
import System.Directory (doesFileExist)
2119
import System.Exit (exitFailure)
@@ -74,16 +72,16 @@ add name version time =
7472
encode :: [Release] -> Encode.Value
7573
encode releases =
7674
Encode.object $ flip map (List.sort releases) $ \(Release version time) ->
77-
( Pkg.versionToString version, Encode.int (floor time) )
75+
( Pkg.versionToText version, Encode.int (floor time) )
7876

7977

80-
releasesDecoder :: Decode.Decoder [Release]
78+
releasesDecoder :: Decode.Decoder () [Release]
8179
releasesDecoder =
8280
do pairs <- HashMap.toList <$> Decode.dict Decode.int
8381
forM (List.sort pairs) $ \(vsn, int) ->
8482
case Pkg.versionFromText vsn of
85-
Left _ ->
86-
Decode.fail $ Text.unpack vsn <> " is not a valid version"
87-
88-
Right version ->
83+
Just version ->
8984
Decode.succeed (Release version (fromIntegral int))
85+
86+
Nothing ->
87+
Decode.fail ()

Diff for: src/backend/Server.hs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
{-# OPTIONS_GHC -Wall #-}
22
{-# LANGUAGE OverloadedStrings #-}
3-
module Server (serve) where
3+
module Server
4+
( serve
5+
)
6+
where
7+
48

59
import Data.Foldable (asum)
610
import qualified Data.List as List
@@ -88,7 +92,7 @@ data Vsn = Latest | Exactly Pkg.Version
8892

8993
versionRoute :: Route (Pkg.Version -> a) a
9094
versionRoute =
91-
Router.custom (either (\_ -> Nothing) Just . Pkg.versionFromText)
95+
Router.custom Pkg.versionFromText
9296

9397

9498
versionStuff :: Route (PkgInfo -> a) a
@@ -154,7 +158,7 @@ serveVersionHelp name version maybeAsset =
154158
serveFile (Path.directory name version ++ "/README.md")
155159

156160
Just asset ->
157-
case Module.dehyphenate asset of
161+
case Module.fromHyphenPath asset of
158162
Nothing ->
159163
S.pass
160164

0 commit comments

Comments
 (0)