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

_ = require('underscore')

DeploymentMonitor = require('./deploy/monitor')
deploymentMonitor = new DeploymentMonitor()

module.exports = (robot) ->
  robot.respond /deploy pending ([^\s]+) ([^\s]+)$/i, (chat) ->
    app = chat.match[1]
    env = chat.match[2]
    chat.send "Getting changes…"

    job = pulsarApi.createJob(app, env, 'deploy:pending')
    job.on('success', () ->
      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 /deploy ([^\s]+) ([^\s]+)$/i, (chat) ->
    return unless robot.userHasRole(chat, 'deployer')
    if(deploymentMonitor.hasDeployJob())
      chat.send "Deploy job can not be started because #{deploymentMonitor.getDeployJob()} is in progress"
      return
    app = chat.match[1]
    env = chat.match[2]
    chat.send "Getting changes…"

    deployJob = pulsarApi.createJob(app, env, 'deploy')
    deploymentMonitor.setDeployJob(deployJob, chat)
    deployJob.on('create', () ->
      chat.send "Job was created: #{@}.\nMore info: #{@data.url}"
    ).on('success', () ->
      chat.send "#{@} finished."
    ).on('error', (error) ->
      chat.send "#{@} failed with error: #{JSON.stringify(error)}"
    )

    pendingJob = pulsarApi.createJob(app, env, 'deploy:pending')
    pendingJob.on('success', ()->
      deployJob.taskVariables = revision: @.taskVariables.revision
      chat.send "Pending changes for #{@app} #{@env}:\n#{@data.stdout}"
      chat.send "Please confirm that you still want to #{deployJob}.\nSay 'CONFIRM DEPLOY' or 'CANCEL DEPLOY'."
    ).on('error', (error)->
      deployJob.emit('error', error)
      chat.send "More info: #{@data.url}"
    )

    showNextRevisionJob = pulsarApi.createJob(app, env, 'deploy:show_next_revision')
    showNextRevisionJob.on('success', ()->
      if(!@data.stdout || !@data.stdout.trim())
        @.emit('error', new Error("#{@} does not have a revision number."))
        return
      revision = @data.stdout.trim()
      pendingJob.taskVariables = revision: revision
      pulsarApi.runJob(pendingJob)
    ).on('error', (error)->
      deployJob.emit('error', error)
      chat.send "More info: #{@data.url}"
    )
    pulsarApi.runJob(showNextRevisionJob)

  robot.respond /confirm deploy$/i, (chat) ->
    return unless robot.userHasRole(chat, 'deployer')
    if(!deploymentMonitor.hasDeployJob())
      chat.send 'No deploy job to confirm'
      return
    deployJob = deploymentMonitor.getDeployJob()
    pulsarApi.runJob(deployJob)
    chat.send deployJob + ' in progress'

  robot.respond /cancel deploy$/i, (chat) ->
    return unless robot.userHasRole(chat, 'deployer')
    if(!deploymentMonitor.hasDeployJob())
      chat.send 'No deploy job to cancel'
      return
    chat.send deploymentMonitor.getDeployJob() + ' cancelled'
    deploymentMonitor.removeDeployJob()
<commit_msg>Streamline chat conversation<commit_after># Description:
#   Deploy applications with pulsar
#
# Commands:
#   hubot deploy pending <application> <environment> - Show pending changes
#   hubot deploy <application> <environment> - Deploy application

_ = require('underscore')

DeploymentMonitor = require('./deploy/monitor')
deploymentMonitor = new DeploymentMonitor()

module.exports = (robot) ->
  robot.respond /deploy pending ([^\s]+) ([^\s]+)$/i, (chat) ->
    app = chat.match[1]
    env = chat.match[2]
    chat.send "Getting changes…"

    job = pulsarApi.createJob(app, env, 'deploy:pending')
    job.on('success', () ->
      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 /deploy ([^\s]+) ([^\s]+)$/i, (chat) ->
    return unless robot.userHasRole(chat, 'deployer')
    if(deploymentMonitor.hasDeployJob())
      chat.send "Deploy job can not be started because #{deploymentMonitor.getDeployJob()} is in progress"
      return
    app = chat.match[1]
    env = chat.match[2]
    chat.send "Getting changes…"

    deployJob = pulsarApi.createJob(app, env, 'deploy')
    deploymentMonitor.setDeployJob(deployJob, chat)
    deployJob.on('create', () ->
      chat.send "Deployment started.\nMore info: #{@data.url}"
    ).on('success', () ->
      chat.send "#{@} finished."
    ).on('error', (error) ->
      chat.send "Deployment failed: #{JSON.stringify(error)}"
    )

    pendingJob = pulsarApi.createJob(app, env, 'deploy:pending')
    pendingJob.on('success', ()->
      deployJob.taskVariables = revision: @.taskVariables.revision
      chat.send "Pending changes for #{@app} #{@env}:\n#{@data.stdout}"
      chat.send "Say 'CONFIRM DEPLOY' or 'CANCEL DEPLOY'."
    ).on('error', (error)->
      deployJob.emit('error', error)
      chat.send "More info: #{@data.url}"
    )

    showNextRevisionJob = pulsarApi.createJob(app, env, 'deploy:show_next_revision')
    showNextRevisionJob.on('success', ()->
      if(!@data.stdout || !@data.stdout.trim())
        @.emit('error', new Error("#{@} does not have a revision number."))
        return
      revision = @data.stdout.trim()
      pendingJob.taskVariables = revision: revision
      pulsarApi.runJob(pendingJob)
    ).on('error', (error)->
      deployJob.emit('error', error)
      chat.send "More info: #{@data.url}"
    )
    pulsarApi.runJob(showNextRevisionJob)

  robot.respond /confirm deploy$/i, (chat) ->
    return unless robot.userHasRole(chat, 'deployer')
    if(!deploymentMonitor.hasDeployJob())
      chat.send 'No deploy job to confirm'
      return
    deployJob = deploymentMonitor.getDeployJob()
    pulsarApi.runJob(deployJob)
    chat.send 'Deployment confirmed.'

  robot.respond /cancel deploy$/i, (chat) ->
    return unless robot.userHasRole(chat, 'deployer')
    if(!deploymentMonitor.hasDeployJob())
      chat.send 'No deploy job to cancel'
      return
    chat.send 'Deployment cancelled.'
    deploymentMonitor.removeDeployJob()

{'fraction_non_alphanumeric': 0.16173412254039354, 'fraction_numerical': 0.0012797952327627579, 'mean_word_length': 3.4593437945791727, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, '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': '6154917', 'n_tokens_mistral': 2040, 'n_tokens_neox': 1998, 'n_words': 443}