blob: 187f016a7d05325db96813794a9ee0593e72038c (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
 | {-# LANGUAGE OverloadedStrings #-}
module Plugin.GitHubCommit
    ( gitHubCommit
    ) where
import qualified Data.Text as T
import Database.SQLite.Simple
import Database.SQLite.Simple.FromRow
import Text.Regex.TDFA
import qualified Message as M
import Plugin.Base
gitHubCommit = Plugin
    { matchRegex = "^[0-9a-f]{40}$"
    , perform = gitHubCommitAction
    }
gitHubCommitAction :: PluginAction
gitHubCommitAction message = do
    dbConn <- open "db/sorbot_development.sqlite3"
    rs <- query dbConn "SELECT repo_url \
        \ FROM plugin_github_commit_channel_repo_urls \
        \ WHERE channel = ? \
        \ LIMIT 1"
        (Only (M.channel message))
        :: IO [RepoUrlRow]
    close dbConn
    return $ respond rs
  where
    respond [] =
        Left "I couldn't find a repo URL for this channel. \
            \Try `git remote set origin REPO_URL`."
    respond ((RepoUrlRow r):_) =
        Right $ r `T.append` "/commits/" `T.append` T.pack (
            M.textStr message =~ matchRegex gitHubCommit)
type Id = Int
type RepoUrl = T.Text
-- | A type to match the database table for this plugin.
data RepoUrlRow = RepoUrlRow RepoUrl
instance FromRow RepoUrlRow where
    fromRow = RepoUrlRow <$> field
 |