aboutsummaryrefslogtreecommitdiffstats
path: root/app/History/PartialCommitInfo.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/History/PartialCommitInfo.hs')
-rw-r--r--app/History/PartialCommitInfo.hs44
1 files changed, 42 insertions, 2 deletions
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