blob: 2a06fb43f469df3a70eebb9952dd47e6274320dc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
module Plugin
( Plugin
, matchPlugin
, 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
matchPlugin :: String -> Maybe Plugin
matchPlugin message = firstPlugin $ matchPlugins message plugins
where
firstPlugin [] = Nothing
firstPlugin (p:ps) = Just p
matchPlugins :: String -> [Plugin] -> [Plugin]
matchPlugins message plugins = [p | p <- plugins, message =~ matchRegex p]
-- TODO: Make a type for the `perform` function
performPlugin :: Plugin -> String -> String
performPlugin p message = perform p $ message =~ matchRegex p
gitHubCommit = Plugin
{ matchRegex = "^[0-9a-f]{40}$"
, perform = gitHubCommitAction
}
gitHubCommitAction :: String -> String
gitHubCommitAction match = "https://github.com/" ++ match
plugins :: [Plugin]
plugins =
[ gitHubCommit
]
|