flight_plan_cli 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a483a30bc314a4e2f8664d2549dcd6220c4143f
4
- data.tar.gz: ea127beb180f262c57314c936c186971a5f68421
3
+ metadata.gz: 1143966ef8166114dfc708a3937c2e38a20b4b62
4
+ data.tar.gz: edd59507ccd883c018980e8a03223405667aa611
5
5
  SHA512:
6
- metadata.gz: 6fc14dc2d8df9b844439f0d70e2dfd7de05c09cc446fc6c5b272b32937383da00580cfbddd57487842dc18079df5bdc73bf4f2e249d8d0f547eeaae93f6953f1
7
- data.tar.gz: 130b6b32dd15e2f8007186aacb9353bea866f8dbe3493523decaf0d419060b61e9b7a15392ed8111623e6cc9f63db7063f67b38686793f6f4b50e5272baf7bba
6
+ metadata.gz: 3c15ad4a8fb00306867f8754cc192928b59aea5e830ab70c3f190034d7ab9352e29ba3c2f255879d659ae12eedad8b2560483f8e61df3ad8494c86c66f4d9af0
7
+ data.tar.gz: 281f06bbe0d4d961c0f7c96b0b2f29de7c2778fbd256306fac0795bd3d80828522624c174b41b53f5fe15a96e08afaf132e32d9317c981a32e072f1390a85654
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -2,18 +2,21 @@ require 'httparty'
2
2
 
3
3
  module FlightPlanCli
4
4
  class Api
5
- def initialize(url:, key:, secret:)
5
+
6
+ def initialize(url:, key:, secret:, board_id: nil, repo_id: nil)
6
7
  @url = url
7
8
  @key = key
8
9
  @secret = secret
10
+ @board_id = board_id
11
+ @repo_id = repo_id
9
12
  end
10
13
 
11
- def board_tickets(board_id: nil, repo_id: nil, repo_url: nil, assignee_username: nil)
14
+ def board_tickets(assignee_username: nil, remote_number: nil)
12
15
  params = {
13
16
  board_id: board_id,
14
17
  repo_id: repo_id,
15
- repo_url: repo_url,
16
- assignee_username: assignee_username
18
+ assignee_username: assignee_username,
19
+ remote_number: remote_number
17
20
  }
18
21
 
19
22
  HTTParty.get("#{url}/board_tickets.json", query: params, headers: headers)
@@ -22,6 +25,7 @@ module FlightPlanCli
22
25
  private
23
26
 
24
27
  attr_reader :url, :key, :secret
28
+ attr_reader :board_id, :repo_id
25
29
 
26
30
  def headers
27
31
  @headers = {
@@ -1,15 +1,19 @@
1
1
  module FlightPlanCli
2
2
  module Commands
3
3
  class Checkout
4
- def process(issue_no)
5
- puts "Checking out branch for #{issue_no}"
6
- local_branch_for(issue_no) ||
7
- remote_branch_for(issue_no) ||
8
- new_branch_for(issue_no)
4
+ include FlightPlanCli::Config
5
+
6
+ def process(issue)
7
+ puts "Checking out branch for #{issue}"
8
+ local_branch_for(issue) ||
9
+ remote_branch_for(issue) ||
10
+ new_branch_for(issue)
9
11
  rescue Rugged::CheckoutError => e
10
12
  puts "Unable to checkout: #{e.message}".red
11
13
  end
12
14
 
15
+ private
16
+
13
17
  def local_branch_for(issue)
14
18
  issue_branches = local_branches.map(&:name).grep(/##{issue}[^0-9]/)
15
19
  return false unless issue_branches.count == 1
@@ -21,19 +25,45 @@ module FlightPlanCli
21
25
  end
22
26
 
23
27
  def remote_branch_for(issue)
24
- fetch
25
28
  issue_branches = remote_branches.map(&:name).grep(/##{issue}[^0-9]/)
26
29
  return false unless issue_branches.count == 1
27
30
 
28
31
  remote_branch_name = issue_branches.first
29
32
  branch = remote_branches.find { |rb| rb.name == remote_branch_name }
30
- local_name = branch.name[branch.remote_name.size + 1..-1]
31
33
 
32
- puts "Checking out and tracking remote branch '#{local_name}'".green
34
+ puts "Checking out and tracking remote branch '#{branch.name}'".green
35
+ checkout_locally(branch)
36
+ true
37
+ end
38
+
39
+ def checkout_locally(branch)
40
+ local_name = branch.name[branch.remote_name.size + 1..-1]
33
41
  new_branch = git.branches.create(local_name, branch.name)
34
42
  new_branch.upstream = branch
35
43
  git.checkout(local_name)
36
- true
44
+ end
45
+
46
+ def new_branch_for(issue)
47
+ read_config
48
+ branches = client.board_tickets(remote_number: issue)
49
+ # TODO: update flight_plan to only return one issue when remote_numer is provided
50
+ branches = branches.select { |b| b['ticket']['remote_number'] == issue }
51
+ return false unless branches.count == 1
52
+
53
+ branch_name = branch_name(branches.first)
54
+
55
+ puts "Creating new branch #{branch_name} from master".green
56
+
57
+ git.branches.create(branch_name, 'origin/master')
58
+ git.checkout(branch_name)
59
+ end
60
+
61
+ def branch_name(branch)
62
+ "feature/##{branch['ticket']['remote_number']}-" +
63
+ branch['ticket']['remote_title']
64
+ .gsub(/[^a-z0-9\s]/i, '')
65
+ .tr(' ', '-')
66
+ .downcase
37
67
  end
38
68
 
39
69
  def local_branches
@@ -41,11 +71,11 @@ module FlightPlanCli
41
71
  end
42
72
 
43
73
  def remote_branches
44
- @remote_branches ||= git.branches.each(:remote)
45
- end
46
-
47
- def git
48
- @git ||= Rugged::Repository.new(Dir.pwd)
74
+ @remote_branches ||=
75
+ begin
76
+ fetch
77
+ git.branches.each(:remote)
78
+ end
49
79
  end
50
80
 
51
81
  def fetch
@@ -1,6 +1,12 @@
1
1
  module FlightPlanCli
2
2
  module Commands
3
3
  class Ls
4
+ module Color
5
+ SWIMLANE = :cyan
6
+ ISSUE = :yellow
7
+ ISSUE_NO = :red
8
+ end
9
+
4
10
  include FlightPlanCli::Config
5
11
 
6
12
  def initialize
@@ -21,9 +27,10 @@ module FlightPlanCli
21
27
  puts "Network error. #{e.message}".red
22
28
  end
23
29
 
30
+ private
31
+
24
32
  def tickets_by_swimlane
25
- response = client.board_tickets(board_id: board_id, repo_id: repo_id)
26
- puts 'ok2'
33
+ response = client.board_tickets
27
34
  raise ApiUnauthorized if response.code == 401
28
35
  raise ApiNotFound if response.code == 404
29
36
 
@@ -40,10 +47,16 @@ module FlightPlanCli
40
47
  end
41
48
 
42
49
  def print_swimlane(swimlane)
43
- puts "#{swimlane['name']} (#{swimlane['tickets'].count})".green
50
+ puts "#{swimlane['name']} (#{swimlane['tickets'].count})"
51
+ .colorize(Color::SWIMLANE)
52
+
44
53
  swimlane['tickets'].each do |ticket|
45
- puts "├── #{ticket['remote_number'].rjust(4)} : #{ticket['remote_title']}".yellow
54
+ title = ticket['remote_title']
55
+ title = title.underline if git.head.name =~ /##{ticket['remote_number']}[^0-9]/
56
+ print " #{ticket['remote_number']} ".colorize(Color::ISSUE_NO)
57
+ puts title.colorize(Color::ISSUE)
46
58
  end
59
+ puts
47
60
  end
48
61
  end
49
62
  end
@@ -1,5 +1,7 @@
1
1
  module FlightPlanCli
2
2
  module Config
3
+ private
4
+
3
5
  YAML_FILE = '.flight_plan_cli.yml'.freeze
4
6
 
5
7
  attr_reader :board_id, :repo_id, :default_swimlane_ids
@@ -19,10 +21,16 @@ module FlightPlanCli
19
21
  @client ||= FlightPlanCli::Api.new(
20
22
  url: api_url,
21
23
  key: api_key,
22
- secret: api_secret
24
+ secret: api_secret,
25
+ board_id: board_id,
26
+ repo_id: repo_id
23
27
  )
24
28
  end
25
29
 
30
+ def git
31
+ @git ||= Rugged::Repository.new(Dir.pwd)
32
+ end
33
+
26
34
  def config
27
35
  @config ||=
28
36
  begin
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flight_plan_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Cleary
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-15 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler