{-# LANGUAGE BlockArguments #-} {-# LANGUAGE DisambiguateRecordFields #-} {-# LANGUAGE OverloadedRecordDot #-} {-# LANGUAGE OverloadedStrings #-} module Issue (Issue (..), fromMatch, id) where import Data.List (find) import Data.Text (Text) import Data.Text qualified as T import Issue.Tag (Tag (..)) import Issue.Tag qualified as I import Issue.Text qualified as I import TreeGrepper.Match (Match (..)) import TreeGrepper.Match qualified as G import TreeGrepper.Result (Result (..)) import TreeGrepper.Result qualified as G import Prelude hiding (id) data Issue = Issue { title :: Text, description :: Maybe Text, file :: String, start :: G.Position, end :: G.Position, tags :: [Tag], internalTags :: [Tag] } deriving (Show) id :: Issue -> Maybe String id issue = (\(Tag _ v) -> T.unpack v) <$> ( find (\(Tag k _) -> k == "id") $ issue.tags ++ issue.internalTags ) fromMatch :: G.Result -> G.Match -> Maybe Issue fromMatch result match = if T.isPrefixOf marker title' then Just Issue { title = title, description = description, file = result.file, start = match.start, end = match.end, tags = maybe [] I.extractTags description, internalTags = I.internalTags title } else Nothing where (title', description) = I.extractText result.file_type match.text title = stripMarker title' marker :: Text marker = "TODO" stripMarker :: Text -> Text stripMarker text = maybe text T.stripStart (T.stripPrefix marker text)