-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: refactor: extract repo checks to utility method
- Loading branch information
1 parent
3a841f0
commit 9aa39f5
Showing
4 changed files
with
31 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,10 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module Command.NextID where | ||
|
||
import Control.Monad (unless) | ||
import Data.Maybe (fromMaybe) | ||
import System.Exit (die) | ||
|
||
import Security.Advisories.Git (getRepoRoot) | ||
import Security.Advisories.Core.HsecId (printHsecId, getNextHsecId) | ||
import Security.Advisories.Filesystem (isSecurityAdvisoriesRepo, getGreatestId) | ||
import Security.Advisories.Filesystem (getGreatestId) | ||
|
||
runNextIDCommand :: Maybe FilePath -> IO () | ||
runNextIDCommand mPath = do | ||
let | ||
path = fromMaybe "." mPath | ||
repoPath <- getRepoRoot path >>= \case | ||
Left _ -> die "Not a git repo" | ||
Right a -> pure a | ||
isRepo <- isSecurityAdvisoriesRepo repoPath | ||
unless isRepo $ | ||
die "Not a security-advisories repo" | ||
import Util (ensureRepo) | ||
|
||
getGreatestId repoPath >>= getNextHsecId >>= putStrLn . printHsecId | ||
runNextIDCommand :: Maybe FilePath -> IO () | ||
runNextIDCommand mPath = | ||
ensureRepo mPath >>= getGreatestId >>= getNextHsecId >>= putStrLn . printHsecId |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
|
||
module Util where | ||
|
||
import Data.Maybe (fromMaybe) | ||
import System.Exit (die) | ||
|
||
import Security.Advisories.Filesystem (isSecurityAdvisoriesRepo) | ||
import Security.Advisories.Git (getRepoRoot) | ||
|
||
-- | Ensure the given path (or current directory "." if @Nothing@) | ||
-- is an advisory Git repo. Return the (valid) repo root, or die | ||
-- with an error message. | ||
-- | ||
ensureRepo :: Maybe FilePath -> IO FilePath | ||
ensureRepo mPath = | ||
getRepoRoot (fromMaybe "." mPath) >>= \case | ||
Left _ -> die "Not a git repo" | ||
Right repoPath -> isSecurityAdvisoriesRepo repoPath >>= \case | ||
False -> die "Not a security-advisories repo" | ||
True -> pure repoPath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters