diff options
Diffstat (limited to 'src/Plugin/GitRemoteSetOrigin.hs')
-rw-r--r-- | src/Plugin/GitRemoteSetOrigin.hs | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/Plugin/GitRemoteSetOrigin.hs b/src/Plugin/GitRemoteSetOrigin.hs index 8cf2e51..c8a485e 100644 --- a/src/Plugin/GitRemoteSetOrigin.hs +++ b/src/Plugin/GitRemoteSetOrigin.hs @@ -26,12 +26,27 @@ gitRemoteSetOriginAction message = do let url = last m 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 $ withTransaction dbConn $ do + let params = + [":channel" := M.channel message + , ":repo_url" := url + ] + + -- Upsert repo URL for channel + executeNamed dbConn "UPDATE \ + \ plugin_github_commit_channel_repo_urls \ + \ SET channel = :channel, \ + \ repo_url = :repo_url \ + \ WHERE channel = :channel" + params + executeNamed dbConn "INSERT INTO \ + \ plugin_github_commit_channel_repo_urls \ + \ (channel, repo_url) \ + \ SELECT \ + \ :channel, \ + \ :repo_url \ + \ WHERE changes() = 0" + params liftIO $ close dbConn return $ Right $ T.pack url |