Module: Heidi::Shell

Defined in:
lib/heidi/shell.rb

Instance Method Summary collapse

Instance Method Details

#check_heidi_rootObject



10
11
12
13
14
15
# File 'lib/heidi/shell.rb', line 10

def check_heidi_root()
  if !File.exists?("./projects")  && File.directory?("./projects")
    $stderr.puts "You're not inside Heidi"
    exit 1
  end
end

#integrate(name) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/heidi/shell.rb', line 105

def integrate(name)
  heidi = Heidi.new
  heidi.projects.each do |project|
    next if !name.nil? && project.name != name

    project.fetch
    msg = project.integrate(!name.nil?)
    unless msg.nil? || msg == true
      $stderr.puts "#{project.name}: #{msg}"
    end
  end
end

#new_heidi_root(name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/heidi/shell.rb', line 31

def new_heidi_root(name)
  shout "creating #{name}/"
  shout "creating #{name}/projects"
  shell.mkdir %W(-p #{name}/projects)
  shell.mkdir %W(-p #{name}/bin)
  shout "creating #{name}/Gemfile"
  File.open("#{name}/Gemfile", File::CREAT|File::WRONLY) do |f|
    f.puts 'source "http://rubygems.org"'
    f.puts 'gem "heidi"'
  end

  shout "\nIf you like you can run: bundle install --binstubs"
  shout "this will tie heidi and heidi_web to this location"
  shout "\nFor even more tying down, run: bundle install --deployment"
  shout "after running bundle install --binstubs"
end

#new_project(name, repo, branch = "master") ⇒ Object



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
# File 'lib/heidi/shell.rb', line 48

def new_project(name, repo, branch="master")
  if File.exists? "projects/#{name}"
    $stderr.puts "projects/#{name} is in the way. Please remove it"
    exit 1
  end

  # create a logs dir
  shout "creating projects/#{name}"
  shout "creating projects/#{name}/logs"
  shell.mkdir %W(-p projects/#{name}/logs)

  %w(build tests failure success before).each do |hook|
    shout "creating projects/#{name}/hooks/#{hook}"
    shell.mkdir %W(-p projects/#{name}/hooks/#{hook})
  end

  # make a clone
  shell.in("projects/#{name}") do |sh|
    shout "filling #{name} cache"

    shout "git clone #{repo}"
    sh.git %W(clone #{repo} cached)

    sh.in("cached") do |cached|
      shout "setting the name of the project to: #{name}"
      cached.git %W(config heidi.name #{name})
      shout "setting the branch to: #{branch}"
      cached.git %W(config heidi.build.branch #{branch})
    end
  end

  shout "Creating default test hook: projects/#{name}/hooks/tests/01_rspec"
  File.open("projects/#{name}/hooks/tests/01_rspec", File::CREAT|File::WRONLY) do |f|
    f.puts %q(#!/bin/sh

# edit this file to your needs
bundle exec rake spec
)
  end
  shell.chmod %W(+x projects/#{name}/hooks/tests/01_rspec)
  shout "\n"
  shout "Now edit or add some hooks and run: heidi integrate #{name}"

end

#noisyObject



17
18
19
# File 'lib/heidi/shell.rb', line 17

def noisy
  @noisy=true
end

#remove_project(name) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/heidi/shell.rb', line 93

def remove_project(name)
  # remove build and cache dir, expose logs directly
  shout "removing build dir"
  shell.rm %W(-r projects/#{name}/build)
  shout "removing cache (preserving project config)"
  shell.cp %W(-pr projects/#{name}/cached/.git/config projects/#{name})
  shell.rm %W(-r projects/#{name}/cached)
  shout "exposing builds"
  shell.mv %W(projects/#{name}/logs/* projects/#{name}/)
  shell.rm %W(-r projects/#{name}/logs)
end

#shellObject



6
7
8
# File 'lib/heidi/shell.rb', line 6

def shell
  @shell ||= SimpleShell.new
end

#shout(msg) ⇒ Object



25
26
27
28
29
# File 'lib/heidi/shell.rb', line 25

def shout(msg)
  @noisy ||= false
  return if @noisy == false
  puts msg
end

#silentObject



21
22
23
# File 'lib/heidi/shell.rb', line 21

def silent
  @noisy=false
end