Class: Fizzy::CLI::Cards

Inherits:
Thor
  • Object
show all
Includes:
Base
Defined in:
lib/fizzy/cli/cards.rb

Instance Method Summary collapse

Methods included from Base

included

Instance Method Details

#assign(number, assignee_id) ⇒ Object



136
137
138
139
# File 'lib/fizzy/cli/cards.rb', line 136

def assign(number, assignee_id)
  client.post("cards/#{number}/assignments", body: { assignee_id: assignee_id })
  puts "Assignment toggled for card ##{number}."
end

#close(number) ⇒ Object



98
99
100
101
# File 'lib/fizzy/cli/cards.rb', line 98

def close(number)
  client.post("cards/#{number}/closure")
  puts "Card ##{number} closed."
end

#create(title) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fizzy/cli/cards.rb', line 57

def create(title)
  payload = { title: title }
  payload[:description] = options[:body] if options[:body]
  resp = client.post("boards/#{require_board!}/cards", body: payload)
  c = resp.body
  client.post("cards/#{c["number"]}/triage", body: { column_id: options[:column] }) if options[:column]
  output_detail(c, pairs: [
                  ["Number", "##{c["number"]}"],
                  ["Title", c["title"]],
                  ["URL", c["url"]]
                ])
end

#delete(number) ⇒ Object



92
93
94
95
# File 'lib/fizzy/cli/cards.rb', line 92

def delete(number)
  client.delete("cards/#{number}")
  puts "Card ##{number} deleted."
end

#get(number) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fizzy/cli/cards.rb', line 35

def get(number)
  resp = client.get("cards/#{number}")
  c = resp.body
  output_detail(c, pairs: [
                  ["Number", "##{c["number"]}"],
                  ["Title", c["title"]],
                  ["Board", c.dig("board", "name")],
                  ["Column", c.dig("column", "name")],
                  ["Status", c["status"]],
                  ["Creator", c.dig("creator", "name")],
                  ["Assignees", format_assignees(c["assignees"])],
                  ["Tags", format_tags(c["tags"])],
                  ["Steps", format_steps(c["steps"])],
                  ["Created", c["created_at"]],
                  ["URL", c["url"]]
                ])
end

#golden(number) ⇒ Object



154
155
156
157
# File 'lib/fizzy/cli/cards.rb', line 154

def golden(number)
  client.post("cards/#{number}/goldness")
  puts "Card ##{number} marked golden."
end

#listObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fizzy/cli/cards.rb', line 14

def list
  params = {}
  params[:status] = options[:status] if options[:status]
  params[:board_id] = options[:board] if options[:board]
  params[:column_id] = options[:column] if options[:column]
  params[:assignee_id] = options[:assignee] if options[:assignee]
  options[:tag]&.each { |t| (params[:"tag_ids[]"] ||= []) << t }

  data = paginator.all("cards", params: params)
  output_list(data, headers: %w[# Title Board Status Column]) do |c|
    [
      c["number"],
      Formatter.truncate(c["title"], 50),
      c.dig("board", "name") || "",
      c["status"],
      c.dig("column", "name") || ""
    ]
  end
end

#not_now(number) ⇒ Object



111
112
113
114
# File 'lib/fizzy/cli/cards.rb', line 111

def not_now(number)
  client.post("cards/#{number}/not_now")
  puts "Card ##{number} marked not-now."
end

#reopen(number) ⇒ Object



104
105
106
107
# File 'lib/fizzy/cli/cards.rb', line 104

def reopen(number)
  client.delete("cards/#{number}/closure")
  puts "Card ##{number} reopened."
end

#tag(number, tag_title) ⇒ Object



130
131
132
133
# File 'lib/fizzy/cli/cards.rb', line 130

def tag(number, tag_title)
  client.post("cards/#{number}/taggings", body: { tag_title: tag_title })
  puts "Tag '#{tag_title}' added to card ##{number}."
end

#triage(number) ⇒ Object



118
119
120
121
# File 'lib/fizzy/cli/cards.rb', line 118

def triage(number)
  client.post("cards/#{number}/triage", body: { column_id: options[:column] })
  puts "Card ##{number} triaged."
end

#ungolden(number) ⇒ Object



160
161
162
163
# File 'lib/fizzy/cli/cards.rb', line 160

def ungolden(number)
  client.delete("cards/#{number}/goldness")
  puts "Card ##{number} ungolden."
end

#untriage(number) ⇒ Object



124
125
126
127
# File 'lib/fizzy/cli/cards.rb', line 124

def untriage(number)
  client.delete("cards/#{number}/triage")
  puts "Card ##{number} untriaged."
end

#unwatch(number) ⇒ Object



148
149
150
151
# File 'lib/fizzy/cli/cards.rb', line 148

def unwatch(number)
  client.delete("cards/#{number}/watch")
  puts "Unwatched card ##{number}."
end

#update(number) ⇒ Object

Raises:

  • (Thor::Error)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/fizzy/cli/cards.rb', line 73

def update(number)
  payload = {}
  payload[:title] = options[:title] if options[:title]
  payload[:description] = options[:body] if options[:body]
  raise Thor::Error, "Nothing to update. Provide --title or --body" if payload.empty?

  resp = client.put("cards/#{number}", body: payload)
  c = resp.body
  if c
    output_detail(c, pairs: [
                    ["Number", "##{c["number"]}"],
                    ["Title", c["title"]]
                  ])
  else
    puts "Card ##{number} updated."
  end
end

#watch(number) ⇒ Object



142
143
144
145
# File 'lib/fizzy/cli/cards.rb', line 142

def watch(number)
  client.post("cards/#{number}/watch")
  puts "Watching card ##{number}."
end