From d07f02e8e74972fb8c56d0e531feac64c140de90 Mon Sep 17 00:00:00 2001 From: Peter Murphy <26548438+ptrfrncsmrph@users.noreply.github.com> Date: Fri, 18 Aug 2023 19:24:23 -0400 Subject: [PATCH] First pass at #652 --- app/src/App/Effect/Source.purs | 29 ++++++++++++++++++++--------- scripts/src/LegacyImporter.purs | 6 +++--- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/src/App/Effect/Source.purs b/app/src/App/Effect/Source.purs index 42a70c73..2cbc950d 100644 --- a/app/src/App/Effect/Source.purs +++ b/app/src/App/Effect/Source.purs @@ -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 @@ -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 @@ -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 diff --git a/scripts/src/LegacyImporter.purs b/scripts/src/LegacyImporter.purs index 658ebc61..cb01c5d3 100644 --- a/scripts/src/LegacyImporter.purs +++ b/scripts/src/LegacyImporter.purs @@ -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 @@ -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 @@ -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