Class: SchwarmCli::Commands::Repos

Inherits:
Base
  • Object
show all
Defined in:
lib/schwarm_cli/commands/repos.rb

Constant Summary

Constants inherited from Base

Base::DEFAULT_LIST_LIMIT

Instance Method Summary collapse

Methods inherited from Base

pagination_options

Instance Method Details

#createObject



34
35
36
37
38
39
# File 'lib/schwarm_cli/commands/repos.rb', line 34

def create
  handle_errors do
    data = client.repositories.create(**create_attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name", "Status" => "status" })
  end
end

#delete(id) ⇒ Object



56
57
58
59
60
61
# File 'lib/schwarm_cli/commands/repos.rb', line 56

def delete(id)
  handle_errors do
    client.repositories.destroy(id)
    puts "Repository #{id} deleted."
  end
end

#listObject



10
11
12
13
14
15
16
17
# File 'lib/schwarm_cli/commands/repos.rb', line 10

def list
  handle_errors do
    data = fetch_paged do |page_params|
      client.repositories.list(status: options[:status], query: options[:query], **page_params)
    end
    output_list(data, columns: [%w[ID id], %w[NAME name], %w[STATUS status]])
  end
end

#pause(id) ⇒ Object



64
65
66
67
68
69
# File 'lib/schwarm_cli/commands/repos.rb', line 64

def pause(id)
  handle_errors do
    data = client.repositories.pause(id)
    puts "Repository #{id} paused (#{data.dig('data', 'status')})."
  end
end

#resume(id) ⇒ Object



72
73
74
75
76
77
# File 'lib/schwarm_cli/commands/repos.rb', line 72

def resume(id)
  handle_errors do
    data = client.repositories.resume(id)
    puts "Repository #{id} resumed (#{data.dig('data', 'status')})."
  end
end

#show(id) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/schwarm_cli/commands/repos.rb', line 20

def show(id)
  handle_errors do
    data = client.repositories.find(id)
    output_record(data, fields: {
                    "ID" => "id", "Name" => "name", "URL" => "url",
                    "Status" => "status", "Base Branch" => "base_branch"
                  })
  end
end

#update(id) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/schwarm_cli/commands/repos.rb', line 44

def update(id)
  handle_errors do
    attrs = {}
    attrs[:name] = options[:name] if options[:name]
    attrs[:base_branch] = options[:base_branch] if options[:base_branch]

    data = client.repositories.update(id, **attrs)
    output_record(data, fields: { "ID" => "id", "Name" => "name", "Status" => "status" })
  end
end