cp8_cli 6.0.1 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -1
  3. data/cp8_cli.gemspec +2 -6
  4. data/exe/cp8 +3 -4
  5. data/lib/cp8_cli.rb +0 -1
  6. data/lib/cp8_cli/adhoc_story.rb +7 -38
  7. data/lib/cp8_cli/branch.rb +15 -35
  8. data/lib/cp8_cli/branch_name.rb +16 -13
  9. data/lib/cp8_cli/ci.rb +1 -1
  10. data/lib/cp8_cli/command.rb +8 -9
  11. data/lib/cp8_cli/commands/open.rb +1 -1
  12. data/lib/cp8_cli/commands/start.rb +5 -8
  13. data/lib/cp8_cli/commands/submit.rb +1 -10
  14. data/lib/cp8_cli/commands/suggest.rb +2 -1
  15. data/lib/cp8_cli/config_store.rb +2 -0
  16. data/lib/cp8_cli/current_user.rb +4 -12
  17. data/lib/cp8_cli/github/api.rb +29 -0
  18. data/lib/cp8_cli/github/issue.rb +16 -37
  19. data/lib/cp8_cli/github/pull_request.rb +27 -11
  20. data/lib/cp8_cli/global_config.rb +0 -24
  21. data/lib/cp8_cli/main.rb +1 -2
  22. data/lib/cp8_cli/pull_request_body.rb +1 -1
  23. data/lib/cp8_cli/pull_request_title.rb +1 -1
  24. data/lib/cp8_cli/repo.rb +8 -8
  25. data/lib/cp8_cli/story.rb +54 -0
  26. data/lib/cp8_cli/version.rb +1 -1
  27. metadata +10 -79
  28. data/lib/cp8_cli/github/base.rb +0 -14
  29. data/lib/cp8_cli/github/parsed_short_link.rb +0 -25
  30. data/lib/cp8_cli/story_query.rb +0 -23
  31. data/lib/cp8_cli/storyable.rb +0 -7
  32. data/lib/cp8_cli/table.rb +0 -38
  33. data/lib/cp8_cli/table/row.rb +0 -45
  34. data/lib/cp8_cli/trello/base.rb +0 -36
  35. data/lib/cp8_cli/trello/board.rb +0 -13
  36. data/lib/cp8_cli/trello/card.rb +0 -65
  37. data/lib/cp8_cli/trello/error.rb +0 -5
  38. data/lib/cp8_cli/trello/error_handler.rb +0 -15
  39. data/lib/cp8_cli/trello/json_parser.rb +0 -13
  40. data/lib/cp8_cli/trello/label.rb +0 -15
  41. data/lib/cp8_cli/trello/list.rb +0 -32
  42. data/lib/cp8_cli/trello/member.rb +0 -11
@@ -1,68 +1,47 @@
1
- require "cp8_cli/github/base"
1
+ require "cp8_cli/github/api"
2
2
  require "cp8_cli/github/parsed_url"
3
- require "cp8_cli/github/parsed_short_link"
4
- require "cp8_cli/storyable"
3
+ require "cp8_cli/story"
5
4
 
6
5
  module Cp8Cli
7
6
  module Github
8
- class Issue < Base
9
- include Storyable
7
+ class Issue < Story
8
+ include Api::Client
10
9
 
11
- def initialize(number:, repo:, attributes:)
10
+ def initialize(number:, repo:, **attributes)
12
11
  @number = number
13
12
  @repo = repo
14
13
  @attributes = attributes
15
14
  end
16
15
 
17
- def self.fields
18
- [:title]
19
- end
20
-
21
16
  def self.find_by_url(url)
22
17
  url = ParsedUrl.new(url)
23
- issue = client.issue(url.repo, url.number)
24
- new number: url.number, repo: url.repo, attributes: issue
25
- end
26
-
27
- def self.find_by_short_link(short_link)
28
- short_link = ParsedShortLink.new(short_link)
29
- issue = client.issue(short_link.repo, short_link.number)
30
- new number: short_link.number, repo: short_link.repo, attributes: issue
18
+ issue = client.issue(url.repo, url.number).to_h
19
+ new issue.merge(number: url.number, repo: url.repo)
31
20
  end
32
21
 
33
22
  def title
34
23
  attributes[:title]
35
24
  end
36
25
 
37
- def pr_title
38
- title
39
- end
40
-
41
- def url
42
- attributes[:html_url]
43
- end
44
-
45
26
  def summary
46
27
  "Closes #{short_link}"
47
28
  end
48
29
 
49
- def start
50
- assign CurrentUser.new
51
- end
52
-
53
- def short_link
54
- "#{repo}##{number}"
55
- end
56
-
57
30
  private
58
31
 
59
32
  attr_reader :number, :repo, :attributes
60
33
 
61
- def assign(user)
62
- # add_assignes not released as gem yet https://github.com/octokit/octokit.rb/pull/894
63
- client.post "#{Octokit::Repository.path repo}/issues/#{number}/assignees", assignees: [user.github_login]
34
+ def assign
35
+ client.add_assignees repo, number, [user.github_login]
64
36
  end
65
37
 
38
+ def user
39
+ CurrentUser.new
40
+ end
41
+
42
+ def short_link
43
+ "#{repo}##{number}"
44
+ end
66
45
  end
67
46
  end
68
47
  end
@@ -1,24 +1,31 @@
1
- require "cp8_cli/github/base"
1
+ require "cp8_cli/github/api"
2
2
  require "cp8_cli/repo"
3
3
 
4
4
  module Cp8Cli
5
5
  module Github
6
- class PullRequest < Base
6
+ class PullRequest
7
+ include Api::Client
8
+
7
9
  def self.create(attributes = {})
8
10
  new(attributes).save
9
11
  end
10
12
 
11
- def initialize(from:, to:, title: nil, body: nil)
12
- @title = title
13
- @body = body
13
+ def self.find_by(repo:, branch:)
14
+ client.pull_requests(repo, head: branch).map do |data|
15
+ new(data)
16
+ end.first
17
+ end
18
+
19
+ def initialize(from: nil, to: "master", title: nil, body: nil, expand: 1, html_url: nil, **attributes)
14
20
  @from = from
15
21
  @to = to
22
+ @title = title
23
+ @body = body
24
+ @expand = expand
25
+ @html_url = html_url
16
26
  end
17
27
 
18
- def open(expand: 1)
19
- query = base_query.merge(expand: expand)
20
- url = "#{base_url}?#{query.compact.to_query}"
21
-
28
+ def open
22
29
  Command.open_url(url)
23
30
  end
24
31
 
@@ -34,7 +41,15 @@ module Cp8Cli
34
41
 
35
42
  private
36
43
 
37
- attr_reader :from, :to, :title, :body
44
+ attr_reader :from, :to, :title, :body, :expand, :html_url
45
+
46
+ def url
47
+ html_url || new_pr_url
48
+ end
49
+
50
+ def new_pr_url
51
+ "#{base_url}?#{base_query}"
52
+ end
38
53
 
39
54
  def base_url
40
55
  repo.url + "/compare/#{escape to}...#{escape from}"
@@ -44,7 +59,8 @@ module Cp8Cli
44
59
  {
45
60
  title: title,
46
61
  body: body,
47
- }
62
+ expand: expand
63
+ }.compact.to_query
48
64
  end
49
65
 
50
66
  def escape(text)
@@ -1,5 +1,4 @@
1
1
  require "cp8_cli/config_store"
2
- require "cp8_cli/trello/base"
3
2
 
4
3
  module Cp8Cli
5
4
  class GlobalConfig
@@ -9,14 +8,6 @@ module Cp8Cli
9
8
  @store = store || ConfigStore.new(PATH)
10
9
  end
11
10
 
12
- def trello_key
13
- @_trello_key ||= store[:key] || configure_trello_key
14
- end
15
-
16
- def trello_token
17
- @_trello_token ||= store[:token] || configure_trello_token
18
- end
19
-
20
11
  def github_token
21
12
  @_github_token ||= store[:github_token] || env_github_token || configure_github_token
22
13
  end
@@ -25,17 +16,6 @@ module Cp8Cli
25
16
 
26
17
  attr_reader :store
27
18
 
28
- def configure_trello_key
29
- Command.ask "Press enter to setup Trello for this project (will open public key url)", validate: //
30
- Command.open_url "https://trello.com/app-key"
31
- store.save :key, Command.ask("Input Developer API key")
32
- end
33
-
34
- def configure_trello_token
35
- Command.open_url trello_authorize_url
36
- store.save :token, Command.ask("Input member token")
37
- end
38
-
39
19
  def env_github_token
40
20
  ENV["OCTOKIT_ACCESS_TOKEN"]
41
21
  end
@@ -43,9 +23,5 @@ module Cp8Cli
43
23
  def configure_github_token
44
24
  store.save :github_token, Command.ask("Input GitHub token")
45
25
  end
46
-
47
- def trello_authorize_url
48
- "https://trello.com/1/authorize?key=#{trello_key}&name=Trello-Flow&scope=read,write,account&expiration=never&response_type=token"
49
- end
50
26
  end
51
27
  end
@@ -9,8 +9,7 @@ require "cp8_cli/commands/suggest"
9
9
  module Cp8Cli
10
10
  class Main
11
11
  def initialize(global_config = GlobalConfig.new)
12
- Trello::Base.configure(key: global_config.trello_key, token: global_config.trello_token)
13
- Github::Base.configure(token: global_config.github_token)
12
+ Github::Api.configure(token: global_config.github_token)
14
13
  end
15
14
 
16
15
  def start(name)
@@ -5,7 +5,7 @@ module Cp8Cli
5
5
  end
6
6
 
7
7
  def run
8
- return unless story
8
+ return if story.summary.blank?
9
9
 
10
10
  summary_with_release_note
11
11
  end
@@ -2,7 +2,7 @@ module Cp8Cli
2
2
  class PullRequestTitle
3
3
  def initialize(title, prefixes: [])
4
4
  @title = title
5
- @prefixes = prefixes
5
+ @prefixes = Array(*prefixes)
6
6
  end
7
7
 
8
8
  def run
@@ -9,14 +9,6 @@ module Cp8Cli
9
9
  @path = path
10
10
  end
11
11
 
12
- def user
13
- path.split('/').first
14
- end
15
-
16
- def name
17
- path.split('/').last
18
- end
19
-
20
12
  def shorthand
21
13
  "#{user}/#{name}"
22
14
  end
@@ -28,5 +20,13 @@ module Cp8Cli
28
20
  private
29
21
 
30
22
  attr_reader :path
23
+
24
+ def user
25
+ path.split('/').first
26
+ end
27
+
28
+ def name
29
+ path.split('/').last
30
+ end
31
31
  end
32
32
  end
@@ -0,0 +1,54 @@
1
+ module Cp8Cli
2
+ class Story
3
+ def start
4
+ checkout_branch
5
+ create_empty_commit
6
+ push_branch
7
+ create_wip_pull_request
8
+ assign
9
+ Command.say "Created WIP PR, run `cp8 open` to view."
10
+ end
11
+
12
+ private
13
+
14
+ def checkout_branch
15
+ branch.checkout
16
+ end
17
+
18
+ def create_empty_commit
19
+ Command.run "git commit --allow-empty -m\"#{commit_message}\""
20
+ end
21
+
22
+ def commit_message
23
+ "Started: #{escaped_title}"
24
+ end
25
+
26
+ def escaped_title
27
+ title.gsub('"', '\"')
28
+ end
29
+
30
+ def push_branch
31
+ branch.push
32
+ end
33
+
34
+ def create_wip_pull_request
35
+ Github::PullRequest.create(
36
+ from: branch.name,
37
+ title: PullRequestTitle.new(title, prefixes: :wip).run,
38
+ body: PullRequestBody.new(self).run
39
+ )
40
+ end
41
+
42
+ def branch
43
+ @_branch ||= Branch.new(branch_name)
44
+ end
45
+
46
+ def branch_name
47
+ BranchName.new(user: user, story: self).to_s
48
+ end
49
+
50
+ def user
51
+ @_user ||= CurrentUser.new
52
+ end
53
+ end
54
+ end
@@ -1,5 +1,5 @@
1
1
  module Cp8Cli
2
- VERSION = "6.0.1"
2
+ VERSION = "8.0.0"
3
3
 
4
4
  class Version
5
5
  def self.latest?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cp8_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-20 00:00:00.000000000 Z
11
+ date: 2018-04-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: webmock
98
+ name: multi_json
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: faraday-conductivity
112
+ name: webmock
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -164,48 +164,6 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: hirb
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-colors
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: hirb-unicode
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
167
  - !ruby/object:Gem::Dependency
210
168
  name: launchy
211
169
  requirement: !ruby/object:Gem::Requirement
@@ -220,20 +178,6 @@ dependencies:
220
178
  - - ">="
221
179
  - !ruby/object:Gem::Version
222
180
  version: '0'
223
- - !ruby/object:Gem::Dependency
224
- name: multi_json
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
181
  - !ruby/object:Gem::Dependency
238
182
  name: octokit
239
183
  requirement: !ruby/object:Gem::Requirement
@@ -249,7 +193,7 @@ dependencies:
249
193
  - !ruby/object:Gem::Version
250
194
  version: '0'
251
195
  - !ruby/object:Gem::Dependency
252
- name: spyke
196
+ name: thor
253
197
  requirement: !ruby/object:Gem::Requirement
254
198
  requirements:
255
199
  - - ">="
@@ -263,7 +207,7 @@ dependencies:
263
207
  - !ruby/object:Gem::Version
264
208
  version: '0'
265
209
  - !ruby/object:Gem::Dependency
266
- name: thor
210
+ name: trollop
267
211
  requirement: !ruby/object:Gem::Requirement
268
212
  requirements:
269
213
  - - ">="
@@ -277,7 +221,7 @@ dependencies:
277
221
  - !ruby/object:Gem::Version
278
222
  version: '0'
279
223
  - !ruby/object:Gem::Dependency
280
- name: trollop
224
+ name: tty-prompt
281
225
  requirement: !ruby/object:Gem::Requirement
282
226
  requirements:
283
227
  - - ">="
@@ -328,9 +272,8 @@ files:
328
272
  - lib/cp8_cli/commands/suggest.rb
329
273
  - lib/cp8_cli/config_store.rb
330
274
  - lib/cp8_cli/current_user.rb
331
- - lib/cp8_cli/github/base.rb
275
+ - lib/cp8_cli/github/api.rb
332
276
  - lib/cp8_cli/github/issue.rb
333
- - lib/cp8_cli/github/parsed_short_link.rb
334
277
  - lib/cp8_cli/github/parsed_url.rb
335
278
  - lib/cp8_cli/github/pull_request.rb
336
279
  - lib/cp8_cli/global_config.rb
@@ -338,19 +281,7 @@ files:
338
281
  - lib/cp8_cli/pull_request_body.rb
339
282
  - lib/cp8_cli/pull_request_title.rb
340
283
  - lib/cp8_cli/repo.rb
341
- - lib/cp8_cli/story_query.rb
342
- - lib/cp8_cli/storyable.rb
343
- - lib/cp8_cli/table.rb
344
- - lib/cp8_cli/table/row.rb
345
- - lib/cp8_cli/trello/base.rb
346
- - lib/cp8_cli/trello/board.rb
347
- - lib/cp8_cli/trello/card.rb
348
- - lib/cp8_cli/trello/error.rb
349
- - lib/cp8_cli/trello/error_handler.rb
350
- - lib/cp8_cli/trello/json_parser.rb
351
- - lib/cp8_cli/trello/label.rb
352
- - lib/cp8_cli/trello/list.rb
353
- - lib/cp8_cli/trello/member.rb
284
+ - lib/cp8_cli/story.rb
354
285
  - lib/cp8_cli/version.rb
355
286
  homepage: https://github.com/balvig/cp8_cli
356
287
  licenses:
@@ -372,7 +303,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
372
303
  version: '0'
373
304
  requirements: []
374
305
  rubyforge_project:
375
- rubygems_version: 2.6.13
306
+ rubygems_version: 2.6.14.1
376
307
  signing_key:
377
308
  specification_version: 4
378
309
  summary: Cookpad Global CLI.