From 34e3154c7ae1b002ff85cd0837c3cbf7d672d458 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Mon, 27 Nov 2023 13:55:04 +0100 Subject: close separate-database-issues-and-history-issues --- app/History/CommitInfo.hs | 1 - app/History/PartialCommitInfo.hs | 44 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) (limited to 'app/History') diff --git a/app/History/CommitInfo.hs b/app/History/CommitInfo.hs index 3c371d1..bea0cd3 100644 --- a/app/History/CommitInfo.hs +++ b/app/History/CommitInfo.hs @@ -16,7 +16,6 @@ import History.IssueEvent (IssueEvent (..)) import History.PartialCommitInfo (PartialCommitInfo (..)) import Issue (Issue (..), id) import Issue.Provenance qualified as I -import TreeGrepper.Match (Position (..)) import Prelude hiding (id) -- TODO Change `CommitInfo` -> `CommitIssuesAll` diff --git a/app/History/PartialCommitInfo.hs b/app/History/PartialCommitInfo.hs index cd8cd46..b37ada5 100644 --- a/app/History/PartialCommitInfo.hs +++ b/app/History/PartialCommitInfo.hs @@ -4,11 +4,12 @@ module History.PartialCommitInfo ) where -import Control.Exception (catch) +import Control.Exception (catch, handle) import Data.Binary (Binary) import Data.ByteString.Lazy.Char8 qualified as LB8 import Data.Function ((&)) import Data.List.NonEmpty qualified as N +import Data.Maybe (catMaybes) import Data.Text qualified as T import Die (die) import Exception qualified as E @@ -16,13 +17,17 @@ import GHC.Generics (Generic) import Git qualified import History.Cache (cached) import History.CommitHash (CommitHash (..)) -import Issue (Issue, getIssues) +import Issue (Issue (..)) +import Issue.Provenance qualified as I +import Issue.Tag qualified as I +import Issue.Text qualified as I import Parallel (parMapM) import Process (proc, sh) import System.Directory (getCurrentDirectory) import System.FilePath (()) import System.IO.Temp (withSystemTempDirectory) import System.Process.Typed (setWorkingDir) +import TreeGrepper.Comment qualified as G -- | `PartialCommitInfo` records the complete issues ONLY in files that have -- been changed in the commit. @@ -68,6 +73,41 @@ getIssuesAndFilesCommitChanged hash = do issues <- concat <$> catch (mapM (getIssues cwd) files) dieOfInvalidTreeGrepperResult pure (issues, files) +-- | Get all issues in the given directory and file. +getIssues :: FilePath -> FilePath -> IO [Issue] +getIssues cwd filename = + handle (\(_ :: E.UnknownFileExtension) -> pure []) $ + fmap catMaybes . mapM (fromComment cwd) + =<< G.getComments cwd filename + +-- | Note that `provenance` is trivial and needs to be fixed up later. +fromComment :: FilePath -> G.Comment -> IO (Maybe Issue) +fromComment cwd comment = do + commit <- I.commitFromHEAD cwd + let provenance = I.Provenance commit commit + + pure + ( if any (\marker -> T.isPrefixOf marker title') I.issueMarkers + then + Just + Issue + { title = title, + description = description, + file = comment.file, + provenance = provenance, + start = comment.start, + end = comment.end, + tags = maybe [] I.extractTags description, + markers = markers, + rawText = rawText + } + else Nothing + ) + where + rawText = comment.text + (title', description) = I.extractText comment.file_type rawText + (markers, title) = I.stripIssueMarkers title' + dieOfInvalidTreeGrepperResult :: E.InvalidTreeGrepperResult -> IO a dieOfInvalidTreeGrepperResult (E.InvalidTreeGrepperResult e) = die e -- cgit v1.2.3