blob: e25a1dc0ffef79b52bb6ebde9dc02d990f29b2ce (
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
43
44
45
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 -> 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
]
|