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 /src/Plugin | |
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
Diffstat (limited to 'src/Plugin')
-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 |