Skip to content

Commit

Permalink
more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mose committed Aug 5, 2016
1 parent 5cbfe55 commit 2a77250
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions lib/phabricator.coffee
Expand Up @@ -132,7 +132,7 @@ class Phabricator
else
cb { rooms: [ ] }

withProject: (_, project, cb) =>
withProject: (project, cb) =>
if @data.projects[project]?
projectData = @data.projects[project]
projectData.name = project
Expand Down Expand Up @@ -198,7 +198,7 @@ class Phabricator
cb user.phid


withUserByPhid: (_, phid, cb) =>
withUserByPhid: (phid, cb) =>
if phid?
user = null
for k of @robot.brain.data.users
Expand Down Expand Up @@ -233,28 +233,28 @@ class Phabricator
cb()


taskInfo: (_, id, cb) ->
taskInfo: (id, cb) ->
if @ready() is true
query = { 'task_id': id }
@phabGet query, 'maniphest.info', (json_body) ->
cb json_body


fileInfo: (_, id, cb) ->
fileInfo: (id, cb) ->
if @ready() is true
query = { 'id': id }
@phabGet query, 'file.info', (json_body) ->
cb json_body


pasteInfo: (_, id, cb) ->
pasteInfo: (id, cb) ->
if @ready() is true
query = { 'ids[0]': id }
@phabGet query, 'paste.query', (json_body) ->
cb json_body


genericInfo: (_, name, cb) ->
genericInfo: (name, cb) ->
if @ready() is true
query = { 'names[]': name }
@phabGet query, 'phid.lookup', (json_body) ->
Expand Down
8 changes: 4 additions & 4 deletions scripts/phabs_admin.coffee
Expand Up @@ -49,7 +49,7 @@ module.exports = (robot) ->
# hubot phad <project> info
robot.respond (/phad (.+) info$/), (msg) ->
project = msg.match[1]
phab.withProject msg, project, (projectData) ->
phab.withProject project, (projectData) ->
if projectData.error_info?
msg.send projectData.error_info
else
Expand All @@ -69,7 +69,7 @@ module.exports = (robot) ->
phab.withPermission msg, msg.envelope.user, 'phadmin', ->
project = msg.match[1]
alias = msg.match[2]
phab.withProject msg, project, (projectData) ->
phab.withProject project, (projectData) ->
if projectData.error_info?
msg.send projectData.error_info
else
Expand All @@ -94,7 +94,7 @@ module.exports = (robot) ->
phab.withPermission msg, msg.envelope.user, 'phadmin', ->
project = msg.match[1]
room = msg.match[2]
phab.withProject msg, project, (projectData) ->
phab.withProject project, (projectData) ->
if projectData.error_info?
msg.send projectData.error_info
else
Expand All @@ -111,7 +111,7 @@ module.exports = (robot) ->
phab.withPermission msg, msg.envelope.user, 'phadmin', ->
project = msg.match[1]
room = msg.match[2]
phab.withProject msg, project, (projectData) ->
phab.withProject project, (projectData) ->
if projectData.error_info?
msg.send projectData.error_info
else
Expand Down
10 changes: 5 additions & 5 deletions scripts/phabs_commands.coffee
Expand Up @@ -44,7 +44,7 @@ module.exports = (robot) ->
project = msg.match[1]
name = msg.match[2]
description = msg.match[3]
phab.withProject msg, project, (projectData) ->
phab.withProject project, (projectData) ->
if projectData.error_info?
msg.send projectData.error_info
else
Expand Down Expand Up @@ -75,7 +75,7 @@ module.exports = (robot) ->

# hubot phab count <project> - counts how many tasks a project has
robot.respond (/ph(?:ab)? count ([-_a-zA-Z0-9]+)/), (msg) ->
phab.withProject msg, msg.match[1], (projectData) ->
phab.withProject msg.match[1], (projectData) ->
if projectData.error_info?
msg.send projectData.error_info
else
Expand All @@ -93,11 +93,11 @@ module.exports = (robot) ->
msg.send "Sorry, you don't have any task active right now."
msg.finish()
return
phab.taskInfo msg, id, (body) ->
phab.taskInfo id, (body) ->
if body['error_info']?
msg.send "oops T#{id} #{body['error_info']}"
else
phab.withUserByPhid robot, body.result.ownerPHID, (owner) ->
phab.withUserByPhid body.result.ownerPHID, (owner) ->
status = body.result.status
priority = body.result.priority
phab.recordPhid msg, id
Expand Down Expand Up @@ -232,7 +232,7 @@ module.exports = (robot) ->
robot.respond /ph(?:ab)? ([^ ]+) (.+)$/, (msg) ->
project = msg.match[1]
terms = msg.match[2]
phab.withProject msg, project, (projectData) ->
phab.withProject project, (projectData) ->
if projectData.error_info?
msg.send projectData.error_info
else
Expand Down
10 changes: 5 additions & 5 deletions scripts/phabs_hear.coffee
Expand Up @@ -37,7 +37,7 @@ module.exports = (robot) ->
switch

when 'T' is type
phab.taskInfo msg, id, (body) ->
phab.taskInfo id, (body) ->
if body['error_info']?
msg.send "oops #{type}#{id} #{body['error_info']}"
else
Expand All @@ -53,7 +53,7 @@ module.exports = (robot) ->
phab.recordPhid msg, id

when 'F' is type
phab.fileInfo msg, id, (body) ->
phab.fileInfo id, (body) ->
if body['error_info']?
msg.send "oops #{type}#{id} #{body['error_info']}"
else
Expand All @@ -66,7 +66,7 @@ module.exports = (robot) ->
"(#{body['result']['mimeType']} #{size})"

when 'P' is type
phab.pasteInfo msg, id, (body) ->
phab.pasteInfo id, (body) ->
if Object.keys(body['result']).length < 1
msg.send "oops #{type}#{id} was not found."
else
Expand All @@ -80,7 +80,7 @@ module.exports = (robot) ->
msg.send "#{body['result'][key]['uri']} - #{body['result'][key]['title']}#{lang}"

when /^M|B|Q|L|V$/.test type
phab.genericInfo msg, "#{type}#{id}", (body) ->
phab.genericInfo "#{type}#{id}", (body) ->
if Object.keys(body['result']).length < 1
msg.send "oops #{type}#{id} was not found."
else
Expand All @@ -97,7 +97,7 @@ module.exports = (robot) ->
return

when /^r[A-Z]+[a-f0-9]{10,}$/.test type
phab.genericInfo msg, type, (body) ->
phab.genericInfo type, (body) ->
if Object.keys(body['result']).length < 1
msg.send "oops #{type} was not found."
else
Expand Down

0 comments on commit 2a77250

Please sign in to comment.