diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Lib.hs | 12 | ||||
| -rw-r--r-- | src/Plugin.hs | 46 | 
2 files changed, 51 insertions, 7 deletions
| @@ -4,11 +4,9 @@ module Lib  import Text.Regex.TDFA -someFunc :: IO () -someFunc -    | rex == True = putStrLn "Match!!" -    | otherwise   = putStrLn "No match" - +import Plugin -rex :: Bool -rex = "75ac7b18a009ffe7a77a17a61d95c01395f36b44" =~ "^[0-9a-f]{40}$" +someFunc :: IO () +someFunc = do +    let Just plugin = realMatchPlugin "75ac7b18a009ffe7a77a17a61d95c01395f36b44" +    putStrLn $ performPlugin plugin diff --git a/src/Plugin.hs b/src/Plugin.hs new file mode 100644 index 0000000..95f2461 --- /dev/null +++ b/src/Plugin.hs @@ -0,0 +1,46 @@ +module Plugin +    ( realMatchPlugin +    , Plugin +    , performPlugin +    , plugins +    ) where + +import Text.Regex.TDFA + +data Plugin = Plugin +    { matchRegex :: String +    , perform    :: String -> String +    } + +instance Show Plugin where +    show (Plugin r p) = "matchRegex = " ++ r + +realMatchPlugin :: String -> Maybe Plugin +realMatchPlugin message = matchPlugin message plugins + +matchPlugin :: String -> [Plugin] -> Maybe Plugin +matchPlugin message plugins = firstPlugin $ matchPlugins message plugins + +matchPlugins :: String -> [Plugin] -> [Plugin] +matchPlugins message plugins = [p | p <- plugins, message =~ matchRegex p] + +firstPlugin :: [Plugin] -> Maybe Plugin +firstPlugin []     = Nothing +firstPlugin (p:ps) = Just p + +-- TODO: Make a type for the `perform` function +performPlugin :: Plugin -> String +performPlugin p = perform p $ matchRegex p + +gitHubCommit = Plugin +    { matchRegex = "^[0-9a-f]{40}$" +    , perform = gitHubCommitAction +    } + +gitHubCommitAction :: String -> String +gitHubCommitAction match = "https://github.com/" ++ match + +plugins :: [Plugin] +plugins = +    [ gitHubCommit +    ] | 
