<commit_before># Description:
#   Deploy applications with pulsar
#
# Commands:
#   hubot deploy:pending <application> <environment> - Show pending changes
#   hubot deploy <application> <environment> - Deploy application

_ = require('underscore')
pulsarJobConfirmList = require('./pulsar-job-confirm-list')

module.exports = (robot) ->
  robot.respond /deploy (-v|)\s?([^\s]+) ([^\s]+)$/i, (chat) ->
    return unless robot.isAuthorized(chat)
    app = chat.match[2]
    env = chat.match[3]
    isVerbose = chat.match[1] == '-v'

    pending = pulsarApi.createJob(app, env, 'deploy:pending')
    pending.on('close', ()->
      chat.send "Pending changes for #{@app} #{@env}: #{@data.stdout}"
      return if(@data.status != 'FINISHED')
      deploy = pulsarApi.createJob(app, env, 'deploy')
      deploy.on('create', () ->
        chat.send "Job was created: #{@}. More info here #{@data.url}"
      ).on('close', () ->
        chat.send "#{@} finished with status: #{@data.status}. More details here #{@data.url}"
      ).on('error', () ->
        chat.send "#{@} failed due to #{JSON.stringify(error)}"
      )
      if isVerbose
        deploy.on('change', (output)->
          chat.send output
        )
      pulsarJobConfirmList.add(chat, deploy)
    ).on('error', (error)->
      chat.send "#{@} failed due to #{JSON.stringify(error)}"
    )
    pulsarApi.runJob(pending)
    chat.send pending + ' in progress'

  robot.respond /deploy pending ([^\s]+) ([^\s]+)$/i, (chat) ->
    return unless robot.isAuthorized(chat)
    job = pulsarApi.createJob(chat.match[1], chat.match[2], 'deploy:pending')
    job.on('close', () ->
      chat.send "Pending changes for #{@app} #{@env}: #{@data.stdout}"
    ).on('error', (error)->
      chat.send "#{@} failed due to #{JSON.stringify(error)}"
    )
    pulsarApi.runJob(job)

  robot.respond /((?:y(?:es)?)|(?:no?)|(?:ok))$/i, (chat) ->
    return unless robot.isAuthorized(chat)
    answer = chat.match[1]
    isYes = answer.charAt(0) == 'y' || answer.charAt(0) == 'o'
    if(isYes)
      job = pulsarJobConfirmList.get(chat)
      pulsarApi.runJob(job)
      chat.send job + ' in progress'
    else
      pulsarJobConfirmList.remove(chat)<commit_msg>Add new line after "Pending changes for #{@app} #{@env}".<commit_after># Description:
#   Deploy applications with pulsar
#
# Commands:
#   hubot deploy:pending <application> <environment> - Show pending changes
#   hubot deploy <application> <environment> - Deploy application

_ = require('underscore')
pulsarJobConfirmList = require('./pulsar-job-confirm-list')

module.exports = (robot) ->
  robot.respond /deploy (-v|)\s?([^\s]+) ([^\s]+)$/i, (chat) ->
    return unless robot.isAuthorized(chat)
    app = chat.match[2]
    env = chat.match[3]
    isVerbose = chat.match[1] == '-v'

    pending = pulsarApi.createJob(app, env, 'deploy:pending')
    pending.on('close', ()->
      chat.send "Pending changes for #{@app} #{@env}:\n#{@data.stdout}"
      return if(@data.status != 'FINISHED')
      deploy = pulsarApi.createJob(app, env, 'deploy')
      deploy.on('create', () ->
        chat.send "Job was created: #{@}. More info here #{@data.url}"
      ).on('close', () ->
        chat.send "#{@} finished with status: #{@data.status}. More details here #{@data.url}"
      ).on('error', () ->
        chat.send "#{@} failed due to #{JSON.stringify(error)}"
      )
      if isVerbose
        deploy.on('change', (output)->
          chat.send output
        )
      pulsarJobConfirmList.add(chat, deploy)
    ).on('error', (error)->
      chat.send "#{@} failed due to #{JSON.stringify(error)}"
    )
    pulsarApi.runJob(pending)
    chat.send pending + ' in progress'

  robot.respond /deploy pending ([^\s]+) ([^\s]+)$/i, (chat) ->
    return unless robot.isAuthorized(chat)
    job = pulsarApi.createJob(chat.match[1], chat.match[2], 'deploy:pending')
    job.on('close', () ->
      chat.send "Pending changes for #{@app} #{@env}:\n#{@data.stdout}"
    ).on('error', (error)->
      chat.send "#{@} failed due to #{JSON.stringify(error)}"
    )
    pulsarApi.runJob(job)

  robot.respond /((?:y(?:es)?)|(?:no?)|(?:ok))$/i, (chat) ->
    return unless robot.isAuthorized(chat)
    answer = chat.match[1]
    isYes = answer.charAt(0) == 'y' || answer.charAt(0) == 'o'
    if(isYes)
      job = pulsarJobConfirmList.get(chat)
      pulsarApi.runJob(job)
      chat.send job + ' in progress'
    else
      pulsarJobConfirmList.remove(chat)
{'fraction_non_alphanumeric': 0.1961797752808989, 'fraction_numerical': 0.0035955056179775282, 'mean_word_length': 3.098526703499079, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1730094', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1518, 'n_words': 317}