diff options
author | Teddy Wing | 2017-08-17 20:48:55 +0200 |
---|---|---|
committer | Teddy Wing | 2017-08-17 20:48:55 +0200 |
commit | ce5e3cf7fe71c5c508c7eaecfb2280b9346e792a (patch) | |
tree | ceddcc8784fb2b98d1332de10849cae5a61ae61d /src | |
parent | 3ee61aec34d6c652a485c3098d50ce4a15b542e7 (diff) | |
download | sorbot-ce5e3cf7fe71c5c508c7eaecfb2280b9346e792a.tar.bz2 |
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]]
[]
Diffstat (limited to 'src')
-rw-r--r-- | src/Plugin/GitRemoteSetOrigin.hs | 8 |
1 files changed, 5 insertions, 3 deletions
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 \ |