jira-cli 0.3.6 → 0.4.0

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: 69ec92a6c464ef57118383cdfec850349c3c6e7b
4
- data.tar.gz: 072db85dd22418e94121e28294448643e8b06da6
3
+ metadata.gz: 25748c17ff058c8bf351f77db807ef8a5702ec26
4
+ data.tar.gz: ed745d5b66227e6e696dabe0c4747fd6279edecd
5
5
  SHA512:
6
- metadata.gz: 0cd9b78698d419d394fb3e3945f3293e10155a1aa0c5f572f49af8dbfda892b2302d9fcba57c7215a797940051dd29c35728cc2f9d543d3e2d76a948b3096abf
7
- data.tar.gz: 2c100f048e3991ee5b5be9252a42c14e0011b655a639ca3bb8496420cf2652bf3d10efe264e3ebd5940881b3feec5f02d6ceb30b4a50ab38d5390fe3fa04b7cd
6
+ metadata.gz: 3008287942dcfe89f3c6cd73892a55fe2b767226e620b46e611af0291d368c63269ea20a43310cb95a308124d973a70318904df9f2b369edd4fc6e9603be669d
7
+ data.tar.gz: c7f58f7054e546df6374a5e7848f98d628fda7c38d4ff844f9dd7a6a5a0e2788aa7a82b0a51384687efb7e735b6fff5ec5792b12ec1a640538d419e854016800
data/README.md CHANGED
@@ -1,34 +1,31 @@
1
1
  # JIRA CLI [![Gem Version](https://badge.fury.io/rb/jira-cli.png)](http://badge.fury.io/rb/jira-cli)
2
2
 
3
- Ruby gem CLI tool used to manage JIRA workflows leveraging git
3
+ Control JIRA from your terminal
4
4
 
5
5
  * * *
6
6
 
7
- [![Circle CI](https://circleci.com/gh/drn/jira-cli.svg?style=svg)](https://circleci.com/gh/drn/jira-cli)
8
- [![Dependency Status](https://gemnasium.com/darrenli/jira-cli.png)](https://gemnasium.com/darrenli/jira-cli)
9
- [![Code Climate](https://codeclimate.com/github/darrenli/jira-cli.png)](https://codeclimate.com/github/darrenli/jira-cli)
7
+ [![Circle CI](https://circleci.com/gh/ruby-jira/jira-cli.svg?style=svg)](https://circleci.com/gh/ruby-jira/jira-cli)
8
+ [![Code Climate](https://codeclimate.com/github/ruby-jira/jira-cli.png)](https://codeclimate.com/github/ruby-jira/jira-cli)
10
9
 
11
10
  ### Available Commands
12
11
 
13
- jira all # Describes all local branches that match JIRA ticketing syntax
14
- jira assign # Assign a ticket to a user
15
- jira attachments # View ticket attachments
16
- jira checkout <ticket> # Checks out a ticket from JIRA in the git branch
17
- jira comment <command> # Commands for comment operations in JIRA
18
- jira delete # Deletes a ticket in JIRA and the git branch
19
- jira describe # Describes the input ticket
20
- jira help [COMMAND] # Describe available commands or one specific command
21
- jira install # Guides the user through JIRA CLI installation
22
- jira link # Creates a link between two tickets in JIRA
23
- jira log <command> # Commands for logging operations in JIRA
24
- jira new # Creates a new ticket in JIRA and checks out the git branch
25
- jira rename # Updates the summary of the input ticket
26
- jira sprint # Lists sprint info
27
- jira tickets [jql] # List the tickets of the input username (or jql)
28
- jira transition # Transitions the input ticket to the next state
29
- jira version # Displays the version
30
- jira vote <command> # Commands for voting operations in JIRA
31
- jira watch <command> # Commands for watching tickets in JIRA
12
+ jira assign <ticket> # Assign a ticket to a user
13
+ jira attachments <ticket> # View ticket attachments
14
+ jira comment <command> # Commands for comment operations in JIRA
15
+ jira delete <ticket> # Deletes a ticket
16
+ jira describe <ticket> # Describes the input ticket
17
+ jira help [COMMAND] # Describe available commands or one specific command
18
+ jira install # Guides the user through JIRA CLI installation
19
+ jira link <ticket> # Creates a link between two tickets in JIRA
20
+ jira log <command> # Commands for logging operations in JIRA
21
+ jira new # Creates a new ticket
22
+ jira rename <ticket> # Updates the summary of the input ticket
23
+ jira sprint # Lists sprint info
24
+ jira tickets [jql] # List the tickets of the input jql
25
+ jira transition <ticket> # Transitions the input ticket to the next state
26
+ jira version # Displays the version
27
+ jira vote <command> # Commands for voting operations in JIRA
28
+ jira watch <command> # Commands for watching tickets in JIRA
32
29
 
33
30
  ### Gem Installation
34
31
 
@@ -38,27 +35,10 @@ Rubygems:
38
35
 
39
36
  Manually:
40
37
 
41
- git clone git@github.com:darrenli/jira-cli.git
38
+ git clone git@github.com:ruby-jira/jira-cli.git
42
39
  cd jira-cli
43
40
  ./scripts/install
44
41
 
45
- ### Project Installation
46
-
47
- In order to use this tool, you'll need to run the installation script in the
48
- git repository that you're managing via JIRA.
49
-
50
- cd path/to/jira/repo
51
- jira install
52
-
53
- Note: Authentication files are expected to drastically change. Currently, they
54
- are completely unencrypted. Use are your own risk... (see disclaimer above)
55
-
56
- ### Disclaimer
57
-
58
- This tool is in very early alpha and its architecture and commands
59
- are expected to change drastically. Please only use this tool for testing
60
- purposes.
61
-
62
42
  ### License
63
43
 
64
44
  (The MIT License)
data/bin/jira CHANGED
@@ -17,8 +17,6 @@ rescue Faraday::Error, UnauthorizedException
17
17
  end
18
18
  end
19
19
  puts "JIRA failed connect, you may need to rerun 'jira install'"
20
- rescue GitException
21
- puts "JIRA commands can only be run within a git repository."
22
20
  rescue InstallationException
23
21
  puts "Please run #{Jira::Format.summary('jira install')} before "\
24
22
  "running this command."
@@ -1,9 +1,9 @@
1
1
  module Jira
2
2
  class CLI < Thor
3
3
 
4
- desc "assign", "Assign a ticket to a user"
4
+ desc "assign <ticket>", "Assign a ticket to a user"
5
5
  method_option :assignee, aliases: "-a", type: :string, default: nil, lazy_default: "auto", banner: "ASSIGNEE"
6
- def assign(ticket=Jira::Core.ticket)
6
+ def assign(ticket)
7
7
  Command::Assign.new(ticket, options).run
8
8
  end
9
9
 
@@ -1,8 +1,8 @@
1
1
  module Jira
2
2
  class CLI < Thor
3
3
 
4
- desc "attachments", "View ticket attachments"
5
- def attachments(ticket=Jira::Core.ticket)
4
+ desc "attachments <ticket>", "View ticket attachments"
5
+ def attachments(ticket)
6
6
  Command::Attachments.new(ticket).run
7
7
  end
8
8
 
@@ -3,7 +3,7 @@ module Jira
3
3
 
4
4
  desc 'add', 'Add a comment to the input ticket'
5
5
  method_option :text, aliases: "-t", type: :string, default: nil, lazy_default: "", banner: "TEXT"
6
- def add(ticket=Jira::Core.ticket)
6
+ def add(ticket)
7
7
  Command::Comment::Add.new(ticket, options).run
8
8
  end
9
9
 
@@ -2,7 +2,7 @@ module Jira
2
2
  class Comment < Thor
3
3
 
4
4
  desc 'delete', 'Delete a comment to the input ticket'
5
- def delete(ticket=Jira::Core.ticket)
5
+ def delete(ticket)
6
6
  Command::Comment::Delete.new(ticket).run
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ module Jira
2
2
  class Comment < Thor
3
3
 
4
4
  desc 'list', 'Lists the comments of the input ticket'
5
- def list(ticket=Jira::Core.ticket)
5
+ def list(ticket)
6
6
  Command::Comment::List.new(ticket).run
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ module Jira
2
2
  class Comment < Thor
3
3
 
4
4
  desc 'update', 'Update a comment to the input ticket'
5
- def update(ticket=Jira::Core.ticket)
5
+ def update(ticket)
6
6
  Command::Comment::Update.new(ticket).run
7
7
  end
8
8
 
@@ -1,9 +1,9 @@
1
1
  module Jira
2
2
  class CLI < Thor
3
3
 
4
- desc "delete", "Deletes a ticket in JIRA and the git branch"
4
+ desc "delete <ticket>", "Deletes a ticket"
5
5
  method_option :force, type: :boolean, default: false
6
- def delete(ticket=Jira::Core.ticket)
6
+ def delete(ticket)
7
7
  Command::Delete.new(ticket, options[:force]).run
8
8
  end
9
9
 
@@ -26,50 +26,12 @@ module Jira
26
26
  return if subtasks_failure?
27
27
 
28
28
  api.delete "issue/#{ticket}?deleteSubtasks=#{force}",
29
- success: on_success,
30
- failure: on_failure
29
+ success: ->{ puts "Ticket #{ticket} has been deleted." },
30
+ failure: ->{ puts "No change made to ticket #{ticket}." }
31
31
  end
32
32
 
33
33
  private
34
34
 
35
- def on_success
36
- -> do
37
- on_failure and return unless create_branch?
38
- on_failure and return unless delete_branch?
39
- end
40
- end
41
-
42
- def on_failure
43
- -> { puts "No change made to ticket #{ticket}." }
44
- end
45
-
46
- def branches
47
- branches = `git branch --list 2> /dev/null`.split(' ')
48
- branches.delete("*")
49
- branches.delete(ticket.to_s)
50
- branches
51
- end
52
-
53
- def create_branch?
54
- response = io.yes?("Create branch?")
55
-
56
- if branches.count == 1 or response
57
- io.say("Creating a new branch.")
58
- new_branch = io.ask("Branch?").strip
59
- new_branch.delete!(" ")
60
- on_failure and return false if new_branch.empty?
61
- `git branch #{new_branch} 2> /dev/null`
62
- end
63
- true
64
- end
65
-
66
- def delete_branch?
67
- response = self.io.select("Select a branch:", branches)
68
- `git checkout #{response} 2> /dev/null`
69
- `git branch -D #{ticket} 2> /dev/null`
70
- true
71
- end
72
-
73
35
  def subtasks_failure?
74
36
  return false unless subtask?
75
37
  if !metadata['fields']['subtasks'].empty? && !force
@@ -1,8 +1,8 @@
1
1
  module Jira
2
2
  class CLI < Thor
3
3
 
4
- desc "describe", "Describes the input ticket"
5
- def describe(ticket=Jira::Core.ticket)
4
+ desc "describe <ticket>", "Describes the input ticket"
5
+ def describe(ticket)
6
6
  Command::Describe.new(ticket).run
7
7
  end
8
8
 
@@ -1,8 +1,8 @@
1
1
  module Jira
2
2
  class CLI < Thor
3
3
 
4
- desc "link", "Creates a link between two tickets in JIRA"
5
- def link(ticket=Jira::Core.ticket)
4
+ desc "link <ticket>", "Creates a link between two tickets in JIRA"
5
+ def link(ticket)
6
6
  Command::Link.new(ticket).run
7
7
  end
8
8
 
@@ -1,7 +1,7 @@
1
1
  module Jira
2
2
  class CLI < Thor
3
3
 
4
- desc "new", "Creates a new ticket in JIRA and checks out the git branch"
4
+ desc 'new', 'Creates a new ticket'
5
5
  method_option :project, aliases: "-p", type: :string, default: nil, banner: "PROJECT"
6
6
  method_option :components, aliases: "-c", type: :array, default: nil, lazy_default: [], banner: "COMPONENTS"
7
7
  method_option :issuetype, aliases: "-i", type: :string, default: nil, banner: "ISSUETYPE"
@@ -50,9 +50,9 @@ module Jira
50
50
  issuetype: { id: issue_type['id'] },
51
51
  summary: summary,
52
52
  description: description,
53
- parent: @parent.nil? ? {} : { key: @parent },
54
- components: @components.nil? ? [] : @components
55
- }
53
+ parent: @parent.nil? ? nil : { key: @parent },
54
+ components: @components.nil? ? nil : @components
55
+ }.delete_if{|_,v| v.nil? || v.eql?([])}
56
56
  }
57
57
  end
58
58
 
@@ -61,7 +61,6 @@ module Jira
61
61
  self.ticket = json['key']
62
62
  io.say("Ticket #{ticket} created.")
63
63
  assign? if options.empty? || !options['assignee'].nil?
64
- create_branch? && checkout_branch? if options.empty?
65
64
  end
66
65
  end
67
66
 
@@ -69,18 +68,6 @@ module Jira
69
68
  Command::Assign.new(ticket, options).run if !options['assignee'].nil? || io.yes?('Assign?')
70
69
  end
71
70
 
72
- def create_branch?
73
- return false if io.no?("Create branch?")
74
- `git branch #{ticket} 2> /dev/null`
75
- true
76
- end
77
-
78
- def checkout_branch?
79
- return false if io.no?("Check-out branch?")
80
- `git checkout #{ticket} 2> /dev/null`
81
- true
82
- end
83
-
84
71
  def on_failure
85
72
  ->{ puts "No ticket created." }
86
73
  end
@@ -139,7 +126,7 @@ module Jira
139
126
  end
140
127
 
141
128
  def parent
142
- @parent ||= options['parent'] || io.ask('Subtask parent:', default: Jira::Core.ticket)
129
+ @parent ||= options['parent'] || io.ask('Subtask parent:')
143
130
  end
144
131
 
145
132
  def issue_type
@@ -164,8 +151,9 @@ module Jira
164
151
 
165
152
  def description
166
153
  @description ||= (
167
- description = options['description'] || (io.ask("Description:", default: '') if options['summary'].nil?)
168
- description ||= ""
154
+ options['description'] ||
155
+ (io.ask("Description:", default: '') if options['summary'].nil?) ||
156
+ ""
169
157
  )
170
158
  end
171
159
 
@@ -1,9 +1,9 @@
1
1
  module Jira
2
2
  class CLI < Thor
3
3
 
4
- desc "rename", "Updates the summary of the input ticket"
4
+ desc "rename <ticket>", "Updates the summary of the input ticket"
5
5
  method_option :summary, aliases: "-s", type: :string, default: nil, lazy_default: "", banner: "SUMMARY"
6
- def rename(ticket=Jira::Core.ticket)
6
+ def rename(ticket)
7
7
  Command::Rename.new(ticket, options).run
8
8
  end
9
9
 
@@ -1,10 +1,10 @@
1
1
  module Jira
2
2
  class CLI < Thor
3
3
 
4
- desc "transition", "Transitions the input ticket to the next state"
4
+ desc "transition <ticket>", "Transitions the input ticket to the next state"
5
5
  method_option :transition, aliases: "-t", type: :string, default: nil, lazy_default: "", banner: "TRANSITION"
6
6
  method_option :resolution, aliases: "-r", type: :string, default: nil, lazy_default: "", banner: "RESOLUTION"
7
- def transition(ticket=Jira::Core.ticket)
7
+ def transition(ticket)
8
8
  Command::Transition.new(ticket, options).run
9
9
  end
10
10
 
@@ -2,7 +2,7 @@ module Jira
2
2
  class Vote < Thor
3
3
 
4
4
  desc 'add', 'Vote for the input ticket'
5
- def add(ticket=Jira::Core.ticket)
5
+ def add(ticket)
6
6
  Command::Vote::Add.new(ticket).run
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ module Jira
2
2
  class Vote < Thor
3
3
 
4
4
  desc 'delete', 'Delete vote for the input ticket'
5
- def delete(ticket=Jira::Core.ticket)
5
+ def delete(ticket)
6
6
  Command::Vote::Delete.new(ticket).run
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ module Jira
2
2
  class Vote < Thor
3
3
 
4
4
  desc 'list', "List the votes on the input ticket"
5
- def list(ticket=Jira::Core.ticket)
5
+ def list(ticket)
6
6
  Command::Vote::List.new(ticket).run
7
7
  end
8
8
 
@@ -42,7 +42,7 @@ module Jira
42
42
  end
43
43
 
44
44
  def no_voters?
45
- if voters.count == 0
45
+ if voters.count.zero?
46
46
  puts "There are no votes on ticket #{ticket}."
47
47
  return true
48
48
  end
@@ -2,7 +2,7 @@ module Jira
2
2
  class Watch < Thor
3
3
 
4
4
  desc 'add', 'Watch the input ticket'
5
- def add(ticket=Jira::Core.ticket)
5
+ def add(ticket)
6
6
  Command::Watch::Add.new(ticket).run
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ module Jira
2
2
  class Watch < Thor
3
3
 
4
4
  desc 'delete', 'Stop watching the input ticket'
5
- def delete(ticket=Jira::Core.ticket)
5
+ def delete(ticket)
6
6
  Command::Watch::Delete.new(ticket).run
7
7
  end
8
8
 
@@ -2,7 +2,7 @@ module Jira
2
2
  class Watch < Thor
3
3
 
4
4
  desc 'list', 'Lists the watchers of the input ticket'
5
- def list(ticket=Jira::Core.ticket)
5
+ def list(ticket)
6
6
  Command::Watch::List.new(ticket).run
7
7
  end
8
8
 
@@ -34,7 +34,7 @@ module Jira
34
34
  attr_accessor :watcher
35
35
 
36
36
  def no_watchers?
37
- if watchers.count == 0
37
+ if watchers.count.zero?
38
38
  puts "Ticket #{ticket} has no watchers."
39
39
  return true
40
40
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jira
4
4
 
5
- VERSION = '0.3.6'.freeze
5
+ VERSION = '0.4.0'.freeze
6
6
 
7
7
  end
@@ -38,13 +38,6 @@ module Jira
38
38
  { name: config[:cookie]['name'], value: config[:cookie]['value'] }
39
39
  end
40
40
 
41
- #
42
- # @return [String] default ticket is the current branch
43
- #
44
- def ticket
45
- `git rev-parse --abbrev-ref HEAD 2>/dev/null`.strip
46
- end
47
-
48
41
  #
49
42
  # Determines whether or not the input ticket matches the expected JIRA
50
43
  # ticketing syntax. Outputs a warning that the input ticket isn't a valid
@@ -69,14 +62,14 @@ module Jira
69
62
  # @return [String] path to .jira-cli file
70
63
  #
71
64
  def cli_path
72
- @cli_path ||= root_path + "/.jira-cli"
65
+ @cli_path ||= "#{Dir.home}/.jira-cli"
73
66
  end
74
67
 
75
68
  #
76
69
  # @return [String] path to .jira-rescue-cookie file
77
70
  #
78
71
  def rescue_cookie_path
79
- @rescue_cookie_path ||= root_path + "/.jira-rescue-cookie"
72
+ @rescue_cookie_path ||= "#{Dir.home}/.jira-rescue-cookie"
80
73
  end
81
74
 
82
75
  def config
@@ -86,16 +79,6 @@ module Jira
86
79
  )
87
80
  end
88
81
 
89
- private
90
-
91
- def root_path
92
- @root_path ||= (
93
- root_path = `git rev-parse --show-toplevel 2>/dev/null`.strip
94
- raise GitException if root_path.empty?
95
- root_path
96
- )
97
- end
98
-
99
82
  end
100
83
  end
101
84
  end
@@ -1,3 +1,2 @@
1
1
  class InstallationException < StandardError; end
2
- class GitException < StandardError; end
3
2
  class UnauthorizedException < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Cheng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-05 00:00:00.000000000 Z
11
+ date: 2017-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -124,7 +124,7 @@ dependencies:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: 2.0.2
127
- description: Ruby CLI managing git-based JIRA workflows
127
+ description: Control JIRA from your terminal
128
128
  email: darren@thanx.com
129
129
  executables:
130
130
  - jira
@@ -137,10 +137,8 @@ files:
137
137
  - lib/jira/api.rb
138
138
  - lib/jira/auth_api.rb
139
139
  - lib/jira/command.rb
140
- - lib/jira/commands/all.rb
141
140
  - lib/jira/commands/assign.rb
142
141
  - lib/jira/commands/attachments.rb
143
- - lib/jira/commands/checkout.rb
144
142
  - lib/jira/commands/comment.rb
145
143
  - lib/jira/commands/comment/add.rb
146
144
  - lib/jira/commands/comment/delete.rb
@@ -174,7 +172,7 @@ files:
174
172
  - lib/jira/exceptions.rb
175
173
  - lib/jira/format.rb
176
174
  - lib/jira/sprint_api.rb
177
- homepage: https://github.com/drn/jira-cli
175
+ homepage: https://github.com/ruby-jira/jira-cli
178
176
  licenses:
179
177
  - MIT
180
178
  metadata: {}
@@ -194,9 +192,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
192
  version: '0'
195
193
  requirements: []
196
194
  rubyforge_project:
197
- rubygems_version: 2.5.1
195
+ rubygems_version: 2.6.11
198
196
  signing_key:
199
197
  specification_version: 4
200
198
  summary: JIRA CLI
201
199
  test_files: []
202
- has_rdoc:
@@ -1,72 +0,0 @@
1
- module Jira
2
- class CLI < Thor
3
-
4
- desc "all", "Describes all local branches that match JIRA ticketing syntax"
5
- def all
6
- Command::All.new.run
7
- end
8
-
9
- end
10
-
11
- module Command
12
- class All < Base
13
-
14
- def run
15
- if tickets.empty?
16
- puts 'No tickets'
17
- return
18
- end
19
- return if json.empty?
20
- return unless errors.empty?
21
- render_table(header, rows)
22
- end
23
-
24
- private
25
-
26
- def header
27
- [ 'Ticket', 'Assignee', 'Status', 'Summary' ]
28
- end
29
-
30
- def rows
31
- json['issues'].map do |issue|
32
- [
33
- issue['key'],
34
- issue['fields']['assignee']['name'] || 'Unassigned',
35
- issue['fields']['status']['name'] || 'Unknown',
36
- truncate(issue['fields']['summary'], 45)
37
- ]
38
- end
39
- end
40
-
41
- def errors
42
- @errors ||= (json['errorMessages'] || []).join('. ')
43
- end
44
-
45
- def json
46
- @json ||= api.get "search", params: params
47
- end
48
-
49
- def params
50
- {
51
- jql: "key in (#{tickets.join(',')})"
52
- }
53
- end
54
-
55
- def tickets
56
- @tickets ||= (
57
- tickets = []
58
- branches.each do |branch|
59
- ticket = branch.delete('*').strip
60
- tickets << ticket if Jira::Core.ticket?(ticket, false)
61
- end
62
- tickets
63
- )
64
- end
65
-
66
- def branches
67
- `git branch`.strip.split("\n")
68
- end
69
-
70
- end
71
- end
72
- end
@@ -1,87 +0,0 @@
1
- module Jira
2
- class CLI < Thor
3
-
4
- desc "checkout <ticket>", "Checks out a ticket from JIRA in the git branch"
5
- method_option :remote, aliases: "-r", type: :string, default: nil, lazy_default: "", banner: "REMOTE"
6
- def checkout(ticket)
7
- Command::Checkout.new(ticket, options).run
8
- end
9
-
10
- end
11
-
12
- module Command
13
- class Checkout < Base
14
-
15
- attr_accessor :ticket, :options
16
-
17
- def initialize(ticket, options)
18
- self.ticket = ticket
19
- self.options = options
20
- end
21
-
22
- def run
23
- return unless Jira::Core.ticket?(ticket)
24
- return if metadata.empty?
25
- unless metadata['errorMessages'].nil?
26
- on_failure
27
- return
28
- end
29
- unless remote?
30
- on_failure
31
- return
32
- end
33
-
34
- create_branch unless branches.include?(ticket)
35
- checkout_branch
36
- reset_branch unless branches.include?(ticket)
37
- on_success
38
- end
39
-
40
- private
41
-
42
- def on_success
43
- puts "Ticket #{ticket} checked out."
44
- end
45
-
46
- def on_failure
47
- puts "No ticket checked out."
48
- end
49
-
50
- def branches
51
- @branches ||= `git branch --list 2> /dev/null`.split(' ')
52
- @branches.delete("*")
53
- @branches
54
- end
55
-
56
- def create_branch
57
- `git branch #{ticket} 2> /dev/null`
58
- end
59
-
60
- def checkout_branch
61
- `git checkout #{ticket} 2> /dev/null`
62
- end
63
-
64
- def metadata
65
- @metadata ||= api.get("issue/#{ticket}")
66
- end
67
-
68
- def remote
69
- @remote ||= options['remote'] || io.select('Remote?', remotes)
70
- end
71
-
72
- def remotes
73
- @remotes ||= `git remote 2> /dev/null`.split(' ')
74
- end
75
-
76
- def remote?
77
- return true if remotes.include?(remote)
78
- false
79
- end
80
-
81
- def reset_branch
82
- `git reset --hard #{remote} 2> /dev/null`
83
- end
84
-
85
- end
86
- end
87
- end