cp8_cli 6.0.1 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f3ff52745a24efe4e1b23b61a30f2b88bd5d9691
4
- data.tar.gz: 1ac607e96ed473335468195e39495bc620257938
3
+ metadata.gz: 1f89f5cef49c8003d4e122a20839552d4f2f9356
4
+ data.tar.gz: cb65a62d4e2106f1c257fb975f2e153eeb23bb71
5
5
  SHA512:
6
- metadata.gz: ae8d41a0bcce0d76d92ecfe57cafc83289477d7364484c775fe5ffcf25ee1d90242d845923e40b0b7a909481226d74ae3c8024e433107fd474771f14b5e62fb7
7
- data.tar.gz: 613234213ce6fb3e8f6a5f2c1434ea1eb71af9ae2bd821a27e8c01d6e1f9e0b17495751697a2d96f52ee3a824d713200865dffe8ab9c6e48cb37bfb6109addd5
6
+ metadata.gz: ea264e71c5e44e09b69497ea494b8ae841361cfa97809238d2877d837efbcb9abf1f9a28da777d91e9f779fd53adc514364fbde7e12021137bb7e85e7af2b7b1
7
+ data.tar.gz: 21de39da770d3d3cd563fc606a1552b10328aec458e5475d14f4bc47cc4d618e67d8f568366835d3bfe33150a5df4aa43941317bde3c6ecc3c8ab33827b51d22
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  ## Installation
4
4
 
5
5
  ```bash
6
- gem uninstall trello_flow # if used
7
6
  gem install cp8_cli
8
7
  ```
9
8
 
@@ -25,19 +25,15 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "minitest-line"
26
26
  spec.add_development_dependency "minitest-reporters"
27
27
  spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "multi_json"
28
29
  spec.add_development_dependency "webmock"
29
- spec.add_development_dependency "faraday-conductivity"
30
30
 
31
31
  spec.add_dependency "activesupport"
32
32
  spec.add_dependency "colored"
33
33
  spec.add_dependency "highline"
34
- spec.add_dependency "hirb"
35
- spec.add_dependency "hirb-colors"
36
- spec.add_dependency "hirb-unicode"
37
34
  spec.add_dependency "launchy"
38
- spec.add_dependency "multi_json"
39
35
  spec.add_dependency "octokit"
40
- spec.add_dependency "spyke"
41
36
  spec.add_dependency "thor"
42
37
  spec.add_dependency "trollop"
38
+ spec.add_dependency "tty-prompt"
43
39
  end
data/exe/cp8 CHANGED
@@ -12,13 +12,12 @@ module Cp8Cli
12
12
  main.start(name)
13
13
  end
14
14
 
15
- desc "submit", "Pushes branch to GitHub and opens a PR"
16
- method_option :wip, desc: "Flag PR as WIP", type: :boolean
15
+ desc "submit", "Pushes branch to GitHub and opens PR"
17
16
  def submit
18
- main.submit(options.to_h.symbolize_keys)
17
+ main.submit
19
18
  end
20
19
 
21
- desc "open", "Open current associated issue in browser"
20
+ desc "open", "Open current associated PR in browser"
22
21
  def open
23
22
  main.open
24
23
  end
@@ -1,6 +1,5 @@
1
1
  require "cp8_cli/version"
2
2
  require "cp8_cli/command"
3
- require "cp8_cli/table"
4
3
  require "cp8_cli/branch"
5
4
  require "cp8_cli/main"
6
5
 
@@ -1,8 +1,7 @@
1
- require "cp8_cli/storyable"
1
+ require "cp8_cli/story"
2
2
 
3
3
  module Cp8Cli
4
- class AdhocStory
5
- include Storyable
4
+ class AdhocStory < Story
6
5
  attr_reader :title
7
6
 
8
7
  def initialize(title)
@@ -10,47 +9,17 @@ module Cp8Cli
10
9
  end
11
10
 
12
11
  def summary
13
- nil # noop for now
12
+ # noop
14
13
  end
15
14
 
16
- def start
17
- create_empty_commit
18
- push_branch
19
- create_wip_pull_request
20
- end
21
-
22
- def short_link
23
- nil # noop for now
24
- end
25
-
26
- def pr_title
27
- PullRequestTitle.new(title, prefixes: [:wip]).run
15
+ def url
16
+ "#{Repo.current.url}/tree/#{Branch.current}"
28
17
  end
29
18
 
30
19
  private
31
20
 
32
- def create_empty_commit
33
- Command.run "git commit --allow-empty -m\"#{commit_message}\""
34
- end
35
-
36
- def commit_message
37
- "Started: #{escaped_title}"
38
- end
39
-
40
- def escaped_title
41
- title.gsub('"', '\"')
42
- end
43
-
44
- def push_branch
45
- branch.push
46
- end
47
-
48
- def create_wip_pull_request
49
- Github::PullRequest.create(
50
- title: pr_title,
51
- from: branch.name,
52
- to: branch.target
53
- )
21
+ def assign
22
+ # noop
54
23
  end
55
24
  end
56
25
  end
@@ -3,7 +3,6 @@ require "cp8_cli/ci"
3
3
  require "cp8_cli/github/pull_request"
4
4
  require "cp8_cli/branch_name"
5
5
  require "cp8_cli/current_user"
6
- require "cp8_cli/story_query"
7
6
  require "cp8_cli/pull_request_title"
8
7
  require "cp8_cli/pull_request_body"
9
8
 
@@ -24,19 +23,6 @@ module Cp8Cli
24
23
  new("suggestion-#{SecureRandom.hex(8)}")
25
24
  end
26
25
 
27
- def self.from_story(story)
28
- new BranchName.new(
29
- user: CurrentUser.new,
30
- target: current,
31
- title: story.title,
32
- short_link: story.short_link
33
- ).to_s
34
- end
35
-
36
- def story
37
- @_story ||= StoryQuery.new(short_link).find if short_link
38
- end
39
-
40
26
  def checkout
41
27
  Command.run "git checkout #{name} >/dev/null 2>&1 || git checkout -b #{name}"
42
28
  end
@@ -45,20 +31,12 @@ module Cp8Cli
45
31
  Command.run "git push origin #{name} -u"
46
32
  end
47
33
 
48
- def open_ci
49
- Ci.new(branch_name: name, repo: Repo.current).open
34
+ def open_pr
35
+ pull_request.open
50
36
  end
51
37
 
52
- def open_story_in_browser
53
- if story
54
- Command.open_url story.url
55
- else
56
- Command.error "Not currently on story branch"
57
- end
58
- end
59
-
60
- def target
61
- name_parts[2] || "master"
38
+ def open_ci
39
+ Ci.new(branch_name: name, repo: repo).open
62
40
  end
63
41
 
64
42
  def reset
@@ -75,22 +53,24 @@ module Cp8Cli
75
53
 
76
54
  private
77
55
 
78
- def short_link
79
- return unless linked_branch?
56
+ def repo
57
+ Repo.current
58
+ end
80
59
 
81
- name_parts.last
60
+ def dirty?
61
+ Command.read("git status --porcelain")
82
62
  end
83
63
 
84
- def linked_branch?
85
- name_parts.size == 4
64
+ def pull_request
65
+ existing_pull_request || new_pull_request
86
66
  end
87
67
 
88
- def name_parts
89
- @_name_parts ||= name.split(".")
68
+ def existing_pull_request
69
+ Github::PullRequest.find_by(branch: name, repo: repo.shorthand)
90
70
  end
91
71
 
92
- def dirty?
93
- Command.read("git status --porcelain")
72
+ def new_pull_request
73
+ Github::PullRequest.new(from: name)
94
74
  end
95
75
  end
96
76
  end
@@ -1,27 +1,30 @@
1
1
  module Cp8Cli
2
2
  class BranchName
3
- def initialize(user:, target:, title:, short_link: nil)
3
+ SEPARATOR = "/"
4
+
5
+ def initialize(user:, story:)
4
6
  @user = user
5
- @target = target
6
- @title = title
7
- @short_link = short_link
7
+ @story = story
8
8
  end
9
9
 
10
10
  def to_s
11
- parts.join(".")
11
+ "#{prefix}#{user_input}"
12
12
  end
13
13
 
14
14
  private
15
15
 
16
- attr_reader :user, :target, :title, :short_link
16
+ attr_reader :user, :story
17
+
18
+ def user_input
19
+ Command.ask("Branch name: #{prefix}", default: default)
20
+ end
21
+
22
+ def prefix
23
+ user.initials.downcase + SEPARATOR
24
+ end
17
25
 
18
- def parts
19
- parts = []
20
- parts << user.initials.downcase
21
- parts << title.parameterize[0..50]
22
- parts << target
23
- parts << short_link
24
- parts.compact
26
+ def default
27
+ story.title.parameterize[0..50]
25
28
  end
26
29
  end
27
30
  end
@@ -14,7 +14,7 @@ module Cp8Cli
14
14
  attr_reader :branch_name, :repo
15
15
 
16
16
  def url
17
- "https://circleci.com/gh/#{repo.user}/#{repo.name}/tree/#{escape branch_name}"
17
+ "https://circleci.com/gh/#{repo.shorthand}/tree/#{escape branch_name}"
18
18
  end
19
19
 
20
20
  def escape(text)
@@ -1,22 +1,17 @@
1
1
  require "colored"
2
2
  require "active_support/core_ext/module/delegation"
3
3
  require "highline"
4
- require "hirb-colors"
5
- require "hirb"
4
+ require "tty-prompt"
6
5
 
7
6
  module Cp8Cli
8
7
  class Command
9
8
  class << self
10
- delegate :table, :open_url, :say, :success, :ask, :title, :error, :run, :read, to: :client
9
+ delegate :open_url, :say, :success, :ask, :title, :error, :run, :read, to: :client
11
10
  attr_accessor :client
12
11
  end
13
12
 
14
13
  self.client = new
15
14
 
16
- def table(items)
17
- puts Hirb::Helpers::AutoTable.render(items, unicode: true)
18
- end
19
-
20
15
  def open_url(url)
21
16
  return title(url) if ENV['BROWSER'] == 'echo'
22
17
  `open \"#{url}\"`
@@ -30,8 +25,8 @@ module Cp8Cli
30
25
  highline.say(message.green.bold)
31
26
  end
32
27
 
33
- def ask(message, type: nil, validate: /.+/)
34
- highline.ask(message, type) { |q| q.validate = validate }
28
+ def ask(message, required: true, default: nil)
29
+ tty.ask(message, required: required, default: default)
35
30
  end
36
31
 
37
32
  def title(message)
@@ -57,5 +52,9 @@ module Cp8Cli
57
52
  def highline
58
53
  @_highline ||= HighLine.new
59
54
  end
55
+
56
+ def tty
57
+ @_tty ||= TTY::Prompt.new
58
+ end
60
59
  end
61
60
  end
@@ -2,7 +2,7 @@ module Cp8Cli
2
2
  module Commands
3
3
  class Open
4
4
  def run
5
- Branch.current.open_story_in_browser
5
+ Branch.current.open_pr
6
6
  end
7
7
  end
8
8
  end
@@ -10,10 +10,11 @@ module Cp8Cli
10
10
 
11
11
  def run
12
12
  check_version
13
- story.branch.checkout
14
- story.start
15
- rescue Trello::Error => error
16
- Command.error(error.message)
13
+ if story
14
+ story.start
15
+ else
16
+ Command.error "No name/url provided"
17
+ end
17
18
  end
18
19
 
19
20
  private
@@ -33,12 +34,8 @@ module Cp8Cli
33
34
  def find_or_create_story
34
35
  if name.to_s.start_with?("https://github.com")
35
36
  Github::Issue.find_by_url(name)
36
- elsif name.to_s.start_with?("http")
37
- Trello::Card.find_by_url(name)
38
37
  elsif name.present?
39
38
  AdhocStory.new(name)
40
- else
41
- Command.error "No name/url provided"
42
39
  end
43
40
  end
44
41
  end
@@ -7,7 +7,7 @@ module Cp8Cli
7
7
 
8
8
  def run
9
9
  branch.push
10
- pull_request.open
10
+ branch.open_pr
11
11
  end
12
12
 
13
13
  private
@@ -17,15 +17,6 @@ module Cp8Cli
17
17
  def branch
18
18
  @_branch ||= Branch.current
19
19
  end
20
-
21
- def pull_request
22
- Github::PullRequest.new(
23
- from: branch,
24
- to: branch.target,
25
- title: PullRequestTitle.new(branch.story&.pr_title, prefixes: options.keys).run,
26
- body: PullRequestBody.new(branch.story).run
27
- )
28
- end
29
20
  end
30
21
  end
31
22
  end
@@ -7,7 +7,7 @@ module Cp8Cli
7
7
 
8
8
  suggestion_branch.checkout
9
9
  suggestion_branch.push
10
- pull_request.open(expand: nil)
10
+ pull_request.open
11
11
 
12
12
  original_branch.checkout
13
13
  original_branch.reset
@@ -31,6 +31,7 @@ module Cp8Cli
31
31
  Github::PullRequest.new(
32
32
  from: suggestion_branch,
33
33
  to: original_branch,
34
+ expand: nil
34
35
  )
35
36
  end
36
37
 
@@ -1,3 +1,5 @@
1
+ require "yaml"
2
+
1
3
  module Cp8Cli
2
4
  class ConfigStore
3
5
  def initialize(path)
@@ -1,17 +1,13 @@
1
+ require "active_support/core_ext/string"
2
+
1
3
  module Cp8Cli
2
4
  class CurrentUser
3
- def current
4
- @_current ||= new
5
- end
5
+ include Github::Api::Client
6
6
 
7
7
  def initials
8
8
  git_user_name.parameterize(separator: " ").split.map(&:first).join
9
9
  end
10
10
 
11
- def trello_id
12
- trello_user.id
13
- end
14
-
15
11
  def github_login
16
12
  github_user.login
17
13
  end
@@ -23,11 +19,7 @@ module Cp8Cli
23
19
  end
24
20
 
25
21
  def github_user
26
- @_github_user ||= Github::Base.client.user
27
- end
28
-
29
- def trello_user
30
- @_trello_user ||= Trello::Member.current
22
+ @_github_user ||= client.user
31
23
  end
32
24
  end
33
25
  end
@@ -0,0 +1,29 @@
1
+ require "active_support"
2
+ require "active_support/concern"
3
+ require "octokit"
4
+
5
+ module Cp8Cli
6
+ module Github
7
+ class Api
8
+ cattr_accessor :client
9
+
10
+ def self.configure(token:)
11
+ self.client = Octokit::Client.new(access_token: token)
12
+ end
13
+
14
+ module Client
15
+ extend ActiveSupport::Concern
16
+
17
+ def client
18
+ self.class.client
19
+ end
20
+
21
+ class_methods do
22
+ def client
23
+ Api.client
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end