diff options
author | Fabian Kirchner <kirchner@posteo.de> | 2023-10-14 00:46:19 +0200 |
---|---|---|
committer | Fabian Kirchner <kirchner@posteo.de> | 2023-10-14 00:46:19 +0200 |
commit | 154f48642dfdeff09472d462d6a5a069d0d9f4e9 (patch) | |
tree | 006ebd9e4b25073537c91f8f2c315e44ca9b5b63 /app/History.hs | |
parent | 3f8d07cbbbd31ba9850208af58039024f31d56b9 (diff) |
deduce initial provenance from commit history
Diffstat (limited to 'app/History.hs')
-rw-r--r-- | app/History.hs | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/app/History.hs b/app/History.hs index c3b3699..fad911a 100644 --- a/app/History.hs +++ b/app/History.hs @@ -7,11 +7,11 @@ import Control.Exception (Exception, catch, handle, throw) import Data.Aeson (eitherDecode) import Data.ByteString.Lazy.Char8 qualified as L8 import Data.List (intercalate) -import Data.Maybe (catMaybes) +import Data.Maybe (catMaybes, mapMaybe) import Data.String (fromString) import Data.Text (Text, lines, unpack) import Data.Text.Encoding (decodeUtf8) -import Issue (Issue (..), fromMatch) +import Issue (Issue (..), fromMatch, id) import Issue.Filter (Filter, applyFilter) import Process (quote, sh, sh_) import System.Directory (getCurrentDirectory, setCurrentDirectory) @@ -21,7 +21,7 @@ import System.IO.Temp (withSystemTempDirectory) import Text.Printf (printf) import TreeGrepper.Match qualified as G import TreeGrepper.Result qualified as G -import Prelude hiding (lines) +import Prelude hiding (id, lines) import Prelude qualified as Prelude data UnknownFileExtension = UnknownFileExtension @@ -41,7 +41,29 @@ instance Exception InvalidTreeGrepperResult listIssues :: [Filter] -> [FilePath] -> IO [Issue] listIssues filters files = do commits <- fmap (lines . decodeUtf8 . L8.toStrict) $ sh ("git log --format=%H") - fmap head $ mapM (\commit -> listIssuesOf commit filters files) commits + issueses <- mapM (\commit -> listIssuesOf commit filters files) commits + (currentIssues, historicalIssues) <- + case issueses of + currentIssues : historicalIssueses -> + pure (currentIssues, concat historicalIssueses) + [] -> + die "no commits" + pure (map (merge . pick historicalIssues) currentIssues) + +pick :: [Issue] -> Issue -> (Issue, [Issue]) +pick issues issue = + (issue, filter (isSameIssue) issues) + where + isSameIssue otherIssue = + id otherIssue == id issue + +merge :: (Issue, [Issue]) -> Issue +merge (issue, issues) = + case (mapMaybe provenance (reverse issues)) of + [] -> + issue + provenance : _ -> + issue {provenance = Just provenance} listIssuesOf :: Text -> [Filter] -> [FilePath] -> IO [Issue] listIssuesOf commit filters files = do |