Skip to content

Commit

Permalink
First pass at purescript#652
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-murphy committed Aug 19, 2023
1 parent 282a4f0 commit d07f02e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
29 changes: 20 additions & 9 deletions app/src/App/Effect/Source.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Data.DateTime (DateTime)
import Data.HTTP.Method (Method(..))
import Data.JSDate as JSDate
import Effect.Aff as Aff
import Effect.Now as Now
import Node.Buffer as Buffer
import Node.FS.Aff as FS.Aff
import Node.Path as Path
Expand Down Expand Up @@ -48,9 +49,17 @@ fetch destination location ref = Except.rethrow =<< Run.lift _source (Fetch dest
interpret :: forall r a. (Source ~> Run r) -> Run (SOURCE + r) a -> Run r a
interpret handler = Run.interpret (Run.on _source handler Run.send)

-- | Handle the SOURCE effect by downloading package source to the file system.
handleLegacy :: forall r a. Source a -> Run (GITHUB + LOG + AFF + EFFECT + r) a
handleLegacy = handle' LegacyImport

handle :: forall r a. Source a -> Run (GITHUB + LOG + AFF + EFFECT + r) a
handle = case _ of
handle = handle' NonLegacyImport

data IsLegacyImport = LegacyImport | NonLegacyImport

-- | Handle the SOURCE effect by downloading package source to the file system.
handle' :: forall r a. IsLegacyImport -> Source a -> Run (GITHUB + LOG + AFF + EFFECT + r) a
handle' isLegacyImport = case _ of
Fetch destination location ref reply -> map (map reply) Except.runExcept do
Log.info $ "Fetching " <> printJson Location.codec location
case location of
Expand Down Expand Up @@ -92,13 +101,15 @@ handle = case _ of
Log.debug $ "Getting published time..."

let
getRefTime = do
timestamp <- Except.rethrow =<< Run.liftAff (Git.gitCLI [ "log", "-1", "--date=iso8601-strict", "--format=%cd", ref ] (Just repoDir))
jsDate <- Run.liftEffect $ JSDate.parse timestamp
dateTime <- case JSDate.toDateTime jsDate of
Nothing -> Except.throw $ "Could not parse timestamp of git ref to a datetime given timestamp " <> timestamp <> " and parsed js date " <> JSDate.toUTCString jsDate
Just parsed -> pure parsed
pure dateTime
getRefTime = case isLegacyImport of
LegacyImport -> do
timestamp <- Except.rethrow =<< Run.liftAff (Git.gitCLI [ "log", "-1", "--date=iso8601-strict", "--format=%cd", ref ] (Just repoDir))
jsDate <- Run.liftEffect $ JSDate.parse timestamp
case JSDate.toDateTime jsDate of
Nothing -> Except.throw $ "Could not parse timestamp of git ref to a datetime given timestamp " <> timestamp <> " and parsed js date " <> JSDate.toUTCString jsDate
Just parsed -> pure parsed
NonLegacyImport ->
Run.liftEffect Now.nowDateTime

-- Cloning will result in the `repo` name as the directory name
publishedTime <- Except.runExcept getRefTime >>= case _ of
Expand Down
6 changes: 3 additions & 3 deletions scripts/src/LegacyImporter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ main = launchAff_ do
Registry.interpret (Registry.handle (registryEnv Git.Autostash Registry.ReadOnly))
>>> Storage.interpret (Storage.handleReadOnly cache)
>>> Pursuit.interpret Pursuit.handlePure
>>> Source.interpret Source.handle
>>> Source.interpret Source.handleLegacy
>>> GitHub.interpret (GitHub.handle { octokit, cache, ref: githubCacheRef })

GenerateRegistry -> do
Expand All @@ -140,7 +140,7 @@ main = launchAff_ do
Registry.interpret (Registry.handle (registryEnv Git.Autostash (Registry.CommitAs (Git.pacchettibottiCommitter token))))
>>> Storage.interpret (Storage.handleS3 { s3, cache })
>>> Pursuit.interpret Pursuit.handlePure
>>> Source.interpret Source.handle
>>> Source.interpret Source.handleLegacy
>>> GitHub.interpret (GitHub.handle { octokit, cache, ref: githubCacheRef })

UpdateRegistry -> do
Expand All @@ -151,7 +151,7 @@ main = launchAff_ do
Registry.interpret (Registry.handle (registryEnv Git.ForceClean (Registry.CommitAs (Git.pacchettibottiCommitter token))))
>>> Storage.interpret (Storage.handleS3 { s3, cache })
>>> Pursuit.interpret (Pursuit.handleAff token)
>>> Source.interpret Source.handle
>>> Source.interpret Source.handleLegacy
>>> GitHub.interpret (GitHub.handle { octokit, cache, ref: githubCacheRef })

-- Logging setup
Expand Down

0 comments on commit d07f02e

Please sign in to comment.