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
@@ -1,14 +0,0 @@
1
- require "active_support"
2
- require "octokit"
3
-
4
- module Cp8Cli
5
- module Github
6
- class Base
7
- cattr_accessor :client
8
-
9
- def self.configure(token:)
10
- self.client = Octokit::Client.new(access_token: token)
11
- end
12
- end
13
- end
14
- end
@@ -1,25 +0,0 @@
1
- module Cp8Cli
2
- module Github
3
- class ParsedShortLink
4
- def initialize(short_link)
5
- @short_link = short_link
6
- end
7
-
8
- def number
9
- parts.last
10
- end
11
-
12
- def repo
13
- parts.first
14
- end
15
-
16
- private
17
-
18
- attr_accessor :short_link
19
-
20
- def parts
21
- short_link.split("#")
22
- end
23
- end
24
- end
25
- end
@@ -1,23 +0,0 @@
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
@@ -1,7 +0,0 @@
1
- module Cp8Cli
2
- module Storyable
3
- def branch
4
- @_branch ||= Branch.from_story(self)
5
- end
6
- end
7
- end
@@ -1,38 +0,0 @@
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, type: 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
@@ -1,45 +0,0 @@
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
@@ -1,36 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,65 +0,0 @@
1
- require "cp8_cli/storyable"
2
-
3
- module Cp8Cli
4
- module Trello
5
- class Card < Base
6
- include Storyable
7
-
8
- belongs_to :board, foreign_key: "idBoard"
9
-
10
- def self.fields
11
- [:title]
12
- end
13
-
14
- def self.find_by_url(url)
15
- card = Card.new(url: url)
16
- find(card.short_link)
17
- end
18
-
19
- def title
20
- name
21
- end
22
-
23
- def pr_title
24
- "#{title} [Delivers ##{short_link}]"
25
- end
26
-
27
- def summary
28
- "Trello: #{short_url}"
29
- end
30
-
31
- def start
32
- move_to board.lists.started
33
- assign CurrentUser.new
34
- end
35
-
36
- def short_link
37
- url.scan(/\/c\/(.+)\//).flatten.first
38
- end
39
-
40
- # Used by CP-8 bot
41
- def attach(url:)
42
- self.class.request(:post, "cards/#{id}/attachments", url: url)
43
- end
44
-
45
- private
46
-
47
- def short_url
48
- attributes[:shortUrl]
49
- end
50
-
51
- def assign(user)
52
- return if member_ids.include?(user.trello_id)
53
- self.class.request(:post, "cards/#{id}/members", value: user.trello_id)
54
- end
55
-
56
- def move_to(list)
57
- self.class.with("cards/:id/idList").where(id: id, value: list.id).put
58
- end
59
-
60
- def member_ids
61
- attributes["idMembers"] || []
62
- end
63
- end
64
- end
65
- end
@@ -1,5 +0,0 @@
1
- module Cp8Cli
2
- module Trello
3
- class Error < StandardError; end
4
- end
5
- end
@@ -1,15 +0,0 @@
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
@@ -1,13 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,32 +0,0 @@
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
@@ -1,11 +0,0 @@
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