class Lita::Handlers::Teamcity

Public Instance Methods

build(response) click to toggle source
# File lib/lita/handlers/teamcity.rb, line 33
def build(response)
  Lita.logger.debug(response.matches)
  Lita.logger.debug(response.args)
  Lita.logger.debug(response.room.metadata)
  options = {
    comment: {text: "Triggered by #{response.user.name} in room #{response.room.name} via chatbot"},
  }
  options[:branchName] = response.args[2] if response.args[2]

  result = client.create_buildqueue(response.args[1], options)
  Lita.logger.debug(result)

  message = {
    title: 'Done!',
    text: render_template('build', build: result),
  }
  reply(response, message)
end
builds(response) click to toggle source
# File lib/lita/handlers/teamcity.rb, line 23
def builds(response)
  records = client.builds
  Lita.logger.debug(records)
  message = {
    title: 'Builds',
    text: render_template('builds', builds: records),
  }
  reply(response, message)
end
projects(response) click to toggle source
# File lib/lita/handlers/teamcity.rb, line 14
def projects(response)
  message = {
    title: 'Projects',
    text: render_template('projects', projects: client.projects),
  }
  
  reply(response, message)
end

Private Instance Methods

client() click to toggle source
# File lib/lita/handlers/teamcity.rb, line 53
def client
  @_client ||= ::TeamCity::Client.new(endpoint: config.endpoint, http_user: config.user, http_password: config.password)
end
reply(response, message) click to toggle source
# File lib/lita/handlers/teamcity.rb, line 57
def reply(response, message)
  Lita.logger.info(message[:text])
  case robot.config.robot.adapter
  when :slack
    _message = {
      mrkdwn: true,
      color: '#36a64f',
    }.merge(message)
    attachment = Lita::Adapters::Slack::Attachment.new(message[:text], _message)
    robot.chat_service.send_attachment(response.room, attachment)
  else
    response.reply(message[:title], message[:text])
  end
end