Skip to content
This repository was archived by the owner on Jun 9, 2019. It is now read-only.

Check if commit message mentions submodule name #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions git-haskell-org-hooks.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ executable submodchecker
other-modules: Common

build-depends:
base >=4.5 && <4.9,
base >=4.5 && <4.10,
deepseq >=1.1 && <1.5,
shelly >=1.6 && <1.7,
text >=0.11 && <1.3
Expand All @@ -30,7 +30,7 @@ executable validate-commit-msg
main-is: validate-commit-msg.hs

build-depends:
base >=4.5 && <4.9,
base >=4.5 && <4.10,
deepseq >=1.1 && <1.5,
mtl >=2.1 && <2.3,
shelly >=1.6 && <1.7,
Expand All @@ -44,7 +44,7 @@ executable validate-whitespace
main-is: validate-whitespace.hs

build-depends:
base >=4.5 && <4.9,
base >=4.5 && <4.10,
deepseq >=1.1 && <1.5,
mtl >=2.1 && <2.3,
shelly >=1.6 && <1.7,
Expand Down
5 changes: 3 additions & 2 deletions src/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ gitBranchesContain d ref = do



-- | returns @[(path, (url, key))]@
-- | returns @[(path, (url, name))]@
--
-- may throw exception
getModules :: FilePath -> GitRef -> Sh [(Text, (Text, Text))]
Expand All @@ -99,8 +99,9 @@ getModules d ref = do
, let (_,key1) = T.break (=='.') (T.init key')
]

ms' = [ (path', (url, k))
ms' = [ (path', (url, name))
| es@((k,_):_) <- groupBy ((==) `on` fst) ms
, let (_,name) = T.breakOnEnd "/" k
, let props = map snd es
, let url = fromMaybe (error "getModules1") (lookup "url" props)
, let path' = fromMaybe (error "getModules2") (lookup "path" props)
Expand Down
11 changes: 8 additions & 3 deletions src/validate-submod-refs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,21 @@ main = do
echo $ "Submodule update(s) detected in " <> cid <> ":"

(_, msg) <- gitCatCommit dir cid
let msg' = T.toLower msg

unless ("submodule" `T.isInfixOf` msg) $ do
unless ("submodule" `T.isInfixOf` msg') $ do
echo "*FAIL* commit message does not contain magic 'submodule' word"
quietExit 1

modMapping <- getModules dir ref
forM_ smDeltas $ \(smPath,smCid) -> do
echo $ " " <> smPath <> " => " <> smCid
(smUrl,_) <- maybe (fail "failed to lookup repo-url") return $
lookup smPath modMapping
(smUrl,name) <- maybe (fail "failed to lookup repo-url") return $
lookup smPath modMapping

unless (T.toLower name `T.isInfixOf` msg') $ do
echo $ "*FAIL* commit message does not mention '" <> name <> "'"
quietExit 1

if not ("." `T.isPrefixOf` smUrl)
then echo $ "skipping non-relative Git url (" <> smUrl <> ")"
Expand Down