diff options
Diffstat (limited to 'src/Plugin/GitRemoteSetOrigin.hs')
-rw-r--r-- | src/Plugin/GitRemoteSetOrigin.hs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/Plugin/GitRemoteSetOrigin.hs b/src/Plugin/GitRemoteSetOrigin.hs new file mode 100644 index 0000000..0e8f817 --- /dev/null +++ b/src/Plugin/GitRemoteSetOrigin.hs @@ -0,0 +1,35 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Plugin.GitRemoteSetOrigin + ( gitRemoteSetOrigin + ) where + +import Control.Monad.IO.Class (liftIO) +import qualified Data.Text as T + +import Database.SQLite.Simple +import Text.Regex.TDFA ((=~)) + +import qualified Message as M +import Plugin.Base + +gitRemoteSetOrigin = Plugin + { matchRegex = "^git remote set origin ([^ ]+)$" + , perform = gitRemoteSetOriginAction + } + +gitRemoteSetOriginAction :: PluginAction +gitRemoteSetOriginAction message = do + case M.textStr message =~ matchRegex gitRemoteSetOrigin of + "" -> return $ Left "blast" + url -> do + dbConn <- liftIO $ open "db/sorbot_development.sqlite3" + liftIO $ execute dbConn "INSERT INTO \ + \ plugin_github_commit_channel_repo_urls \ + \ (channel, repo_url) \ + \ VALUES \ + \ (?, ?)" + (M.channel message, url) + liftIO $ close dbConn + + return $ Right $ T.pack url |