By | fr33domlover |
At | 2015-12-20 |
Title | add note event announcements, but no gitlab support yet |
Description |
Edit file NEWS.md 33188 → 33188
14 14 15 15 * Send history-on-join as a notice
16 16 * Log web source errors into a file instead of stdout
17 17 * Merge request announcements mention repo name
18 18 * Add issue ext event announcements
+ 19 * Add note ext event announcements
19 20 * Return an HTTP response to gitlab web hook, it seems to want it
20 21 21 22 Bug fixes:
22 23 23 24 * (None)
… … … … Edit file src/FunBot/ExtHandlers.hs 33188 → 33188
86 86 Orange #> Pure ('#' : show iid) <> " " <>
87 87 Purple #> Pure repo <> " | " <>
88 88 Teal #> Pure title <> " " <>
89 89 Gray #> Pure url
90 90 + 91 formatNote (Note author repo _owner content target url) =
+ 92 encode $
+ 93 Green #> Pure author <>
+ 94 Maroon #> " commented on " <>
+ 95 Orange #> Pure target <> " " <>
+ 96 Purple #> Pure repo <> " | " <>
+ 97 Teal #> Pure content <> " " <>
+ 98 Gray #> Pure url
+ 99 91 100 formatNews item fields =
92 101 let -- Filtered fields
93 102 filt pass val = if pass then val else Nothing
94 103 authorF = filt (dispAuthor fields) (itemAuthor item)
95 104 fTitleF = filt (dispFeedTitle fields) (itemFeedTitle item)
… … … … 123 132 124 133 keym mr = (mrRepo mr, lower $ mrRepoOwner mr)
125 134 126 135 keyi i = (issueRepo i, lower $ issueRepoOwner i)
127 136 + 137 keyn n = (noteRepo n, lower $ noteRepoOwner n)
+ 138 128 139 annCommits branch msgs ellip spec =
129 140 let chan = pAnnChannel spec
130 141 in when (branch `passes` pAnnBranches spec) $
131 142 if pAnnAllCommits spec || length msgs <= 3
132 143 then mapM_ (sendToChannel chan) msgs
… … … … 194 205 in mapM_ (ann . pAnnChannel) specs
195 206 Nothing ->
196 207 liftIO $ putStrLn $
197 208 "Ext handler: Issue for unregistered repo: " ++
198 209 show (keyi i)
+ 210 handler (NoteEvent n) = do
+ 211 chans <- getStateS $ stGitAnnChans . bsSettings
+ 212 case M.lookup (keyn n) chans of
+ 213 Just specs ->
+ 214 let msg = formatNote n
+ 215 ann chan = sendToChannel chan msg
+ 216 in mapM_ (ann . pAnnChannel) specs
+ 217 Nothing ->
+ 218 liftIO $ putStrLn $
+ 219 "Ext handler: Note for unregistered repo: " ++
+ 220 show (keyn n)
199 221 handler (NewsEvent item) = do
200 222 feeds <- getStateS $ stWatchedFeeds . bsSettings
201 223 let label = itemFeedLabel item
202 224 case M.lookup label feeds of
203 225 Just NewsFeed { nfAnnSpec = spec } ->
… … … … Edit file src/FunBot/Sources/WebListener/GitLab.hs 33188 → 33188
75 75 title = T.unpack $ T.takeWhile (not . nl) $ G.mrTitle mr -- to be safe
76 76 url = T.unpack $ G.mrUrl mr
77 77 action = T.unpack $ G.mreAction mre
78 78 in MergeRequestEvent $ MergeRequest author iid repo owner title url action
79 79 + 80 {-makeIssue ie =
+ 81 let i = G.ieIssue ie
+ 82 author = T.unpack $ G.userName $ G.ieUser ie
+ 83 iid = G.issueId i
+ 84 repo = T.unpack $ G.repoName $ G.ieRepo ie
+ 85 owner = T.unpack $ G.mepNamespace $ G.mrTarget mr
+ 86 title = T.unpack $ T.takeWhile (not . nl) $ G.mrTitle mr -- to be safe
+ 87 url = T.unpack $ G.mrUrl mr
+ 88 action = T.unpack $ G.mreAction mre
+ 89 in MergeRequestEvent $ MergeRequest author iid repo owner title url action
+ 90 -}
+ 91 80 92 dispatchPush push _pushMany p =
81 93 let commits = map makeCommit $ G.pushCommits p
82 94 branch = makeBranch (G.pushRef p) (G.pushRepository p)
83 95 in push $ GitPushEvent $ Push branch commits
84 96 … … … … 95 107 putStr "Web hook source: GitLab: "
96 108 print e
97 109 BC.putStrLn $ rqBody request
98 110 Right (G.EventPush e) -> dispatchPush push pushMany e
99 111 Right (G.EventPushTag e) -> dispatchTag push pushMany e
- 100 Right (G.EventIssue e) -> putStrLn ">>> GitLab Issue"
+ 112 Right (G.EventIssue e) -> {-dispatchIssue push pushMany e-} return ()
101 113 Right (G.EventMergeRequest e) -> dispatchMR push pushMany e
+ 114 Right (G.EventNote e) -> {-dispatchNote push pushMany e-} return ()
… … … …