Class: Yadecli::Command::Composer::ComposerListCommand

Inherits:
Mutations::Command
  • Object
show all
Defined in:
lib/yadecli/command/composer/composer_list_command.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



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
# File 'lib/yadecli/command/composer/composer_list_command.rb', line 12

def execute
  composer_project_client = Yade::Composer::Rest::Client::ComposerProjectClient.new
  composer_service_client = Yade::Composer::Rest::Client::ComposerServiceClient.new

  composer_projects = composer_project_client.list

  # print table
  table = TTY::Table.new header: ['Id', 'Name', 'Services', 'Installed', 'Branches', 'Git Url']

  # add as rows to table
  composer_projects.each do |p|
    project_id = p.id
    project_name = p.name
    project_installed = p.installed?

    composer_services = composer_service_client.get_by_composer_project_id(project_id)
    service_names = composer_services.collect(&:name).join(', ')

    gitlab_client = Yadecli::Client::GitlabClient.new

    branches = gitlab_client.get_branch_names(p.git_repo_name)
    default_branch = gitlab_client.get_default_branch(p.git_repo_name)

    if project_installed
      current_branch = FileUtil.git_current_branch(p.install_dir)
    else
      current_branch = nil
    end

    branches = branches.map do |b|
      if b == default_branch && b == current_branch
        "#{b} (Default, Current)"
      elsif b == default_branch && b != current_branch
        "#{b} (Default)"
      elsif b == current_branch && b != default_branch
        "#{b} (Current)"
      else
        b
      end
    end

    table << [project_id, project_name, service_names , project_installed, branches.join(', '), p.gitUrl]
  end

  renderer = TTY::Table::Renderer::ASCII.new(table, padding: [0, 1])

  renderer.render
end