Skip to content

Commit

Permalink
fix some elm-review failures
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Oct 25, 2024
1 parent 6970870 commit 4968f04
Show file tree
Hide file tree
Showing 44 changed files with 286 additions and 1,163 deletions.
17 changes: 11 additions & 6 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const http = require("node:http");
const https = require("node:https");
const resolve = require("node:path").resolve;
const zlib = require("node:zlib");
const crypto = require("node:crypto");
const AdmZip = require("adm-zip");
const which = require("which");
const tmp = require("tmp");
Expand All @@ -27,24 +28,28 @@ const processes = {};
let state = null;

const download = function (index, method, url) {
const req = https.request(url, { method: method }, (res) => {
const req = https.request(url, { method }, (res) => {
if (res.statusCode >= 200 && res.statusCode < 300) {
let data = [];
let chunks = [];

res.on("data", (chunk) => {
data.push(chunk);
chunks.push(chunk);
});

res.on("end", () => {
const zip = new AdmZip(Buffer.concat(data));
const buffer = Buffer.concat(chunks);
const zip = new AdmZip(buffer);

const sha = crypto.createHash("sha1").update(buffer).digest("hex");

const jsonData = zip.getEntries().map(function (entry) {
const archive = zip.getEntries().map(function (entry) {
return {
eRelativePath: entry.entryName,
eData: zip.readAsText(entry),
};
});

this.send({ index, value: jsonData });
this.send({ index, value: { sha, archive } });
});
} else if (res.headers.location) {
download.apply(this, [index, method, res.headers.location]);
Expand Down
7 changes: 4 additions & 3 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
"elm-community/list-extra": "8.7.0",
"elm-community/maybe-extra": "5.3.0",
"guida-lang/glsl": "1.0.0",
"guida-lang/graph": "1.0.0",
"rtfeldman/elm-hex": "1.0.0",
"the-sett/elm-pretty-printer": "3.1.0",
"zwilias/elm-rosetree": "1.5.0"
"the-sett/elm-pretty-printer": "3.1.0"
},
"indirect": {
"andre-dietrich/parser-combinators": "4.1.0",
"elm/regex": "1.0.0",
"fredcy/elm-parseint": "2.0.1",
"pilatch/flip": "1.0.0"
"pilatch/flip": "1.0.0",
"zwilias/elm-rosetree": "1.5.0"
}
},
"test-dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions review/src/ReviewConfig.elm
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import Simplify

config : List Rule
config =
[ -- Docs.ReviewAtDocs.rule
NoConfusingPrefixOperator.rule
[ Docs.ReviewAtDocs.rule
, NoConfusingPrefixOperator.rule
, NoDebug.Log.rule

-- , NoDebug.TodoOrToString.rule
Expand Down
3 changes: 1 addition & 2 deletions src/Builder/Deps/Website.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Builder.Deps.Website exposing
( domain
, metadata
( metadata
, route
)

Expand Down
10 changes: 5 additions & 5 deletions src/Builder/Elm/Details.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module Builder.Elm.Details exposing
, loadObjects
, localDecoder
, localEncoder
, statusDecoder
, verifyInstall
)

Expand Down Expand Up @@ -1061,10 +1060,11 @@ downloadPackage cache manager pkg vsn =
Ok ( endpoint, expectedHash ) ->
Http.getArchive manager endpoint Exit.PP_BadArchiveRequest (Exit.PP_BadArchiveContent endpoint) <|
\( sha, archive ) ->
-- TODO (IMPORTANT) if expectedHash == Http.shaToChars sha then
IO.fmap Ok (File.writePackage (Stuff.package cache pkg vsn) archive)
-- else
-- IO.pure (Err (Exit.PP_BadArchiveHash endpoint expectedHash (Http.shaToChars sha)))
if expectedHash == Http.shaToChars sha then
IO.fmap Ok (File.writePackage (Stuff.package cache pkg vsn) archive)

else
IO.pure (Err (Exit.PP_BadArchiveHash endpoint expectedHash (Http.shaToChars sha)))
)


Expand Down
1 change: 0 additions & 1 deletion src/Builder/Elm/Outline.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Builder.Elm.Outline exposing
, SrcDir(..)
, decoder
, defaultSummary
, encode
, flattenExposed
, read
, srcDirDecoder
Expand Down
14 changes: 0 additions & 14 deletions src/Builder/File.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Builder.File exposing
, readBinary
, readUtf8
, remove
, removeDir
, timeDecoder
, timeEncoder
, writeBinary
Expand Down Expand Up @@ -184,19 +183,6 @@ remove path =
)


removeDir : FilePath -> IO ()
removeDir path =
Utils.dirDoesFileExist path
|> IO.bind
(\exists_ ->
if exists_ then
Utils.dirRemoveDirectoryRecursive path

else
IO.pure ()
)



-- ENCODERS and DECODERS

Expand Down
70 changes: 7 additions & 63 deletions src/Builder/Http.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Builder.Http exposing
( Error(..)
, Header
, HttpExceptionContent(..)
, Manager
, MultiPart
, Sha
Expand All @@ -28,7 +27,7 @@ import Data.IO as IO exposing (IO)
import Json.Decode as Decode
import Json.Encode as Encode
import Url.Builder
import Utils.Main as Utils exposing (HTTPResponse, SomeException)
import Utils.Main as Utils exposing (SomeException)



Expand Down Expand Up @@ -145,16 +144,10 @@ accept mime =

type Error
= BadUrl String String
| BadHttp String HttpExceptionContent
| BadHttp String Utils.HttpExceptionContent
| BadMystery String SomeException


type HttpExceptionContent
= StatusCodeException (HTTPResponse ()) String
| TooManyRedirects (List (HTTPResponse ()))
| ConnectionFailure SomeException



-- SHA

Expand All @@ -173,13 +166,9 @@ shaToChars =


getArchive : Manager -> String -> (Error -> e) -> e -> (( Sha, Utils.ZipArchive ) -> IO (Result e a)) -> IO (Result e a)
getArchive manager url onError err onSuccess =
IO.make Utils.zipArchiveDecoder (IO.GetArchive "GET" url)
|> IO.bind
(\archive ->
-- TODO review the need to use `readArchive...`
onSuccess ( "SHA-TODO", archive )
)
getArchive _ url _ _ onSuccess =
IO.make Utils.shaAndArchiveDecoder (IO.GetArchive "GET" url)
|> IO.bind (\shaAndArchive -> onSuccess shaAndArchive)



Expand Down Expand Up @@ -260,7 +249,7 @@ errorEncoder error =
Encode.object
[ ( "type", Encode.string "BadHttp" )
, ( "url", Encode.string url )
, ( "httpExceptionContent", httpExceptionContentEncoder httpExceptionContent )
, ( "httpExceptionContent", Utils.httpExceptionContentEncoder httpExceptionContent )
]

BadMystery url someException ->
Expand All @@ -285,7 +274,7 @@ errorDecoder =
"BadHttp" ->
Decode.map2 BadHttp
(Decode.field "url" Decode.string)
(Decode.field "httpExceptionContent" httpExceptionContentDecoder)
(Decode.field "httpExceptionContent" Utils.httpExceptionContentDecoder)

"BadMystery" ->
Decode.map2 BadMystery
Expand All @@ -295,48 +284,3 @@ errorDecoder =
_ ->
Decode.fail ("Failed to decode Error's type: " ++ type_)
)


httpExceptionContentEncoder : HttpExceptionContent -> Encode.Value
httpExceptionContentEncoder httpExceptionContent =
case httpExceptionContent of
StatusCodeException response body ->
Encode.object
[ ( "type", Encode.string "StatusCodeException" )
, ( "response", Utils.httpResponseEncoder response )
, ( "body", Encode.string body )
]

TooManyRedirects responses ->
Encode.object
[ ( "type", Encode.string "TooManyRedirects" )
, ( "responses", Encode.list Utils.httpResponseEncoder responses )
]

ConnectionFailure someException ->
Encode.object
[ ( "type", Encode.string "ConnectionFailure" )
, ( "someException", Utils.someExceptionEncoder someException )
]


httpExceptionContentDecoder : Decode.Decoder HttpExceptionContent
httpExceptionContentDecoder =
Decode.field "type" Decode.string
|> Decode.andThen
(\type_ ->
case type_ of
"StatusCodeException" ->
Decode.map2 StatusCodeException
(Decode.field "response" Utils.httpResponseDecoder)
(Decode.field "body" Decode.string)

"TooManyRedirects" ->
Decode.map TooManyRedirects (Decode.field "responses" (Decode.list Utils.httpResponseDecoder))

"ConnectionFailure" ->
Decode.map ConnectionFailure (Decode.field "someException" Utils.someExceptionDecoder)

_ ->
Decode.fail ("Failed to decode HttpExceptionContent's type: " ++ type_)
)
Loading

0 comments on commit 4968f04

Please sign in to comment.