taiyoh's memorandum

@ttaiyoh が、技術ネタで気づいたことを書き溜めておきます。

Ukigumo + hubot-ircでビルド結果を通知

 hubotをIRC通知するやり方はあちこちで書かれてるが、僕としてはhubot-irc-runnableを使った方がカジュアルなのでオススメ。
 →jgable/hubot-irc-runnable · GitHub
 その上で、scripts/httpd.coffeeに以下のコードを追加する

  #http://chobie.hatenablog.com/entry/2012/02/26/125532
  robot.router.post "/hubot/say", (req, res) ->
    room = req.body.channel
    message = req.body.message
    #user = robot.userForId room # これだと動かない
    user = robot.adapter.userForId room
    user.room = room
    user.type = 'groupchat'
    robot.send user, "#{message}"
    res.writeHead 200, {'Content-Type': 'text/plain'}
    res.end 'OK'

こうすると、POST /hubot/sayにリクエストを送ればmessageパラメータの内容をchannelパラメータで指定したチャンネルに対して投稿してくれる。これでhubotにもikachanの機能が追加される。
なので、

$app->push_notifier(
    Ukigumo::Client::Notify::Ikachan->new(
        url     => 'http://example.com/hubot',
        channel => '#your-channel',
        method  => 'say'
    )
);

 Ukigumo::Clientのpush_notifierでNotify::Ikachanがそのまま使えるようになる。methodの指定が必要だから、同梱されてるukigumo-client.plとは別でスクリプトを用意しないといけないけど、/hubot/noticeのパスで受け取れるようにしておけばそのまま使える。