Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: dpetersen/trampfire
base: fb1416267f
...
head fork: dpetersen/trampfire
compare: 2b049c37bc
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 12 files changed
  • 0 commit comments
  • 1 contributor
View
1  Procfile
@@ -4,3 +4,4 @@ image-bot: cd socket_server/bots/image && bundle exec ruby image_bot.rb
youtube-bot: cd socket_server/bots/youtube && bundle exec ruby youtube_bot.rb
github-bot: cd socket_server/bots/github && bundle exec ruby github_bot.rb
pivotal-tracker-bot: cd socket_server/bots/pivotal_tracker && bundle exec ruby pivotal_tracker_bot.rb
+deployment-bot: cd socket_server/bots/deployment && bundle exec ruby deployment_bot.rb
View
49 socket_server/bots/deployment/Rakefile
@@ -0,0 +1,49 @@
+require 'active_record'
+require 'logger'
+require 'fileutils'
+
+ActiveRecord::Base.establish_connection(
+ :adapter => "mysql2",
+ :host => "localhost",
+ :username => "root",
+ :password => "",
+ :database => "deployment_bot",
+ :encoding => 'utf8',
+ :reconnec => true
+)
+ActiveRecord::Base.logger = Logger.new(STDOUT)
+
+namespace :db do
+ desc "migrate your database"
+ task :migrate do
+ ActiveRecord::Migrator.migrate(
+ 'db/migrate',
+ ENV["VERSION"] ? ENV["VERSION"].to_i : nil
+ )
+ end
+
+ desc "create an ActiveRecord migration in ./db/migrate"
+ task :create_migration do
+ name = ENV['NAME']
+ abort("no NAME specified. use `rake db:create_migration NAME=create_users`") if !name
+
+ migrations_dir = File.join("db", "migrate")
+ version = ENV["VERSION"] || Time.now.utc.strftime("%Y%m%d%H%M%S")
+ filename = "#{version}_#{name}.rb"
+ migration_name = name.gsub(/_(.)/) { $1.upcase }.gsub(/^(.)/) { $1.upcase }
+
+ FileUtils.mkdir_p(migrations_dir)
+
+ open(File.join(migrations_dir, filename), 'w') do |f|
+ f << (<<-EOS).gsub(" ", "")
+ class #{migration_name} < ActiveRecord::Migration
+ def self.up
+ end
+
+ def self.down
+ end
+ end
+ EOS
+ end
+ end
+end
View
13 socket_server/bots/deployment/db/migrate/20111009012858_create_projects.rb
@@ -0,0 +1,13 @@
+class CreateProjects < ActiveRecord::Migration
+ def self.up
+ create_table :projects do |t|
+ t.string :clone_url
+ t.string :heroku_app_name
+ t.string :destination_tag_name
+ end
+ end
+
+ def self.down
+ drop_table :projects
+ end
+end
View
39 socket_server/bots/deployment/deployment_bot.rb
@@ -0,0 +1,39 @@
+require_relative '../../../lib/shared'
+require File.join(PATHS::SOCKET_SERVER::BOT_LIB, 'bot_essentials')
+
+require_relative 'models/models'
+require_relative 'lib/libs'
+
+class DeploymentBotRequest < BotRequestBase
+ handle_bot_event("fetch_projects") do
+ Project.all.as_json.to_json
+ end
+
+ handle_bot_event("create_project") do
+ project_attributes = JSON.parse(message_hash)
+ project = Project.create(project_attributes)
+
+ if project.persisted?
+ within_subprocess do
+ ProjectPreparer.prepare(project)
+ end
+ end
+
+ project.as_json(methods: :errors).to_json
+ end
+
+ def process_user_initiated_message
+ # TODO: Nothing to do here, should make this an optional method
+ end
+end
+
+class DeploymentBot < BotBase
+ REPO_STORAGE_PATH = File.join(File.dirname(__FILE__), "repositories")
+
+ def initialize
+ autoconnect_database
+ super
+ end
+end
+
+DeploymentBot.new
View
1  socket_server/bots/deployment/lib/libs.rb
@@ -0,0 +1 @@
+require_relative 'project_preparer'
View
26 socket_server/bots/deployment/lib/project_preparer.rb
@@ -0,0 +1,26 @@
+module ProjectPreparer
+ def self.prepare(project)
+ html = "Preparing to onboard new project '#{project.heroku_app_name}'"
+
+ message_object = MessageFromFactory.new(
+ project.destination_tag_name,
+ "DeploymentBot",
+ html
+ ).message
+
+ BotInitiatedInterprocessMessage.new(
+ "deployment_bot",
+ "project_prepare",
+ message_hash: message_object
+ ).send_to_asynchronous_pipe
+
+ output = `cd #{DeploymentBot::REPO_STORAGE_PATH} && git clone #{project.clone_url} #{project.id} --progress 2>&1`
+ output += `cd #{DeploymentBot::REPO_STORAGE_PATH}/#{project.id} && git remote add heroku git@heroku.com:#{project.heroku_app_name}.git`
+
+ html = "Project '#{project.heroku_app_name}' imported:"
+ html << "<pre>#{output}</pre>"
+ message_object["data"] = html
+
+ UserInitiatedInterprocessMessage.new(message_hash: message_object).send_to_asynchronous_pipe
+ end
+end
View
5 socket_server/bots/deployment/models/models.rb
@@ -0,0 +1,5 @@
+require 'active_record'
+
+ActiveRecord::Base.include_root_in_json = false
+
+require_relative 'project'
View
4 socket_server/bots/deployment/models/project.rb
@@ -0,0 +1,4 @@
+class Project < ActiveRecord::Base
+ validates :destination_tag_name, presence: true
+ validates :clone_url, :heroku_app_name, presence: true, uniqueness: true
+end
View
48 socket_server/bots/deployment/rack/preferences.rb
@@ -0,0 +1,48 @@
+require 'json'
+require 'haml'
+require 'sinatra'
+
+require File.join(PATHS::SOCKET_SERVER::LIB, 'interprocess_message')
+
+module DeploymentBot
+ module Rack
+ class Preferences < Sinatra::Base
+ set :views, File.dirname(__FILE__) + '/views'
+
+ get "/" do
+ @projects = \
+ NamedPipe.with_anonymous_pipe_for_reading do |pipe|
+ BotInitiatedInterprocessMessage.new(
+ "deployment",
+ "fetch_projects",
+ response_pipe: pipe
+ ).send_to_bot
+
+ pipe.read_json
+ end
+
+ haml :preferences
+ end
+
+ post "/projects" do
+ project = \
+ NamedPipe.with_anonymous_pipe_for_reading do |pipe|
+ BotInitiatedInterprocessMessage.new(
+ "deployment",
+ "create_project",
+ message_hash: params[:project].to_json,
+ response_pipe: pipe
+ ).send_to_bot
+
+ pipe.read_json
+ end
+
+ if project["id"].nil?
+ "Error saving project: #{project["errors"]}"
+ else
+ "Successfully saved project."
+ end
+ end
+ end
+ end
+end
View
17 socket_server/bots/deployment/rack/views/preferences.haml
@@ -0,0 +1,17 @@
+%h3 Current projects:
+%ul
+ - @projects.each do |project|
+ %li Clone URL: #{project["clone_url"]}, Heroku App Name: #{project["heroku_app_name"]}, Tag: #{project["destination_tag_name"]}
+
+%form{ action: "/bots/deployment/preferences/projects", method: "post" }
+
+ %label Clone URL
+ %input.medium{ type: "text", name: "project[clone_url]" }
+
+ %label Heroku App Name
+ %input.medium{ type: "text", name: "project[heroku_app_name]" }
+
+ %label Destination Tag
+ %input.medium{ type: "text", name: "project[destination_tag_name]" }
+
+ %input.btn.primary{ type: 'submit', value: "Save Project" }
View
1  socket_server/bots/deployment/repositories/.gitignore
@@ -0,0 +1 @@
+/*
View
2  socket_server/bots/pivotal_tracker/rack/views/preferences.haml
@@ -1,7 +1,7 @@
%h3 Current projects:
%ul
- @projects.each do |project|
- %li Repository: #{project["project_id"]}, Tag: #{project["destination_tag_name"]}
+ %li Project ID: #{project["project_id"]}, Tag: #{project["destination_tag_name"]}
%form{ action: "/bots/pivotal_tracker/preferences/projects", method: "post" }

No commit comments for this range

Something went wrong with that request. Please try again.