diff options
author | Teddy Wing | 2017-08-17 04:33:39 +0200 |
---|---|---|
committer | Teddy Wing | 2017-08-17 04:33:39 +0200 |
commit | b4646cc2522f204550d97998d727d12108896ffa (patch) | |
tree | c13aa70023776b0af305b98ba617a272667d9d94 | |
parent | 5acf337a778d4806f2a4ed84b04d2d8fc3415949 (diff) | |
download | sorbot-b4646cc2522f204550d97998d727d12108896ffa.tar.bz2 |
Add GitRemoteSetOrigin plugin
This plugin provides a command to set a git commit repo URL for use with
the `GitHubCommit` plugin. Typing
git remote set origin URL
in chat will set that URL to the current channel.
Problems:
* Can't figure out how to use capture groups, so the entire matched
message string comes back, not just the URL
* Need to upsert instead of insert into the database
-rw-r--r-- | sorbot.cabal | 1 | ||||
-rw-r--r-- | src/Plugin.hs | 2 | ||||
-rw-r--r-- | src/Plugin/GitRemoteSetOrigin.hs | 35 |
3 files changed, 38 insertions, 0 deletions
diff --git a/sorbot.cabal b/sorbot.cabal index f27aff6..d69d7eb 100644 --- a/sorbot.cabal +++ b/sorbot.cabal @@ -21,6 +21,7 @@ library , Plugin , Plugin.Base , Plugin.GitHubCommit + , Plugin.GitRemoteSetOrigin build-depends: base >= 4.7 && < 5 , bytestring , irc-client diff --git a/src/Plugin.hs b/src/Plugin.hs index 0ff1367..a9918fc 100644 --- a/src/Plugin.hs +++ b/src/Plugin.hs @@ -11,6 +11,7 @@ import Text.Regex.TDFA import qualified Message as M import Plugin.Base import Plugin.GitHubCommit +import Plugin.GitRemoteSetOrigin -- | Get the first plugin that matches the given message text. matchPlugin :: M.Message -> Maybe Plugin @@ -32,4 +33,5 @@ performPlugin p message = perform p $ message plugins :: [Plugin] plugins = [ gitHubCommit + , gitRemoteSetOrigin ] 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 |