hook handling

This commit is contained in:
Yann Esposito (Yogsototh) 2018-10-21 12:21:57 +02:00
parent a79af4e822
commit 39070e1078
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
4 changed files with 56 additions and 1 deletions

View file

@ -2,7 +2,7 @@
-- --
-- see: https://github.com/sol/hpack -- see: https://github.com/sol/hpack
-- --
-- hash: 2181d6cb75bcd17dab9a58fcfa594141af68c4c3e34050da6ce0beeb47bb7642 -- hash: 04bfdb9ffa855881f6cd6cc09bf3b494a2107ded6cc33c41699546a12526099e
name: gpm name: gpm
version: 0.1.0.0 version: 0.1.0.0
@ -24,6 +24,7 @@ library
GPM GPM
GPM.Docs GPM.Docs
GPM.Helpers GPM.Helpers
GPM.Hooks
GPM.Init GPM.Init
GPM.Issue GPM.Issue
GPM.Review GPM.Review

View file

@ -14,6 +14,7 @@ import Turtle
import GPM.Helpers (inGPM) import GPM.Helpers (inGPM)
import qualified GPM.Hooks as Hooks
import qualified GPM.Init as Init import qualified GPM.Init as Init
import qualified GPM.Issue as Issue import qualified GPM.Issue as Issue
import qualified GPM.Review as Review import qualified GPM.Review as Review
@ -27,11 +28,13 @@ gpm = do
NewIssue issueOpt -> inGPM (Issue.handleNewIssue issueOpt) NewIssue issueOpt -> inGPM (Issue.handleNewIssue issueOpt)
Review reviewCmd -> inGPM (Review.handleReview reviewCmd) Review reviewCmd -> inGPM (Review.handleReview reviewCmd)
Serve serveCmd -> inGPM (Serve.handleServe serveCmd) Serve serveCmd -> inGPM (Serve.handleServe serveCmd)
Hooks hooksCmd -> inGPM (Hooks.handleHooks hooksCmd)
data Command = Init data Command = Init
| NewIssue Issue.IssueOptions | NewIssue Issue.IssueOptions
| Review Review.ReviewCommand | Review Review.ReviewCommand
| Serve Serve.ServeCommand | Serve Serve.ServeCommand
| Hooks Hooks.HooksCommand
parser :: Parser Command parser :: Parser Command
parser = subcommand "init" "Initialize gpm" (pure Init) parser = subcommand "init" "Initialize gpm" (pure Init)
@ -44,3 +47,6 @@ parser = subcommand "init" "Initialize gpm" (pure Init)
<|> Serve <$> subcommand "serve" <|> Serve <$> subcommand "serve"
"Serve the git to the web" "Serve the git to the web"
Serve.parseServeCommand Serve.parseServeCommand
<|> Hooks <$> subcommand "hooks"
"Handle hooks for this git repository"
Hooks.parseHooksCommand

46
src/GPM/Hooks.hs Normal file
View file

@ -0,0 +1,46 @@
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-|
module : GPM.Helpers
Description : GPM helper functions
License : Public Domain
Maintainer : yann.esposito@gmail.com
-}
module GPM.Hooks
( init
, handleHooks
, parseHooksCommand
, HooksCommand(..)
)
where
import Protolude hiding ((%))
import Turtle
import GPM.Helpers
data HooksCommand = SyncHooks
parseHooksCommand :: Parser HooksCommand
parseHooksCommand = subcommand "sync" "Synchronize hooks from gpm branch" (pure SyncHooks)
-- | Init a hook directory with the git hooks
init :: IO ()
init = do
green "* hooks/"
putText " Copyings default hooks into the hooks directory"
let hooksDir = "hooks"
cptree (".git" </> "hooks") hooksDir
debug_ (toS (format ("git add "%fp) hooksDir))
-- | Handle hooks related commands
handleHooks :: HooksCommand -> Text -> IO ()
handleHooks SyncHooks _ = do
let githooksdir = ".git" </> "hooks"
gpmhooksdir = "hooks"
putErrText (format (" deleting "%fp) githooksdir)
rmtree githooksdir
putErrText (format (" cp -r "%fp%" "%fp) gpmhooksdir githooksdir)
cptree gpmhooksdir githooksdir

View file

@ -21,6 +21,7 @@ import GPM.Helpers (debug_, yellow)
import qualified GPM.Issue as Issue import qualified GPM.Issue as Issue
import qualified GPM.Review as Review import qualified GPM.Review as Review
import qualified GPM.Serve as Serve import qualified GPM.Serve as Serve
import qualified GPM.Hooks as Hooks
-- | Init a repository with a new empty branch named @gpm@ -- | Init a repository with a new empty branch named @gpm@
init :: IO () init :: IO ()
@ -30,6 +31,7 @@ init = do
Issue.init Issue.init
Docs.init Docs.init
Review.init Review.init
Hooks.init
Serve.init Serve.init
debug_ "git commit -m 'gpm initialized'" debug_ "git commit -m 'gpm initialized'"
debug_ "git checkout master" debug_ "git checkout master"