flight_plan_cli 0.2.1 → 0.2.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c4167472c77c9b96fe0e658ec800936df03616e
4
- data.tar.gz: cdf35761a2355426892613d068e6d8e1a0e79345
3
+ metadata.gz: 78181ba943356a2938c0b17c0ebcb72ee0aa5d04
4
+ data.tar.gz: fe51626d77304f08f7b736b706a8cfbc7efd0a87
5
5
  SHA512:
6
- metadata.gz: 6525651c2920c877e50ae4b092351a4bade1c8716eeccc6cfb6f2cd26d53e4b15633f19a81557c024e25fe10b6f8b2f0c191f451188976f466e558aa4ca5555b
7
- data.tar.gz: 94b7ff8f05e5331c0e350cb34fd6291607e822459f192de8e0de53533cf42639ab6502be8d2470aebb6956c89b65f67f72ed38c05481c7e012098aed0a2af242
6
+ metadata.gz: 8667298164e296c2dfc04126bce4b0fb5ef23a19ce031cf52e2c770d6915b81d6f5c4c472c1d52be1a376ed910aa487e1e7a53c62fe5e932bb9e1be93e067269
7
+ data.tar.gz: d497fcceda6ddd0dbb3efad73a174c986fe16ea8e44c2bfd82936ac994c1153e4fb7b0406ea3e40ec411464b74adba408d3f0a9ec53e11821f41dacecf2a3f56
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -1,5 +1,6 @@
1
1
  require 'thor'
2
2
  require 'colorize'
3
+ require 'rugged'
3
4
 
4
5
  module FlightPlanCli
5
6
  class ApiUnauthorized < StandardError; end
@@ -28,6 +29,14 @@ module FlightPlanCli
28
29
  puts "Network error. #{e.message}".red
29
30
  end
30
31
 
32
+ desc 'checkout ISSUE_NO', 'checkout a branch for ISSUE_NO'
33
+ def checkout(issue_no)
34
+ puts "Checking out branch for #{issue_no}"
35
+ local_branch_for(issue_no) || remote_branch_for(issuei_no)
36
+ end
37
+
38
+ map co: :checkout
39
+
31
40
  private
32
41
 
33
42
  attr_reader :board_id, :repo_id, :default_swimlane_ids
@@ -43,6 +52,44 @@ module FlightPlanCli
43
52
  @api_secret = ENV['FLIGHT_PLAN_API_SECRET']
44
53
  end
45
54
 
55
+ def local_branch_for(issue)
56
+ issue_branches = local_branches.grep(/##{issue}[^0-9]/)
57
+ return false unless issue_branches.count == 1
58
+
59
+ branch = issue_branches.first
60
+ puts "Checking out local branch '#{branch}'".green
61
+ git.checkout(branch)
62
+ true
63
+ end
64
+
65
+ def local_branches
66
+ @local_branches ||= git.branches.each(:local).map(&:name)
67
+ end
68
+
69
+ def remote_branch_for(issue)
70
+ git.fetch('origin')
71
+ return
72
+ git.branches.each(:remote) do |branch|
73
+ local_name = branch.name[branch.remote_name.size+1..-1]
74
+ next unless local_name.start_with? "feature/##{issue}-"
75
+ puts "Checking out and tracking remote branch '#{local_name}'".green
76
+ new_branch = git.branches.create(local_name, branch.name)
77
+ new_branch.upstream = branch
78
+ git.checkout(local_name)
79
+ return true
80
+ end
81
+ false
82
+ end
83
+
84
+ def git
85
+ @git ||= Rugged::Repository.new(Dir.pwd)
86
+ end
87
+
88
+ def fetch
89
+ puts 'fetching...'
90
+ git.remotes.each(&:fetch)
91
+ end
92
+
46
93
  def print_swimlane(swimlane)
47
94
  puts "#{swimlane['name']} (#{swimlane['tickets'].count})".green
48
95
  swimlane['tickets'].each do |ticket|
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.1
4
+ version: 0.2.2
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-12 00:00:00.000000000 Z
11
+ date: 2018-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler