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 | Phabricator = require '../lib/phabricator'
|
26 | moment = require 'moment'
|
27 | path = require 'path'
|
28 |
|
29 | module.exports = (robot) ->
|
30 |
|
31 | robot.phab ?= new Phabricator robot, process.env
|
32 | phab = robot.phab
|
33 |
|
34 |
|
35 | robot.respond /phad (?:projects|list) *$/, (msg) ->
|
36 | projects = Object.keys(phab.data.projects).filter (i) ->
|
37 | i isnt '*'
|
38 | if projects.length > 0
|
39 | msg.send "Known Projects: #{projects.join(', ')}"
|
40 | else
|
41 | msg.send 'There is no project.'
|
42 |
|
43 |
|
44 | robot.respond /phad del(?:ete)? (.+) *$/, (msg) ->
|
45 | project = msg.match[1]
|
46 | phab.getPermission(msg.envelope.user, 'phadmin')
|
47 | .then ->
|
48 | if phab.data.projects[project]?
|
49 | delete phab.data.projects[project]
|
50 | for alias, proj of phab.data.aliases
|
51 | delete phab.data.aliases[alias] if proj is project
|
52 | msg.send "#{project} erased from memory."
|
53 | else
|
54 | msg.send "#{project} not found in memory."
|
55 | .catch (e) ->
|
56 | msg.send e.message or e
|
57 |
|
58 |
|
59 | robot.respond /phad (info|show|refresh) (.+) *$/, (msg) ->
|
60 | refresh = (msg.match[1] is 'refresh')
|
61 | project = msg.match[2]
|
62 | phab.getProject(project, refresh)
|
63 | .then (proj) ->
|
64 | response = "'#{project}' is"
|
65 | if proj.data.parent?
|
66 | response += " '#{proj.data.parent}/#{proj.data.name}'"
|
67 | else
|
68 | response += " '#{proj.data.name}'"
|
69 | if proj.aliases? and proj.aliases.length > 0
|
70 | response += " (aka #{proj.aliases.join(', ')})"
|
71 | else
|
72 | response += ', with no alias'
|
73 | if proj.data.feeds? and proj.data.feeds.length > 0
|
74 | response += ", announced on #{proj.data.feeds.join(', ')}"
|
75 | else
|
76 | response += ', with no feed'
|
77 | if proj.data.columns? and Object.keys(proj.data.columns).length > 0
|
78 | response += ", columns #{Object.keys(proj.data.columns).join(', ')}"
|
79 | else
|
80 | response += ', and no columns'
|
81 | if proj.data.parent?
|
82 | response += " (child of #{proj.data.parent})"
|
83 | response += '.'
|
84 | msg.send response
|
85 | .catch (e) ->
|
86 | msg.send e.message or e
|
87 |
|
88 |
|
89 | robot.respond /phad alias (.+) as (.+)$/, (msg) ->
|
90 | project = msg.match[1]
|
91 | alias = msg.match[2]
|
92 | phab.getPermission(msg.envelope.user, 'phadmin')
|
93 | .then ->
|
94 | phab.getProject(project)
|
95 | .then (proj) ->
|
96 | if phab.data.aliases[alias]?
|
97 | msg.send "The alias '#{alias}' already exists for project '#{phab.data.aliases[alias]}'."
|
98 | else
|
99 | if proj.data.parent?
|
100 | fullname = "#{proj.data.parent}/#{proj.data.name}"
|
101 | else
|
102 | fullname = proj.data.name
|
103 | phab.data.aliases[alias] = fullname
|
104 | msg.send "Ok, '#{fullname}' will be known as '#{alias}'."
|
105 | .catch (e) ->
|
106 | msg.send e.message or e
|
107 |
|
108 |
|
109 | robot.respond /phad forget (.+)$/, (msg) ->
|
110 | alias = msg.match[1]
|
111 | phab.getPermission(msg.envelope.user, 'phadmin')
|
112 | .then ->
|
113 | if phab.data.aliases[alias]
|
114 | delete phab.data.aliases[alias]
|
115 | msg.send "Ok, the alias '#{alias}' is forgotten."
|
116 | else
|
117 | msg.send "Sorry, I don't know the alias '#{alias}'."
|
118 | .catch (e) ->
|
119 | msg.send e.message or e
|
120 |
|
121 |
|
122 | robot.respond /phad feeds? (.+) to (.+)$/, (msg) ->
|
123 | project = msg.match[1]
|
124 | room = msg.match[2]
|
125 | phab.getPermission(msg.envelope.user, 'phadmin')
|
126 | .then ->
|
127 | phab.getProject(project)
|
128 | .then (proj) ->
|
129 | if proj.data.parent?
|
130 | fullname = "#{proj.data.parent}/#{proj.data.name}"
|
131 | else
|
132 | fullname = proj.data.name
|
133 | phab.data.projects[fullname].feeds ?= [ ]
|
134 | if room in phab.data.projects[fullname].feeds
|
135 | msg.send "The feed from '#{fullname}' to '#{room}' already exist."
|
136 | else
|
137 | phab.data.projects[fullname].feeds.push room
|
138 | msg.send "Ok, '#{fullname}' is now feeding '#{room}'."
|
139 | .catch (e) ->
|
140 | msg.send e.message or e
|
141 |
|
142 |
|
143 | robot.respond /phad feedall to (.+)$/, (msg) ->
|
144 | room = msg.match[1]
|
145 | phab.getPermission(msg.envelope.user, 'phadmin')
|
146 | .then ->
|
147 | phab.getProject('*')
|
148 | .then (proj) ->
|
149 | phab.data.projects['*'].feeds ?= [ ]
|
150 | if room in phab.data.projects['*'].feeds
|
151 | msg.send "The catchall feed to '#{room}' already exist."
|
152 | else
|
153 | phab.data.projects['*'].feeds.push room
|
154 | msg.send "Ok, all feeds will be announced on '#{room}'."
|
155 | .catch (e) ->
|
156 | msg.send e.message or e
|
157 |
|
158 |
|
159 | robot.respond /phad remove (.+) from (.+)$/, (msg) ->
|
160 | project = msg.match[1]
|
161 | room = msg.match[2]
|
162 | phab.getPermission(msg.envelope.user, 'phadmin')
|
163 | .then ->
|
164 | phab.getProject(project)
|
165 | .then (proj) ->
|
166 | if proj.data.parent?
|
167 | fullname = "#{proj.data.parent}/#{proj.data.name}"
|
168 | else
|
169 | fullname = proj.data.name
|
170 | phab.data.projects[fullname].feeds ?= [ ]
|
171 | if room in phab.data.projects[fullname].feeds
|
172 | idx = phab.data.projects[fullname].feeds.indexOf room
|
173 | phab.data.projects[fullname].feeds.splice(idx, 1)
|
174 | msg.send "Ok, The feed from '#{fullname}' to '#{room}' was removed."
|
175 | else
|
176 | msg.send "Sorry, '#{fullname}' is not feeding '#{room}'."
|
177 | .catch (e) ->
|
178 | msg.send e.message or e
|
179 |
|
180 |
|
181 | robot.respond /phad removeall from (.+)$/, (msg) ->
|
182 | room = msg.match[1]
|
183 | phab.getPermission(msg.envelope.user, 'phadmin')
|
184 | .then ->
|
185 | phab.getProject('*')
|
186 | .then (proj) ->
|
187 | proj.data.feeds ?= [ ]
|
188 | phab.data.projects['*'].feeds ?= [ ]
|
189 | if room in phab.data.projects['*'].feeds
|
190 | idx = phab.data.projects['*'].feeds.indexOf room
|
191 | phab.data.projects['*'].feeds.splice(idx, 1)
|
192 | msg.send "Ok, The catchall feed to '#{room}' was removed."
|
193 | else
|
194 | msg.send "Sorry, the catchall feed for '#{room}' doesn't exist."
|
195 | .catch (e) ->
|
196 | msg.send e.message or e
|
197 |
|
198 |
|
199 | robot.respond /phad columns (.+)$/, (msg) ->
|
200 | project = msg.match[1]
|
201 | phab.getPermission(msg.envelope.user, 'phadmin')
|
202 | .then ->
|
203 | phab.getProject(project)
|
204 | .then (payload) ->
|
205 | if payload.data.columns? and Object.keys(payload.data.columns).length > 0
|
206 | msg.send "Columns for #{project}: #{Object.keys(payload.data.columns).join(', ')}"
|
207 | else
|
208 | msg.send "The project #{project} has no columns."
|
209 | .catch (e) ->
|
210 | msg.send e.message or e
|