aboutsummaryrefslogtreecommitdiffstats
path: root/src/Plugin/GitHubCommit.hs
diff options
context:
space:
mode:
authorTeddy Wing2017-08-03 20:34:12 +0200
committerTeddy Wing2017-08-03 20:34:12 +0200
commitf409e64310432f91132e0e56676f7dd75113d47b (patch)
tree8949bee8b3b3f3fa76afdb2be3cd97af36e49b65 /src/Plugin/GitHubCommit.hs
parent5070ee3f46a7b9cd796594736ebd48d8270a7ff6 (diff)
downloadsorbot-f409e64310432f91132e0e56676f7dd75113d47b.tar.bz2
GitHubCommit.hs: Only select `repo_url` column from database
We don't need to select the channel because we don't do anything with it. All we need is the repo URL. Create a new data type for use with the database query that allows us to select only the URL. Remove the `ChannelRepoUrl` type as it's no longer needed.
Diffstat (limited to 'src/Plugin/GitHubCommit.hs')
-rw-r--r--src/Plugin/GitHubCommit.hs17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/Plugin/GitHubCommit.hs b/src/Plugin/GitHubCommit.hs
index 2786ca6..cac74a4 100644
--- a/src/Plugin/GitHubCommit.hs
+++ b/src/Plugin/GitHubCommit.hs
@@ -18,17 +18,17 @@ gitHubCommit = Plugin
gitHubCommitAction :: PluginAction
gitHubCommitAction message dbConn = do
- rs <- query dbConn "SELECT channel, repo_url \
+ rs <- query dbConn "SELECT repo_url \
\ FROM plugin_github_commit_channel_repo_urls \
\ WHERE channel = ? \
\ LIMIT 1"
(Only (M.channel message))
- :: IO [ChannelRepoUrl]
+ :: IO [RepoUrlRow]
return $ response rs
where
response [] = ""
- response (r:rs) =
- repoUrl r ++ "/commits/" ++ M.text message =~ matchRegex gitHubCommit
+ response ((RepoUrlRow r):rs) =
+ r ++ "/commits/" ++ M.text message =~ matchRegex gitHubCommit
-- TODO: Make an Either type for plugins to return errors
type Id = Int
@@ -36,10 +36,7 @@ type Id = Int
type RepoUrl = String
-- | A type to match the database table for this plugin.
-data ChannelRepoUrl = ChannelRepoUrl
- { channel :: M.Channel
- , repoUrl :: RepoUrl
- } deriving (Show)
+data RepoUrlRow = RepoUrlRow RepoUrl
-instance FromRow ChannelRepoUrl where
- fromRow = ChannelRepoUrl <$> field <*> field
+instance FromRow RepoUrlRow where
+ fromRow = RepoUrlRow <$> field