Class: EPC::Command::ShowProjectCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/show_project_command.rb

Constant Summary

Constants inherited from BaseCommand

BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#go, inherited, #initialize, #method_missing, required_arguments_count, required_options, #respond_to?

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class EPC::Command::BaseCommand

Instance Method Details

#execute(project_name = nil) ⇒ Object

Raises:



5
6
7
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
# File 'lib/epc/command/show_project_command.rb', line 5

def execute(project_name = nil)
  path = "."
  path = File.expand_path(path)

  solution_name = @options[:solution_name]

  solution_id, solution_name = infer_solution_context(solution_name, path)
  project_id, project_name = infer_project_context(project_name, path, solution_id)

  raise FatalError, "Project could not be found" if project_id.nil? || project_id == 0

  status, response, message = client.get(EPC::Config::PROJECTS_PATH + "/#{project_id}?include=dependencies,roles,config_values")
  if status.failure?
    say("Request failed: [#{response[:message]}]")
    return status
  end

  response[:created_at] = Time.parse(response[:created_at]).strftime("%m/%d/%Y %I:%M%p")
  response[:last_build_date] = Time.parse(response[:last_build_date]).strftime("%m/%d/%Y %I:%M%p") unless response[:last_build_date].nil? || response[:last_build_date] == "N/A"
  response[:last_push_date] = Time.parse(response[:last_push_date]).strftime("%m/%d/%Y %I:%M%p") unless response[:last_push_date].nil? || response[:last_push_date] == "N/A"
  response[:last_build_status] = nil if response[:last_build_status] == "N/A" # temp hack 
  response[:last_build_status] = (response[:last_build_status] ? "BUILT" : "FAILED" rescue nil) unless response[:last_build_status].nil?

  projects_table = EPC::TabularOutputter.new([response], {:id => "ID", :name => "NAME", :uri_name => "URI NAME", :created_at => "CREATED AT", :last_build_status => "BUILD STATUS", :last_build_date => "BUILD DATE", :last_build_version => "BUILD VERSION"})
  
  unless response[:dependency_definitions].nil? || response[:dependency_definitions].empty?
    dependencies = []
    response[:dependency_definitions].each do |dep_def|
      dependencies << {
        id:         dep_def[:dependency_id],
        project_id: dep_def[:dependency][:id],
        name: dep_def[:dependency][:name],
        type: dep_def[:dependency_kind]
      }
    end
  end

  response[:last_push_by_id] = response[:last_push_by][:id]
  response[:last_push_by_name] = response[:last_push_by][:name]
  last_push_table = EPC::TabularOutputter.new([response], {:last_push_by_id => "USER ID", :last_push_by_name => "USER NAME", :last_push_date => "DATE"})
  dependencies_table = EPC::TabularOutputter.new(dependencies, [:id, :project_id, :name, :type])

  config_values_table = EPC::TabularOutputter.new(response[:config_values], [:id, :name, :no_override, :value, :value_type, :required])
  roles_table = EPC::TabularOutputter.new(response[:roles], [:id, :name])

  say("\nProject details:")
  say(projects_table.print)
  
  say("\nLast push info:")
  say(last_push_table.print)

  unless dependencies.nil? || dependencies.empty?
    say("\nDependencies:")
    say(dependencies_table.print)
  end

  unless response[:config_values].nil? || response[:config_values].empty?
    say("\nConfig values:")
    say(config_values_table.print)
  end

  unless response[:roles].nil? || response[:roles].empty?
    say("\nRoles:")
    say(roles_table.print)
  end
  return status
end