Skip to content

Commit

Permalink
Can now select the branch to deploy from
Browse files Browse the repository at this point in the history
  • Loading branch information
joelmoss committed Mar 23, 2012
1 parent ea5d5e2 commit ef1d48f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
5 changes: 1 addition & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ Strano::Application.load_tasks

# Make spec the default task and replace the test task.
task :test => :spec
task :default => :spec

require 'resque/tasks'
task "resque:setup" => :environment
task :default => :spec
13 changes: 10 additions & 3 deletions app/models/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Job < ActiveRecord::Base
default_scope order('created_at DESC')
default_scope where(:deleted_at => nil)

store :variables, :accessors => [ :branch ]


def self.deleted
self.unscoped.where 'deleted_at IS NOT NULL'
Expand All @@ -20,9 +22,8 @@ def run_task

FileUtils.chdir project.repo.path do
out = capture_stdout do
success = Strano::CLI.parse(Strano::Logger.new(self), full_command).execute!
success = Strano::CLI.parse(Strano::Logger.new(self), full_command.flatten).execute!
end

puts "\n \e[1;32m> #{out.string}\e" unless out.string.blank?
end

Expand Down Expand Up @@ -51,7 +52,13 @@ def results
private

def full_command
%W(-f #{Rails.root.join('Capfile.repos')} -f Capfile -Xx#{verbosity}) + command.split(' ')
%W(-f #{Rails.root.join('Capfile.repos')} -f Capfile -Xx#{verbosity}) + mapped_variables + command.split(' ')
end

def mapped_variables
variables.map do |k,v|
%W(-s #{k}=#{v}) unless v.blank?
end
end

def execute_task
Expand Down
6 changes: 4 additions & 2 deletions app/views/jobs/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
<%- if parent.cap.namespaces.keys.include?(:multistage) -%>
<%= f.input :stage, :as => :select, :collection => parent.cap.stages, :include_blank => false %>
<%- end -%>


<%= f.input :branch, :as => :select, :collection => parent.repo.branches, :include_blank => false, :selected => parent.cap.branch %>

<%= f.input :notes, :input_html => { :class => "span8", :rows => 5, :style => "height:80px;" } %>

<div class="control-group">
Expand All @@ -28,7 +30,7 @@
<%= f.input :verbosity, :as => :hidden %>

<div class="form-actions">
<%= f.button :submit, :disable_with => "Starting task..." %>
<%= f.button :submit, 'Start Task', :disable_with => "Starting task..." %>
<%= f.button :cancel, :url => parent_path %>
</div>

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20120323103049_add_variables_store_to_jobs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddVariablesStoreToJobs < ActiveRecord::Migration
def change
add_column :jobs, :variables, :text
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120322195922) do
ActiveRecord::Schema.define(:version => 20120323103049) do

create_table "jobs", :force => true do |t|
t.string "task"
Expand All @@ -26,6 +26,7 @@
t.datetime "deleted_at"
t.boolean "success", :default => true
t.string "verbosity", :default => "vvv"
t.text "variables"
end

create_table "projects", :force => true do |t|
Expand Down
13 changes: 12 additions & 1 deletion lib/strano/repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def self.pull(url)
repo = new(url)
repo.git.pull({:timeout => false, :chdir => repo.path, :base => false})
end

# Remove a cloned repo from the filesystem.
#
# url - The SSH URL of the git repository that this local repo is cloned from.
Expand All @@ -52,6 +52,17 @@ def path
File.join root_path, user_name, repo_name
end

# Returns an Array of all branches, remote and local.
def branches
str = git.branch({:timeout => false, :chdir => path, :base => false}, '-a')
branches = []
str.split("\n").each do |br|
branch = br.gsub(/\*/, '').strip.split(' ').first.split('/').last
branches << branch unless branch == 'HEAD'
end
branches.uniq
end

def git
@git ||= Grit::Git.new(path)
end
Expand Down

0 comments on commit ef1d48f

Please sign in to comment.