jira-cli 0.3.2 → 0.3.3

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: 97bdc67147e5f936b6b9eca1e0153327185fcbaa
4
- data.tar.gz: 82a46d41fbe2fefc1c288fe45a0f1bbcbe396a4f
3
+ metadata.gz: 406cae0998f9674bbe8734a161b0c1b53b9b923d
4
+ data.tar.gz: 76589c20dff0f392572616955716dd31fa10cbb2
5
5
  SHA512:
6
- metadata.gz: df959df35c8e949e13d11c2703df4c2ae860b50e61fe40d15df96ca0e4af223b0a94822e6aa41c92fb384016cc29a7a8f58f3d3fa7261d71df0a694b3286744d
7
- data.tar.gz: a6bb8e513b9f9ca761a705e29aa23c2377deee7065f4f1b1218e9e0bba1c30323f5afbcf940928e93bea5c1e59d96219418ed008066971d3a92b19bbbac8cf8f
6
+ metadata.gz: a4d4af396cc9cdaf1ff6c980a8ca97f26bbaaf0c6bfc97b5b4204b91b6b8adb4d90ce038c1da98a8a0591995fd80da10121f0de173c08af8a6026b3039db3ff3
7
+ data.tar.gz: 5b1f38ac95332f74f8898507bd3762ea7c6a45a526ad1943c711fe0ebe012110db513ed23f3556a2e4550085c34332d301290c22b31b9df12bb039774f0821ad
data/bin/jira CHANGED
@@ -3,8 +3,8 @@
3
3
  require 'jira'
4
4
  begin
5
5
  Jira::CLI.start
6
- rescue Faraday::Error
7
- puts "JIRA failed connect, you may need to rerun 'jira install'"
6
+ rescue Faraday::Error, UnauthorizedException
7
+ puts "JIRA failed connect, you may need to rerun 'jira install'" unless Jira::CLI.new.try_install_cookie
8
8
  rescue GitException
9
9
  puts "JIRA commands can only be run within a git repository."
10
10
  rescue InstallationException
@@ -24,6 +24,7 @@ module Jira
24
24
  protected
25
25
 
26
26
  def process(response, options)
27
+ raise UnauthorizedException if response.status == 401
27
28
  json = response.body || {}
28
29
  if response.success? && json['errorMessages'].nil?
29
30
  respond_to(options[:success], json)
@@ -1,6 +1,7 @@
1
- # internal dependencies
1
+ # external dependencies
2
2
  require 'time'
3
3
 
4
+ # internal dependencies
4
5
  require 'jira/api'
5
6
  require 'jira/sprint_api'
6
7
  require 'jira/auth_api'
@@ -27,7 +28,7 @@ module Jira
27
28
  # TODO: Move this to relevant subcommand Base
28
29
  def body
29
30
  @body ||= (
30
- comment = io.ask("Leave a comment for ticket #{ticket}:").strip
31
+ comment = io.ask("Leave a comment for ticket #{ticket}:", default: 'Empty comment').strip
31
32
  comment = comment.gsub(/\@[a-zA-Z]+/, '[~\0]') || comment
32
33
  comment.gsub('[~@', '[~') || comment
33
34
  )
@@ -12,9 +12,12 @@ module Jira
12
12
  class All < Base
13
13
 
14
14
  def run
15
- puts 'No tickets' and return if tickets.empty?
15
+ if tickets.empty?
16
+ puts 'No tickets'
17
+ return
18
+ end
16
19
  return if json.empty?
17
- return if errored?
20
+ return unless errors.empty?
18
21
  render_table(header, rows)
19
22
  end
20
23
 
@@ -35,12 +38,6 @@ module Jira
35
38
  end
36
39
  end
37
40
 
38
- def errored?
39
- return false if errors.empty?
40
- puts errors
41
- true
42
- end
43
-
44
41
  def errors
45
42
  @errors ||= (json['errorMessages'] || []).join('. ')
46
43
  end
@@ -66,12 +66,12 @@ module Jira
66
66
  def description_for(comment)
67
67
  author = comment['updateAuthor']['displayName']
68
68
  updated_at = Jira::Format.time(Time.parse(comment['updated']))
69
- body = comment['body'].gsub("\r\n|\r|\n", ";")
69
+ body = comment['body'].split.join(" ")
70
70
  truncate("#{author} @ #{updated_at}: #{body}", 160)
71
71
  end
72
72
 
73
73
  def json
74
- @json ||= api.get("issue/#{ticket}/comment")['comments']
74
+ @json ||= api.get("issue/#{ticket}/comment")['comments'] || {}
75
75
  end
76
76
 
77
77
  end
@@ -19,6 +19,8 @@ module Jira
19
19
  end
20
20
 
21
21
  def run
22
+ return if comments.nil?
23
+
22
24
  if comments.empty?
23
25
  puts "Ticket #{ticket} has no comments."
24
26
  return
@@ -56,7 +58,8 @@ module Jira
56
58
  end
57
59
 
58
60
  def body
59
- comment['body']
61
+ body = comment['body'].gsub("\r\n|\r|\n", ";")
62
+ truncate(body, 45)
60
63
  end
61
64
 
62
65
  def comments
@@ -74,7 +74,7 @@ module Jira
74
74
  def description_for(comment)
75
75
  author = comment['updateAuthor']['displayName']
76
76
  updated_at = Jira::Format.time(Time.parse(comment['updated']))
77
- body = comment['body'].gsub("\r\n|\r|\n", ";")
77
+ body = comment['body'].split.join(" ")
78
78
  truncate("#{author} @ #{updated_at}: #{body}", 160)
79
79
  end
80
80
 
@@ -19,7 +19,7 @@ module Jira
19
19
 
20
20
  def run
21
21
  return if json.empty?
22
- return if errored?
22
+ return unless errors.empty?
23
23
  render_table(header, [row])
24
24
  end
25
25
 
@@ -31,12 +31,6 @@ module Jira
31
31
  [ ticket, assignee, status, summary ]
32
32
  end
33
33
 
34
- def errored?
35
- return false if errors.empty?
36
- puts errors
37
- true
38
- end
39
-
40
34
  def errors
41
35
  @errors ||= (json['errorMessages'] || []).join('. ')
42
36
  end
@@ -6,6 +6,18 @@ module Jira
6
6
  Command::Install.new.run
7
7
  end
8
8
 
9
+ no_commands do
10
+ def try_install_cookie
11
+ return false if Jira::Core.cookie.empty?
12
+ puts " ... cookie expired, renewing your cookie"
13
+ Command::Install.new.run_rescue_cookie
14
+ puts "Cookie renewed, please retry your last command."
15
+ return true
16
+ rescue Interrupt, StandardError
17
+ false
18
+ end
19
+ end
20
+
9
21
  end
10
22
 
11
23
  module Command
@@ -23,7 +35,7 @@ module Jira
23
35
  when "token"
24
36
  inifile[:global][:token] = token
25
37
  when "cookie"
26
- response = cookie
38
+ response = cookie(session_params)
27
39
  inifile[:cookie] = {}
28
40
  inifile[:cookie][:name] = response['name']
29
41
  inifile[:cookie][:value] = response['value']
@@ -31,6 +43,15 @@ module Jira
31
43
  inifile.write
32
44
  end
33
45
 
46
+ def run_rescue_cookie
47
+ response = cookie(rescue_cookie_params)
48
+ config = Jira::Core.config
49
+ config[:cookie] = {}
50
+ config[:cookie][:name] = response['name']
51
+ config[:cookie][:value] = response['value']
52
+ config.write
53
+ end
54
+
34
55
  private
35
56
 
36
57
  def base_params
@@ -40,6 +61,13 @@ module Jira
40
61
  }
41
62
  end
42
63
 
64
+ def rescue_cookie_params
65
+ {
66
+ username: Jira::Core.username,
67
+ password: password
68
+ }
69
+ end
70
+
43
71
  def session_params
44
72
  {
45
73
  username: username,
@@ -70,8 +98,8 @@ module Jira
70
98
  io.ask("JIRA token:")
71
99
  end
72
100
 
73
- def cookie
74
- response = auth_api.post('session', params: session_params)
101
+ def cookie(params)
102
+ response = auth_api.post('session', params: params)
75
103
  return {} unless response['errorMessages'].nil?
76
104
  response['session']
77
105
  end
@@ -43,7 +43,7 @@ module Jira
43
43
  end
44
44
 
45
45
  def summary
46
- @summary ||= io.ask("New summary for ticket #{ticket}:")
46
+ @summary ||= io.ask("New summary for ticket #{ticket}:", default: '')
47
47
  end
48
48
 
49
49
  end
@@ -20,6 +20,8 @@ module Jira
20
20
  def run
21
21
  return if jql.empty?
22
22
  return if metadata.empty?
23
+ return unless metadata['errorMessages'].nil?
24
+
23
25
  puts "There are no tickets for jql=#{jql}." and return if rows.empty?
24
26
  render_table(header, rows)
25
27
  end
@@ -20,6 +20,7 @@ module Jira
20
20
  def run
21
21
  return if ticket.empty?
22
22
  return if metadata.empty?
23
+ return unless metadata['errorMessages'].nil?
23
24
  return if transition.empty?
24
25
  api.post "issue/#{ticket}/transitions",
25
26
  params: params,
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jira
2
4
 
3
- VERSION = '0.3.2'.freeze
5
+ VERSION = '0.3.3'.freeze
4
6
 
5
7
  end
@@ -72,6 +72,13 @@ module Jira
72
72
  @cli_path ||= root_path + "/.jira-cli"
73
73
  end
74
74
 
75
+ def config
76
+ @config ||= (
77
+ raise InstallationException unless File.exist?(cli_path)
78
+ IniFile.load(cli_path, comment: '#', encoding: 'UTF-8')
79
+ )
80
+ end
81
+
75
82
  private
76
83
 
77
84
  def root_path
@@ -82,13 +89,6 @@ module Jira
82
89
  )
83
90
  end
84
91
 
85
- def config
86
- @config ||= (
87
- raise InstallationException unless File.exist?(cli_path)
88
- IniFile.load(cli_path, comment: '#', encoding: 'UTF-8')
89
- )
90
- end
91
-
92
92
  end
93
93
  end
94
94
  end
@@ -1,2 +1,3 @@
1
- class InstallationException < Exception; end
2
- class GitException < Exception; end
1
+ class InstallationException < StandardError; end
2
+ class GitException < StandardError; end
3
+ class UnauthorizedException < StandardError; end
@@ -2,24 +2,24 @@ module Jira
2
2
  class SprintAPI < API
3
3
 
4
4
  def sprint(rapid_view_id, sprint_id)
5
- response = client.get(
6
- 'rapid/charts/sprintreport',
5
+ params = {
7
6
  rapidViewId: rapid_view_id,
8
7
  sprintId: sprint_id
9
- )
10
- return response.body if response.success?
8
+ }
9
+ json = get('rapid/charts/sprintreport', params: params) || {}
10
+ return json if json['errorMessages'].nil?
11
11
  {}
12
12
  end
13
13
 
14
14
  def sprints(rapid_view_id)
15
- response = client.get("sprintquery/#{rapid_view_id}")
16
- return response.body if response.success?
15
+ json = get("sprintquery/#{rapid_view_id}")
16
+ return json if json['errorMessages'].nil?
17
17
  {}
18
18
  end
19
19
 
20
20
  def rapid_views
21
- response = client.get("rapidview")
22
- return response.body['views'] if response.success?
21
+ json = get("rapidview")
22
+ return json['views'] if json['errorMessages'].nil?
23
23
  []
24
24
  end
25
25
 
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.2
4
+ version: 0.3.3
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-11 00:00:00.000000000 Z
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor