From ce5e3cf7fe71c5c508c7eaecfb2280b9346e792a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 17 Aug 2017 20:48:55 +0200 Subject: gitRemoteSetOriginAction: Use regex capture group Finally figured out how to get a capture group out of the regex match. Needed to coerce as a two-dimensional `String` list. Thanks to: - https://stackoverflow.com/questions/24699279/cant-capture-a-group-in-a-string - https://stackoverflow.com/questions/6729158/find-all-capturing-groups-of-a-regular-expression Get the captured group and set it to the URL to insert into the database. It lives in the second element of the first list: Prelude Text.Regex.TDFA> "git remote set origin https://example.new" =~ "^git remote set origin ([^ ]+)$" :: [[String]] [["git remote set origin https://example.new","https://example.new"]] Prelude Text.Regex.TDFA> "" =~ "^git remote set origin ([^ ]+)$" :: [[String]] [] --- src/Plugin/GitRemoteSetOrigin.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Plugin/GitRemoteSetOrigin.hs') diff --git a/src/Plugin/GitRemoteSetOrigin.hs b/src/Plugin/GitRemoteSetOrigin.hs index 0e8f817..8cf2e51 100644 --- a/src/Plugin/GitRemoteSetOrigin.hs +++ b/src/Plugin/GitRemoteSetOrigin.hs @@ -20,9 +20,11 @@ gitRemoteSetOrigin = Plugin gitRemoteSetOriginAction :: PluginAction gitRemoteSetOriginAction message = do - case M.textStr message =~ matchRegex gitRemoteSetOrigin of - "" -> return $ Left "blast" - url -> do + case M.textStr message =~ matchRegex gitRemoteSetOrigin :: [[String]] of + [] -> return $ Left "blast" + (m:_) -> do + let url = last m + dbConn <- liftIO $ open "db/sorbot_development.sqlite3" liftIO $ execute dbConn "INSERT INTO \ \ plugin_github_commit_channel_repo_urls \ -- cgit v1.2.3