UNPKG

1.14 kBtext/coffeescriptView Raw
1# Description:
2# enable http listener for Phabricator feed_http
3#
4# Configuration:
5# PHABRICATOR_URL
6# PHABRICATOR_API_KEY
7#
8# Urls:
9# /hubot/phabs/feeds
10#
11# Author:
12# mose
13#
14# Notes:
15# It's advised to protect this endpoint using
16# hubot-restrict-ip https://github.com/Gandi/hubot-restrict-ip
17# or a nginx/apache proxy
18#
19# Examples:
20# curl -XPOST -H "Content-Type: application/json" -d @test/samples/payload2 \
21# http://localhost:8080/Hubot/phabs/feeds
22
23Phabricator = require '../lib/phabricator'
24module.exports = (robot) ->
25
26 robot.phab ?= new Phabricator robot, process.env
27 phab = robot.phab
28
29 robot.router.post "/#{robot.name}/phabs/feeds", (req, res) ->
30 if req.body.storyID?
31 phab.getFeed(req.body)
32 .then (announce) ->
33 for room in announce.rooms
34 robot.messageRoom room, announce.message
35 robot.logger.debug "#{req.ip} - ok - #{res.statusCode}"
36 .catch (e) ->
37 robot.logger.debug "#{req.ip} - no - #{res.statusCode} - #{e}"
38 res.status(200).end()
39 else
40 robot.logger.debug "#{req.ip} - no - #{res.statusCode} - no story"
41 res.status(422).end()