Merge branch 'master' into production

This commit is contained in:
Nick Winter 2014-08-28 19:05:58 -07:00
commit 1d08a5b431
4 changed files with 29 additions and 3 deletions

View file

@ -88,6 +88,7 @@ class AudioPlayer extends CocoClass
@soundsToPlayWhenLoaded[name] = volume
playSound: (name, volume=1, delay=0, pos=null) ->
return console.error 'Trying to play empty sound?' unless name
audioOptions = {volume: (me.get('volume') ? 1) * volume, delay: delay}
filename = if _.string.startsWith(name, '/file/') then name else '/file/' + name
unless (filename of cache) and createjs.Sound.loadComplete filename

16
server/hipchat.coffee Normal file
View file

@ -0,0 +1,16 @@
config = require '../server_config'
request = require 'request'
log = require 'winston'
module.exports.sendHipChatMessage = sendHipChatMessage = (message) ->
return unless key = config.hipchatAPIKey
roomID = 254598
form =
color: 'yellow'
notify: false
message: message
messageFormat: 'html'
url = "https://api.hipchat.com/v2/room/#{roomID}/notification?auth_token=#{key}"
request.post {uri: url, json: form}, (err, res, body) ->
return log.error 'Error sending HipChat patch request:', err or body if err or /error/.test body
#log.info "Got HipChat patch response:", body

View file

@ -6,6 +6,7 @@ schema = require '../../app/schemas/models/patch'
mongoose = require 'mongoose'
log = require 'winston'
sendwithus = require '../sendwithus'
hipchat = require '../hipchat'
PatchHandler = class PatchHandler extends Handler
modelClass: Patch
@ -75,14 +76,16 @@ PatchHandler = class PatchHandler extends Handler
onPostSuccess: (req, doc) ->
log.error 'Error sending patch created: could not find the loaded target on the patch object.' unless doc.targetLoaded
return unless doc.targetLoaded
docLink = "http://codecombat.com#{req.headers['x-current-path']}"
@sendPatchCreatedHipChatMessage creator: req.user, patch: doc, target: doc.targetLoaded, docLink: docLink
watchers = doc.targetLoaded.get('watchers') or []
watchers = (w for w in watchers when not w.equals(req.user.get('_id')))
return unless watchers?.length
User.find({_id: {$in: watchers}}).select({email: 1, name: 1}).exec (err, watchers) =>
for watcher in watchers
@sendPatchCreatedEmail req.user, watcher, doc, doc.targetLoaded, req.headers['x-current-path']
@sendPatchCreatedEmail req.user, watcher, doc, doc.targetLoaded, docLink
sendPatchCreatedEmail: (patchCreator, watcher, patch, target, editPath) ->
sendPatchCreatedEmail: (patchCreator, watcher, patch, target, docLink) ->
# return if watcher._id is patchCreator._id
context =
email_id: sendwithus.templates.patch_created
@ -92,8 +95,12 @@ PatchHandler = class PatchHandler extends Handler
email_data:
doc_name: target.get('name') or '???'
submitter_name: patchCreator.get('name') or '???'
doc_link: "http://codecombat.com#{editPath}"
doc_link: docLink
commit_message: patch.get('commitMessage')
sendwithus.api.send context, (err, result) ->
sendPatchCreatedHipChatMessage: (options) ->
message = "#{options.creator.get('name')} submitted a patch to <a href=\"#{options.docLink}\">#{options.target.get('name')}</a>: #{options.patch.get('commitMessage')}"
hipchat.sendHipChatMessage message
module.exports = new PatchHandler()

View file

@ -41,6 +41,8 @@ config.mail =
cronHandlerPublicIP: process.env.COCO_CRON_PUBLIC_IP or ''
cronHandlerPrivateIP: process.env.COCO_CRON_PRIVATE_IP or ''
config.hipchatAPIKey = process.env.COCO_HIPCHAT_API_KEY or ''
config.queue =
accessKeyId: process.env.COCO_AWS_ACCESS_KEY_ID or ''
secretAccessKey: process.env.COCO_AWS_SECRET_ACCESS_KEY or ''