Class: DeployPlugin

Inherits:
Campfire::PollingBot::Plugin show all
Defined in:
lib/campfire/polling_bot/plugins/deploy/deploy_plugin.rb

Overview

Plugin to get a list of commits that are on deck to be deployed

Constant Summary

Constants inherited from Campfire::PollingBot::Plugin

Campfire::PollingBot::Plugin::HALT

Instance Attribute Summary

Attributes inherited from Campfire::PollingBot::Plugin

#bot, #config

Instance Method Summary collapse

Methods inherited from Campfire::PollingBot::Plugin

accepts, #accepts?, accepts?, bot, bot=, directory, directory=, inherited, #initialize, load_all, load_plugin_classes, #logger, logger, priority, #priority, requires_config, requires_config?, #requires_config?, setup_database, subclasses, #to_s

Constructor Details

This class inherits a constructor from Campfire::PollingBot::Plugin

Instance Method Details

#default_projectObject



110
111
112
113
# File 'lib/campfire/polling_bot/plugins/deploy/deploy_plugin.rb', line 110

def default_project
  (config && config['default_project']) ||
    (projects.size == 1 ? projects.keys.first : nil)
end

#helpObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/campfire/polling_bot/plugins/deploy/deploy_plugin.rb', line 95

def help
  help_lines = [
    ["what's on deck for <project>?", "shortlog of changes not yet deployed to production"],
    ["what's on deck for <project> staging?", "shortlog of changes not yet deployed to staging"],
  ]
  if default_project
    help_lines << ["what's on deck?", "shortlog of changes not yet deployed to #{default_project}"]
  end
  return help_lines
end

#process(message) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/campfire/polling_bot/plugins/deploy/deploy_plugin.rb', line 8

def process(message)
  case message.command
  when /deploy\s([^\s\!]+)(?:(?: to)? (staging|nine|production))?( with migrations)?/
    project, env, migrate = $1, $2, $3
    name = env ? "#{project} #{env}" : project
    env ||= "production"

    if not projects.any?
      bot.say("Sorry #{message.person}, I don't know about any projects. Please configure the deploy plugin.")
      return HALT
    end

    project ||= default_project
    if project.nil?
      bot.say("Sorry #{message.person}, I don't have a default project. Here are the projects I do know about:")
      bot.paste(projects.keys.sort.join("\n"))
      return HALT
    end
    project.downcase!

    info = project_info(project)
    if info.nil?
      bot.say("Sorry #{message.person}, I don't know anything about #{name}. Here are the projects I do know about:")
      bot.paste(projects.keys.sort.join("\n"))
      return HALT
    end

    bot.say("Okay, trying to deploy #{name}...")

    begin
      deploy = migrate ? "deploy:migrations" : "deploy"
      git(project, "bundle exec cap #{env} #{deploy}")
    rescue => e
      bot.log_error(e)
      bot.say("Sorry #{message.person}, I couldn't deploy #{name}.")
      return HALT
    end

    bot.say("Done.")
    return HALT

  when /on deck(?: for ([^\s\?]+)( staging)?)?/
    project, staging = $1, $2
    project ||= default_project
    name = staging ? "#{project} staging" : project

    if not projects.any?
      bot.say("Sorry #{message.person}, I don't know about any projects. Please configure the deploy plugin.")
      return HALT
    end

    if project.nil?
      bot.say("Sorry #{message.person}, I don't have a default project. Here are the projects I do know about:")
      bot.paste(projects.keys.sort.join("\n"))
      return HALT
    end
    project.downcase!

    info = project_info(project)
    if info.nil?
      bot.say("Sorry #{message.person}, I don't know anything about #{name}. Here are the projects I do know about:")
      bot.paste(projects.keys.sort.join("\n"))
      return HALT
    end

    range = nil
    begin
      range = "#{deployed_revision(project, staging)}..HEAD"
      shortlog = project_shortlog(project, range)
    rescue => e
      bot.log_error(e)
      bot.say("Sorry #{message.person}, I couldn't get what's on deck for #{name}.")
      return HALT
    end

    if shortlog.nil? || shortlog =~ /\A\s*\Z/
      bot.say("There's nothing on deck for #{name} right now.")
      return HALT
    end

    bot.say("Here's what's on deck for #{name}:")
    bot.paste("$ git shortlog #{range}\n\n#{shortlog}")

    return HALT
  end
end

#projectsObject



106
107
108
# File 'lib/campfire/polling_bot/plugins/deploy/deploy_plugin.rb', line 106

def projects
  (config && config['projects']) || {}
end