jira-cli 0.3.3 → 0.3.4

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: 406cae0998f9674bbe8734a161b0c1b53b9b923d
4
- data.tar.gz: 76589c20dff0f392572616955716dd31fa10cbb2
3
+ metadata.gz: 98c9095d9dabba5b2edb2df0aba0d887448af1df
4
+ data.tar.gz: dd2ebf4eb6bfcead3fa14b3f1e810c055f29a212
5
5
  SHA512:
6
- metadata.gz: a4d4af396cc9cdaf1ff6c980a8ca97f26bbaaf0c6bfc97b5b4204b91b6b8adb4d90ce038c1da98a8a0591995fd80da10121f0de173c08af8a6026b3039db3ff3
7
- data.tar.gz: 5b1f38ac95332f74f8898507bd3762ea7c6a45a526ad1943c711fe0ebe012110db513ed23f3556a2e4550085c34332d301290c22b31b9df12bb039774f0821ad
6
+ metadata.gz: 702a29b1122007deb53f149417ff354fcfc9b21c38ecec14d365a22380a277e00fd3ebcdaa7f7380d64867eab74f5ba02e7a809d36db85dd5b32261ac649f945
7
+ data.tar.gz: ddb3495e48300b0e7c09d60ad30b5008829ee414b615f612aa070c7bed1d2dbfd5188788b11527613c76f8cfbf3b5f47072a961faa81c6c3c0a87caf6dc60c15
data/README.md CHANGED
@@ -13,6 +13,7 @@ Ruby gem CLI tool used to manage JIRA workflows leveraging git
13
13
  jira all # Describes all local branches that match JIRA ticketing syntax
14
14
  jira assign # Assign a ticket to a user
15
15
  jira attachments # View ticket attachments
16
+ jira checkout <ticket> # Checks out a ticket from JIRA in the git branch
16
17
  jira comment <command> # Commands for comment operations in JIRA
17
18
  jira delete # Deletes a ticket in JIRA and the git branch
18
19
  jira describe # Describes the input ticket
@@ -26,9 +26,9 @@ module Jira
26
26
  end
27
27
 
28
28
  # TODO: Move this to relevant subcommand Base
29
- def body
29
+ def body(text=nil)
30
30
  @body ||= (
31
- comment = io.ask("Leave a comment for ticket #{ticket}:", default: 'Empty comment').strip
31
+ comment = text || io.ask("Leave a comment for ticket #{ticket}:", default: 'Empty comment').strip
32
32
  comment = comment.gsub(/\@[a-zA-Z]+/, '[~\0]') || comment
33
33
  comment.gsub('[~@', '[~') || comment
34
34
  )
@@ -2,8 +2,9 @@ module Jira
2
2
  class CLI < Thor
3
3
 
4
4
  desc "assign", "Assign a ticket to a user"
5
+ method_option :assignee, aliases: "-a", type: :string, default: nil, lazy_default: "auto", banner: "ASSIGNEE"
5
6
  def assign(ticket=Jira::Core.ticket)
6
- Command::Assign.new(ticket).run
7
+ Command::Assign.new(ticket, options).run
7
8
  end
8
9
 
9
10
  end
@@ -11,10 +12,11 @@ module Jira
11
12
  module Command
12
13
  class Assign < Base
13
14
 
14
- attr_accessor :ticket
15
+ attr_accessor :ticket, :options
15
16
 
16
- def initialize(ticket)
17
+ def initialize(ticket, options={})
17
18
  self.ticket = ticket
19
+ self.options = options
18
20
  end
19
21
 
20
22
  def run
@@ -53,7 +55,7 @@ module Jira
53
55
 
54
56
  def assignee
55
57
  @assignee ||= (
56
- assignee = io.ask('Assignee?', default: 'auto')
58
+ assignee = options['assignee'] || io.ask('Assignee?', default: 'auto')
57
59
  assignee == 'auto' ? '-1' : assignee
58
60
  )
59
61
  end
@@ -31,7 +31,7 @@ module Jira
31
31
  puts "#{Jira::Format.user(name)} #{url}"
32
32
  end
33
33
  else
34
- puts "No attachments found"
34
+ puts "No attachments found for ticket #{ticket}."
35
35
  end
36
36
  end
37
37
 
@@ -0,0 +1,87 @@
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
@@ -2,8 +2,9 @@ module Jira
2
2
  class Comment < Thor
3
3
 
4
4
  desc 'add', 'Add a comment to the input ticket'
5
+ method_option :text, aliases: "-t", type: :string, default: nil, lazy_default: "", banner: "TEXT"
5
6
  def add(ticket=Jira::Core.ticket)
6
- Command::Comment::Add.new(ticket).run
7
+ Command::Comment::Add.new(ticket, options).run
7
8
  end
8
9
 
9
10
  end
@@ -12,14 +13,15 @@ module Jira
12
13
  module Comment
13
14
  class Add < Base
14
15
 
15
- attr_accessor :ticket
16
+ attr_accessor :ticket, :options
16
17
 
17
- def initialize(ticket)
18
+ def initialize(ticket, options)
18
19
  self.ticket = ticket
20
+ self.options = options
19
21
  end
20
22
 
21
23
  def run
22
- return if body.empty?
24
+ return if text.empty?
23
25
  api.post "issue/#{ticket}/comment",
24
26
  params: params,
25
27
  success: on_success,
@@ -29,7 +31,11 @@ module Jira
29
31
  private
30
32
 
31
33
  def params
32
- { body: body }
34
+ { body: text }
35
+ end
36
+
37
+ def text
38
+ body(options['text'])
33
39
  end
34
40
 
35
41
  def on_success
@@ -2,8 +2,9 @@ module Jira
2
2
  class Log < Thor
3
3
 
4
4
  desc 'add', 'Logs work against the input ticket'
5
+ method_option :time, aliases: "-t", type: :string, default: nil, lazy_default: "", banner: "TIME"
5
6
  def add(ticket=Jira::Core.ticket)
6
- Command::Log::Add.new(ticket).run
7
+ Command::Log::Add.new(ticket, options).run
7
8
  end
8
9
 
9
10
  end
@@ -12,10 +13,11 @@ module Jira
12
13
  module Log
13
14
  class Add < Base
14
15
 
15
- attr_accessor :ticket
16
+ attr_accessor :ticket, :options
16
17
 
17
- def initialize(ticket)
18
+ def initialize(ticket, options)
18
19
  self.ticket = ticket
20
+ self.options = options
19
21
  end
20
22
 
21
23
  def run
@@ -33,7 +35,7 @@ module Jira
33
35
  end
34
36
 
35
37
  def time_spent
36
- @time_spent ||= io.ask("Time spent on ticket #{ticket}:")
38
+ @time_spent ||= options['time'] || io.ask("Time spent on ticket #{ticket}:")
37
39
  end
38
40
 
39
41
  def on_success
@@ -2,8 +2,15 @@ module Jira
2
2
  class CLI < Thor
3
3
 
4
4
  desc "new", "Creates a new ticket in JIRA and checks out the git branch"
5
+ method_option :project, aliases: "-p", type: :string, default: nil, banner: "PROJECT"
6
+ method_option :components, aliases: "-c", type: :array, default: nil, lazy_default: [], banner: "COMPONENTS"
7
+ method_option :issuetype, aliases: "-i", type: :string, default: nil, banner: "ISSUETYPE"
8
+ method_option :parent, type: :string, default: nil, lazy_default: "", banner: "PARENT"
9
+ method_option :summary, aliases: "-s", type: :string, default: nil, banner: "SUMMARY"
10
+ method_option :description, aliases: "-d", type: :string, default: nil, lazy_default: "", banner: "DESCRIPTION"
11
+ method_option :assignee, aliases: "-a", type: :string, default: nil, lazy_default: "auto", banner: "ASSIGNEE"
5
12
  def new
6
- Command::New.new.run
13
+ Command::New.new(options).run
7
14
  end
8
15
 
9
16
  end
@@ -11,12 +18,18 @@ module Jira
11
18
  module Command
12
19
  class New < Base
13
20
 
21
+ attr_accessor :options
22
+
23
+ def initialize(options)
24
+ self.options = options
25
+ end
26
+
14
27
  def run
15
28
  return if metadata.empty?
16
- return if project.empty?
29
+ return if project.nil? || project.empty?
17
30
  return if project_metadata.empty?
18
31
  components # Select components if any after a project
19
- return if issue_type.empty?
32
+ return if issue_type.nil? || issue_type.empty?
20
33
  return if assign_parent? && parent.empty?
21
34
  return if summary.empty?
22
35
 
@@ -47,13 +60,13 @@ module Jira
47
60
  ->(json) do
48
61
  self.ticket = json['key']
49
62
  io.say("Ticket #{ticket} created.")
50
- assign?
51
- create_branch? && checkout_branch?
63
+ assign? if options.empty? || !options['assignee'].nil?
64
+ create_branch? && checkout_branch? if options.empty?
52
65
  end
53
66
  end
54
67
 
55
68
  def assign?
56
- Command::Assign.new(ticket).run if io.yes?('Assign?')
69
+ Command::Assign.new(ticket, options).run if !options['assignee'].nil? || io.yes?('Assign?')
57
70
  end
58
71
 
59
72
  def create_branch?
@@ -79,7 +92,7 @@ module Jira
79
92
 
80
93
  def project
81
94
  @project ||= projects[
82
- io.select("Select a project:", projects.keys)
95
+ options['project'] || io.select("Select a project:", projects.keys)
83
96
  ]
84
97
  end
85
98
 
@@ -108,24 +121,30 @@ module Jira
108
121
  components[component['name']] = { 'id' => component['id'] }
109
122
  end
110
123
  unless components.empty?
111
- io.multi_select("Select component(s):", components)
124
+ if options['components'].nil?
125
+ components = io.multi_select("Select component(s):", components)
126
+ else
127
+ components.select! { |k| options['components'].include?(k) }
128
+ components = components.values
129
+ end
112
130
  end
131
+ components.to_a
113
132
  )
114
133
  end
115
134
 
116
135
  def assign_parent?
117
136
  return false unless issue_type['subtask']
118
- return false if io.no?('Set parent of subtask?')
137
+ return false if options['parent'].nil? && io.no?('Set parent of subtask?')
119
138
  true
120
139
  end
121
140
 
122
141
  def parent
123
- @parent ||= io.ask('Subtask parent:', default: Jira::Core.ticket)
142
+ @parent ||= options['parent'] || io.ask('Subtask parent:', default: Jira::Core.ticket)
124
143
  end
125
144
 
126
145
  def issue_type
127
146
  @issue_type ||= issue_types[
128
- io.select("Select an issue type:", issue_types.keys)
147
+ options['issuetype'] || io.select("Select an issue type:", issue_types.keys)
129
148
  ]
130
149
  end
131
150
 
@@ -140,11 +159,14 @@ module Jira
140
159
  end
141
160
 
142
161
  def summary
143
- @summary ||= io.ask("Summary:", default: '')
162
+ @summary ||= options['summary'] || io.ask("Summary:", default: '')
144
163
  end
145
164
 
146
165
  def description
147
- @description ||= io.ask("Description:", default: '')
166
+ @description ||= (
167
+ description = options['description'] || (io.ask("Description:", default: '') if options['summary'].nil?)
168
+ description ||= ""
169
+ )
148
170
  end
149
171
 
150
172
  end
@@ -2,8 +2,9 @@ module Jira
2
2
  class CLI < Thor
3
3
 
4
4
  desc "rename", "Updates the summary of the input ticket"
5
+ method_option :summary, aliases: "-s", type: :string, default: nil, lazy_default: "", banner: "SUMMARY"
5
6
  def rename(ticket=Jira::Core.ticket)
6
- Command::Rename.new(ticket).run
7
+ Command::Rename.new(ticket, options).run
7
8
  end
8
9
 
9
10
  end
@@ -11,10 +12,11 @@ module Jira
11
12
  module Command
12
13
  class Rename < Base
13
14
 
14
- attr_accessor :ticket
15
+ attr_accessor :ticket, :options
15
16
 
16
- def initialize(ticket)
17
+ def initialize(ticket, options)
17
18
  self.ticket = ticket
19
+ self.options = options
18
20
  end
19
21
 
20
22
  def run
@@ -43,7 +45,7 @@ module Jira
43
45
  end
44
46
 
45
47
  def summary
46
- @summary ||= io.ask("New summary for ticket #{ticket}:", default: '')
48
+ @summary ||= options['summary'] || io.ask("New summary for ticket #{ticket}:", default: '')
47
49
  end
48
50
 
49
51
  end
@@ -2,8 +2,9 @@ module Jira
2
2
  class CLI < Thor
3
3
 
4
4
  desc "transition", "Transitions the input ticket to the next state"
5
+ method_option :transition, aliases: "-t", type: :string, default: nil, lazy_default: "", banner: "TRANSITION"
5
6
  def transition(ticket=Jira::Core.ticket)
6
- Command::Transition.new(ticket).run
7
+ Command::Transition.new(ticket, options).run
7
8
  end
8
9
 
9
10
  end
@@ -11,17 +12,18 @@ module Jira
11
12
  module Command
12
13
  class Transition < Base
13
14
 
14
- attr_accessor :ticket
15
+ attr_accessor :ticket, :options
15
16
 
16
- def initialize(ticket)
17
+ def initialize(ticket, options)
17
18
  self.ticket = ticket
19
+ self.options = options
18
20
  end
19
21
 
20
22
  def run
21
23
  return if ticket.empty?
22
24
  return if metadata.empty?
23
25
  return unless metadata['errorMessages'].nil?
24
- return if transition.empty?
26
+ return if transition.nil? || transition.empty?
25
27
  api.post "issue/#{ticket}/transitions",
26
28
  params: params,
27
29
  success: on_success,
@@ -48,7 +50,7 @@ module Jira
48
50
 
49
51
  def transition
50
52
  @transition ||= transitions[
51
- io.select("Transition #{ticket} to:", transitions.keys)
53
+ options['transition'] || io.select("Transition #{ticket} to:", transitions.keys)
52
54
  ]
53
55
  end
54
56
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jira
4
4
 
5
- VERSION = '0.3.3'.freeze
5
+ VERSION = '0.3.4'.freeze
6
6
 
7
7
  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.3
4
+ version: 0.3.4
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-02-15 00:00:00.000000000 Z
11
+ date: 2016-02-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -140,6 +140,7 @@ files:
140
140
  - lib/jira/commands/all.rb
141
141
  - lib/jira/commands/assign.rb
142
142
  - lib/jira/commands/attachments.rb
143
+ - lib/jira/commands/checkout.rb
143
144
  - lib/jira/commands/comment.rb
144
145
  - lib/jira/commands/comment/add.rb
145
146
  - lib/jira/commands/comment/delete.rb