cp8_cli 4.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +4 -0
  4. data/CODE_OF_CONDUCT.md +49 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +19 -0
  8. data/Rakefile +11 -0
  9. data/cp8_cli.gemspec +42 -0
  10. data/exe/cp8 +34 -0
  11. data/exe/git-cleanup +7 -0
  12. data/exe/git-finish +19 -0
  13. data/exe/git-open +7 -0
  14. data/exe/git-start +7 -0
  15. data/lib/cp8_cli.rb +9 -0
  16. data/lib/cp8_cli/branch.rb +61 -0
  17. data/lib/cp8_cli/branch_name.rb +30 -0
  18. data/lib/cp8_cli/cleanup.rb +36 -0
  19. data/lib/cp8_cli/command.rb +61 -0
  20. data/lib/cp8_cli/config_store.rb +32 -0
  21. data/lib/cp8_cli/current_user.rb +29 -0
  22. data/lib/cp8_cli/github/base.rb +13 -0
  23. data/lib/cp8_cli/github/issue.rb +92 -0
  24. data/lib/cp8_cli/github/parsed_short_link.rb +25 -0
  25. data/lib/cp8_cli/github/parsed_url.rb +25 -0
  26. data/lib/cp8_cli/global_config.rb +51 -0
  27. data/lib/cp8_cli/local_config.rb +29 -0
  28. data/lib/cp8_cli/main.rb +74 -0
  29. data/lib/cp8_cli/pull_request.rb +63 -0
  30. data/lib/cp8_cli/repo.rb +21 -0
  31. data/lib/cp8_cli/story_query.rb +23 -0
  32. data/lib/cp8_cli/table.rb +38 -0
  33. data/lib/cp8_cli/table/row.rb +45 -0
  34. data/lib/cp8_cli/trello/base.rb +36 -0
  35. data/lib/cp8_cli/trello/board.rb +13 -0
  36. data/lib/cp8_cli/trello/card.rb +71 -0
  37. data/lib/cp8_cli/trello/error.rb +5 -0
  38. data/lib/cp8_cli/trello/error_handler.rb +15 -0
  39. data/lib/cp8_cli/trello/json_parser.rb +13 -0
  40. data/lib/cp8_cli/trello/label.rb +15 -0
  41. data/lib/cp8_cli/trello/list.rb +32 -0
  42. data/lib/cp8_cli/trello/member.rb +11 -0
  43. data/lib/cp8_cli/version.rb +27 -0
  44. metadata +357 -0
@@ -0,0 +1,23 @@
1
+ module Cp8Cli
2
+ class StoryQuery
3
+ def initialize(short_link)
4
+ @short_link = short_link
5
+ end
6
+
7
+ def find
8
+ if github_issue?
9
+ Github::Issue.find_by_short_link(short_link)
10
+ else
11
+ Trello::Card.find(short_link)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :short_link
18
+
19
+ def github_issue?
20
+ short_link.include?("#")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ require "cp8_cli/table/row"
2
+
3
+ module Cp8Cli
4
+ class Table
5
+ def self.pick(records, caption: "Pick one:")
6
+ new(records).pick(caption)
7
+ end
8
+
9
+ def initialize(records)
10
+ @records = records.to_a.sort_by(&:position)
11
+ end
12
+
13
+ def pick(caption)
14
+ return if records.none?
15
+ render_table
16
+ index = Command.ask(caption, Integer)
17
+ records[index - 1]
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :records
23
+
24
+ def render_table
25
+ if records.size > 0
26
+ Command.table rows
27
+ else
28
+ Command.say "No records found"
29
+ end
30
+ end
31
+
32
+ def rows
33
+ records.each_with_index.map do |record, index|
34
+ Row.new(record, index).to_h
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,45 @@
1
+ module Cp8Cli
2
+ class Table
3
+ class Row
4
+ attr_reader :num
5
+
6
+ COLOR_TRANSLATIONS = {
7
+ "purple" => "magenta",
8
+ "orange" => "yellow",
9
+ "sky" => "cyan",
10
+ "pink" => "red",
11
+ "lime" => "green"
12
+ }
13
+
14
+ def initialize(record, index)
15
+ @record = record
16
+ @num = index + 1
17
+ end
18
+
19
+ def to_h
20
+ result = { "#": num }
21
+ fields.each do |field|
22
+ result[field] = colorize record.send(field)
23
+ end
24
+ result
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :num, :record
30
+
31
+ def colorize(str)
32
+ return str unless record.respond_to?(:color)
33
+ "■".send(color) + " #{str}"
34
+ end
35
+
36
+ def color
37
+ COLOR_TRANSLATIONS[record.color] || record.color || :white
38
+ end
39
+
40
+ def fields
41
+ @_fields ||= record.class.fields
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ require "spyke"
2
+ require "cp8_cli/trello/json_parser"
3
+ require "cp8_cli/trello/error_handler"
4
+
5
+ module Cp8Cli
6
+ module Trello
7
+ class Base < Spyke::Base
8
+ require "cp8_cli/trello/board"
9
+ require "cp8_cli/trello/card"
10
+ require "cp8_cli/trello/label"
11
+ require "cp8_cli/trello/list"
12
+ require "cp8_cli/trello/member"
13
+
14
+ include_root_in_json false
15
+ cattr_accessor :token
16
+
17
+ def self.configure(key:, token:)
18
+ self.connection = Faraday.new(url: "https://api.trello.com/1", params: { key: key, token: token }) do |c|
19
+ c.request :json
20
+ c.use JSONParser
21
+ c.use ErrorHandler
22
+ c.adapter Faraday.default_adapter
23
+
24
+ # For trello api logging
25
+ # require "faraday/conductivity"
26
+ # c.use Faraday::Conductivity::ExtendedLogging
27
+ end
28
+ self.token = token
29
+ end
30
+
31
+ def position
32
+ self[:pos].to_f
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,13 @@
1
+ module Cp8Cli
2
+ module Trello
3
+ class Board < Base
4
+ has_many :lists
5
+ has_many :labels
6
+ scope :active, -> { where(filter: "open") }
7
+
8
+ def self.fields
9
+ [:name]
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,71 @@
1
+ module Cp8Cli
2
+ module Trello
3
+ class Card < Base
4
+ belongs_to :board, foreign_key: "idBoard"
5
+
6
+ def self.fields
7
+ [:title]
8
+ end
9
+
10
+ def self.find_by_url(url)
11
+ card = Card.new(url: url)
12
+ find(card.short_link)
13
+ end
14
+
15
+ def title
16
+ name
17
+ end
18
+
19
+ def pr_title
20
+ "#{title} [Delivers ##{short_link}]"
21
+ end
22
+
23
+ def summary
24
+ "Trello: #{short_url}"
25
+ end
26
+
27
+ def start
28
+ move_to board.lists.started
29
+ end
30
+
31
+ def finish
32
+ move_to board.lists.finished
33
+ end
34
+
35
+ def accept
36
+ move_to board.lists.accepted
37
+ end
38
+
39
+ def assign(user)
40
+ return if member_ids.include?(user.trello_id)
41
+ self.class.request(:post, "cards/#{id}/members", value: user.trello_id)
42
+ end
43
+
44
+ def add_label(label)
45
+ self.class.request(:post, "cards/#{id}/idLabels", value: label.id)
46
+ end
47
+
48
+ def attach(url:)
49
+ self.class.request(:post, "cards/#{id}/attachments", url: url)
50
+ end
51
+
52
+ def short_link
53
+ url.scan(/\/c\/(.+)\//).flatten.first
54
+ end
55
+
56
+ def short_url
57
+ attributes[:shortUrl]
58
+ end
59
+
60
+ private
61
+
62
+ def move_to(list)
63
+ self.class.with("cards/:id/idList").where(id: id, value: list.id).put
64
+ end
65
+
66
+ def member_ids
67
+ attributes["idMembers"] || []
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ module Cp8Cli
2
+ module Trello
3
+ class Error < StandardError; end
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ require "cp8_cli/trello/error"
2
+
3
+ module Cp8Cli
4
+ module Trello
5
+ class ErrorHandler < Faraday::Middleware
6
+ def call(env)
7
+ @app.call(env).on_complete do
8
+ if !env.success?
9
+ raise Error, env[:body]
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ require "multi_json"
2
+
3
+ module Cp8Cli
4
+ module Trello
5
+ class JSONParser < Faraday::Response::Middleware
6
+ def parse(body)
7
+ return if body.blank?
8
+ json = MultiJson.load(body, symbolize_keys: true)
9
+ { data: json }
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ module Cp8Cli
2
+ module Trello
3
+ class Label < Base
4
+ has_many :cards
5
+
6
+ def self.fields
7
+ [:name]
8
+ end
9
+
10
+ def position
11
+ name.downcase
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ module Cp8Cli
2
+ module Trello
3
+ class List < Base
4
+ BACKLOG_INDEX = 0
5
+ STARTED_INDEX = 1
6
+ FINISHED_INDEX = 2
7
+ ACCEPTED_INDEX = 3
8
+
9
+ has_many :cards
10
+
11
+ def self.fields
12
+ [:name]
13
+ end
14
+
15
+ def self.backlog
16
+ all[BACKLOG_INDEX]
17
+ end
18
+
19
+ def self.started
20
+ all[STARTED_INDEX]
21
+ end
22
+
23
+ def self.finished
24
+ all[FINISHED_INDEX]
25
+ end
26
+
27
+ def self.accepted
28
+ all[ACCEPTED_INDEX]
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ module Cp8Cli
2
+ module Trello
3
+ class Member < Base
4
+ has_many :boards
5
+
6
+ def self.current
7
+ with("tokens/#{token}/member").find_one
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module Cp8Cli
2
+ VERSION = "4.0.1"
3
+
4
+ class Version
5
+ def self.latest?
6
+ new.latest?
7
+ end
8
+
9
+ def latest?
10
+ latest_version <= current_version
11
+ end
12
+
13
+ private
14
+
15
+ def latest_version
16
+ @_latest_version ||= Gem.latest_version_for("cp8_cli") || first_version
17
+ end
18
+
19
+ def current_version
20
+ @_current_version ||= Gem::Version.new(VERSION)
21
+ end
22
+
23
+ def first_version
24
+ @_first_version ||= Gem::Version.new("1.0.0")
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,357 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cp8_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jens Balvig
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-line
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday-conductivity
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: colored
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: highline
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: hirb
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: hirb-colors
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :runtime
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: hirb-unicode
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :runtime
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: launchy
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: multi_json
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: octokit
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :runtime
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
+ - !ruby/object:Gem::Dependency
238
+ name: spyke
239
+ requirement: !ruby/object:Gem::Requirement
240
+ requirements:
241
+ - - ">="
242
+ - !ruby/object:Gem::Version
243
+ version: '0'
244
+ type: :runtime
245
+ prerelease: false
246
+ version_requirements: !ruby/object:Gem::Requirement
247
+ requirements:
248
+ - - ">="
249
+ - !ruby/object:Gem::Version
250
+ version: '0'
251
+ - !ruby/object:Gem::Dependency
252
+ name: thor
253
+ requirement: !ruby/object:Gem::Requirement
254
+ requirements:
255
+ - - ">="
256
+ - !ruby/object:Gem::Version
257
+ version: '0'
258
+ type: :runtime
259
+ prerelease: false
260
+ version_requirements: !ruby/object:Gem::Requirement
261
+ requirements:
262
+ - - ">="
263
+ - !ruby/object:Gem::Version
264
+ version: '0'
265
+ - !ruby/object:Gem::Dependency
266
+ name: trollop
267
+ requirement: !ruby/object:Gem::Requirement
268
+ requirements:
269
+ - - ">="
270
+ - !ruby/object:Gem::Version
271
+ version: '0'
272
+ type: :runtime
273
+ prerelease: false
274
+ version_requirements: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ description: Cookpad Global CLI.
280
+ email:
281
+ - jens@balvig.com
282
+ executables:
283
+ - cp8
284
+ - git-cleanup
285
+ - git-finish
286
+ - git-open
287
+ - git-start
288
+ extensions: []
289
+ extra_rdoc_files: []
290
+ files:
291
+ - ".gitignore"
292
+ - ".travis.yml"
293
+ - CODE_OF_CONDUCT.md
294
+ - Gemfile
295
+ - LICENSE.txt
296
+ - README.md
297
+ - Rakefile
298
+ - cp8_cli.gemspec
299
+ - exe/cp8
300
+ - exe/git-cleanup
301
+ - exe/git-finish
302
+ - exe/git-open
303
+ - exe/git-start
304
+ - lib/cp8_cli.rb
305
+ - lib/cp8_cli/branch.rb
306
+ - lib/cp8_cli/branch_name.rb
307
+ - lib/cp8_cli/cleanup.rb
308
+ - lib/cp8_cli/command.rb
309
+ - lib/cp8_cli/config_store.rb
310
+ - lib/cp8_cli/current_user.rb
311
+ - lib/cp8_cli/github/base.rb
312
+ - lib/cp8_cli/github/issue.rb
313
+ - lib/cp8_cli/github/parsed_short_link.rb
314
+ - lib/cp8_cli/github/parsed_url.rb
315
+ - lib/cp8_cli/global_config.rb
316
+ - lib/cp8_cli/local_config.rb
317
+ - lib/cp8_cli/main.rb
318
+ - lib/cp8_cli/pull_request.rb
319
+ - lib/cp8_cli/repo.rb
320
+ - lib/cp8_cli/story_query.rb
321
+ - lib/cp8_cli/table.rb
322
+ - lib/cp8_cli/table/row.rb
323
+ - lib/cp8_cli/trello/base.rb
324
+ - lib/cp8_cli/trello/board.rb
325
+ - lib/cp8_cli/trello/card.rb
326
+ - lib/cp8_cli/trello/error.rb
327
+ - lib/cp8_cli/trello/error_handler.rb
328
+ - lib/cp8_cli/trello/json_parser.rb
329
+ - lib/cp8_cli/trello/label.rb
330
+ - lib/cp8_cli/trello/list.rb
331
+ - lib/cp8_cli/trello/member.rb
332
+ - lib/cp8_cli/version.rb
333
+ homepage: https://github.com/balvig/cp8_cli
334
+ licenses:
335
+ - MIT
336
+ metadata: {}
337
+ post_install_message:
338
+ rdoc_options: []
339
+ require_paths:
340
+ - lib
341
+ required_ruby_version: !ruby/object:Gem::Requirement
342
+ requirements:
343
+ - - ">="
344
+ - !ruby/object:Gem::Version
345
+ version: '0'
346
+ required_rubygems_version: !ruby/object:Gem::Requirement
347
+ requirements:
348
+ - - ">="
349
+ - !ruby/object:Gem::Version
350
+ version: '0'
351
+ requirements: []
352
+ rubyforge_project:
353
+ rubygems_version: 2.6.11
354
+ signing_key:
355
+ specification_version: 4
356
+ summary: Cookpad Global CLI.
357
+ test_files: []