jira-cli 0.0.6 → 0.0.7

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: 317a2980fd40942f189582860e629ec9b7ae6c74
4
- data.tar.gz: d39be85a427cdb978a596b590fdf8101c09a3201
3
+ metadata.gz: 049479b74d7e3b923ec62c844e16bc5962540075
4
+ data.tar.gz: 1033a9b5c1a5f36439e448ea8b7013f7a187c1f6
5
5
  SHA512:
6
- metadata.gz: 74509f9851e7c59807417a42f54f763bbcab7232d1920ef115bf69ab6d3eebe376831eaef90125d5c50aaf7660ea38f594479e0f8f458c8e23031563b0f4553d
7
- data.tar.gz: 5fcee4eb59837605287cf6c7e30671110941f4f82baf7351643988676bac2f7ab23ec4a71ffc54e0b8b8918aedf249e210348c913c70b2d44f5ee301e276eebe
6
+ metadata.gz: a7001f018aea98d4a5ef97c71fbaaf2771653ccc82ad47e03c58115252fde08b03c4ec66c7266875ff6a32be242e5cfd508253fbee99f98c1316d6a3a7173444
7
+ data.tar.gz: fd6b4edf8688c04a67d7bf782b7273f0ee97063a753ecf66e2e863c254813df77b8440f7731728c08ff3b13b2364b8a2f6d69205dd2d8bbc27be0fcaadc0c30a
data/README.md CHANGED
@@ -11,8 +11,9 @@ purposes.
11
11
 
12
12
  Installation
13
13
  ------------
14
- cd path/to/jira/repo
15
- jira install
14
+
15
+ cd path/to/jira/repo
16
+ jira install
16
17
 
17
18
  Note: Authentication files are expected to drastically change. Currently, they
18
19
  are completely unencrypted. Use are your own risk... (see disclaimer above)
@@ -6,11 +6,11 @@ require 'jira/core'
6
6
  require 'jira/api'
7
7
  require 'jira/format'
8
8
  require 'jira/mixins'
9
- # command logic
10
- require 'jira/version'
11
- require 'jira/install'
12
- require 'jira/describe'
13
- require 'jira/comment'
9
+ # include jira/commands/*
10
+ Dir.glob(
11
+ File.dirname(File.absolute_path(__FILE__)) + '/jira/commands/*',
12
+ &method(:require)
13
+ )
14
14
 
15
15
  module Jira
16
16
  class CLI < Thor
@@ -18,7 +18,7 @@ module Jira
18
18
  #
19
19
  def get(path, params={})
20
20
  response = @client.get(self.endpoint(path), params, self.headers)
21
- JSON.parse(response.body)
21
+ return response.body.to_s.from_json
22
22
  end
23
23
 
24
24
  #
@@ -31,7 +31,7 @@ module Jira
31
31
  #
32
32
  def post(path, params={})
33
33
  response = @client.post(self.endpoint(path), params, self.headers)
34
- JSON.parse(response.body)
34
+ return response.body.to_s.from_json
35
35
  end
36
36
 
37
37
  protected
@@ -0,0 +1,10 @@
1
+ module Jira
2
+ class CLI < Thor
3
+
4
+ desc "browse", "Opens the current input ticket in your browser"
5
+ def browse(ticket=Jira::Core.ticket)
6
+ system("open #{Jira::Core.url}/browse/#{ticket}")
7
+ end
8
+
9
+ end
10
+ end
@@ -2,8 +2,7 @@ module Jira
2
2
  class CLI < Thor
3
3
 
4
4
  desc "comment", "Add a comment to the input ticket"
5
- def comment(ticket=nil)
6
- ticket ||= `git rev-parse --abbrev-ref HEAD`.strip
5
+ def comment(ticket=Jira::Core.ticket)
7
6
  comment = self.cli.ask("Leave a comment for ticket #{ticket}:")
8
7
  if comment.strip.empty?
9
8
  puts "No comment posted."
@@ -12,17 +11,15 @@ module Jira
12
11
  if json['errorMessages'].nil?
13
12
  puts "Successfully posted your comment."
14
13
  else
15
- puts json['errorMessages'].first
14
+ puts json['errorMessages'].join('. ')
16
15
  end
17
16
  end
18
17
  end
19
18
 
20
19
  desc "comments", "Lists the comments of the input ticket"
21
- def comments(ticket=nil)
22
- ticket ||= `git rev-parse --abbrev-ref HEAD`.strip
20
+ def comments(ticket=Jira::Core.ticket)
23
21
  json = @api.get("issue/#{ticket}")
24
22
  if json['errorMessages'].nil?
25
-
26
23
  comments = json['fields']['comment']['comments']
27
24
  if comments.count > 0
28
25
  comments.each do |comment|
@@ -30,7 +27,7 @@ module Jira
30
27
  time = Time.parse(comment['created'])
31
28
  body = comment['body']
32
29
 
33
- puts "#{Jira::Format.author(author)} @ "\
30
+ puts "#{Jira::Format.user(author)} @ "\
34
31
  "#{Jira::Format.time(time)}:\n"\
35
32
  "#{Jira::Format.comment(body)}"
36
33
  end
@@ -38,7 +35,7 @@ module Jira
38
35
  puts "There are no comments on issue #{ticket}."
39
36
  end
40
37
  else
41
- puts json['errorMessages'].first
38
+ puts json['errorMessages'].join('. ')
42
39
  end
43
40
  end
44
41
 
@@ -2,8 +2,7 @@ module Jira
2
2
  class CLI < Thor
3
3
 
4
4
  desc "describe", "Describes the input ticket"
5
- def describe(ticket=nil)
6
- ticket ||= `git rev-parse --abbrev-ref HEAD`
5
+ def describe(ticket=Jira::Core.ticket)
7
6
  puts description(ticket.strip)
8
7
  end
9
8
 
@@ -58,9 +57,11 @@ module Jira
58
57
  json = @api.get("issue/#{ticket}")
59
58
  summary = json['fields']['summary']
60
59
  status = json['fields']['status']['name']
60
+ assignee = json['fields']['assignee']['name']
61
61
  return Jira::Format.ticket(ticket) +
62
- (star ? Jira::Format.star : " ") +
63
- Jira::Format.status(status) +
62
+ (star ? Jira::Format.star : " ") + " " +
63
+ ("(" + Jira::Format.user(assignee) + ")").ljust(20) +
64
+ Jira::Format.status(status).ljust(26) +
64
65
  Jira::Format.summary(summary)
65
66
  end
66
67
 
@@ -0,0 +1,16 @@
1
+ module Jira
2
+ class CLI < Thor
3
+
4
+ desc "log", "Logs work against the input ticket"
5
+ def log(ticket=Jira::Core.ticket)
6
+ time_spent = self.cli.ask("Time spent on #{ticket}: ")
7
+ json = @api.post("issue/#{ticket}/worklog", { timeSpent: time_spent }.to_json)
8
+ if json['errorMessages'].nil?
9
+ puts "Successfully logged #{time_spent} on #{ticket}."
10
+ else
11
+ puts json['errorMessages'].join('. ')
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,48 @@
1
+ module Jira
2
+ class CLI < Thor
3
+
4
+ desc "transition", "Transitions the input ticket to the next state"
5
+ def transition(ticket=Jira::Core.ticket)
6
+ json = @api.get("issue/#{ticket}/transitions")
7
+
8
+ options = {}
9
+ json['transitions'].each do |transition|
10
+ options[transition['name']] = transition['id']
11
+ end
12
+ options['Cancel'] = nil
13
+
14
+ self.cli.choose do |menu|
15
+ menu.index = :number
16
+ menu.index_suffix = ") "
17
+ menu.header = "Transitions Available For #{ticket}"
18
+ menu.prompt = "Select a transition: "
19
+ options.keys.each do |choice|
20
+ menu.choice choice do
21
+ transition_id = options[choice]
22
+ if transition_id.nil?
23
+ puts "No transition was performed on #{ticket}."
24
+ else
25
+ self.api_transition(ticket, transition_id, choice)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ protected
33
+
34
+ def api_transition(ticket, transition, description)
35
+ json = @api.post(
36
+ "issue/#{ticket}/transitions",
37
+ { transition: { id: transition } }.to_json
38
+ )
39
+ if json.empty?
40
+ puts "Successfully performed transition (#{description}) "\
41
+ "on ticket #{ticket}."
42
+ else
43
+ puts json['errorMessages'].join('. ')
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -1,5 +1,5 @@
1
1
  module Jira
2
2
 
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
 
5
5
  end
@@ -33,6 +33,13 @@ module Jira
33
33
  @password ||= self.auth.last
34
34
  end
35
35
 
36
+ #
37
+ # @return [String] default ticket is the current branch
38
+ #
39
+ def ticket
40
+ `git rev-parse --abbrev-ref HEAD`.strip
41
+ end
42
+
36
43
  #
37
44
  # Determines whether or not the input ticket matches the expected JIRA
38
45
  # ticketing syntax.
@@ -20,7 +20,7 @@ module Jira
20
20
  "#{Thor::Shell::Color::BLUE}"\
21
21
  "#{status}"\
22
22
  "#{Thor::Shell::Color::CLEAR}"\
23
- "]".center(26)
23
+ "]"
24
24
  end
25
25
 
26
26
  def summary(summary)
@@ -30,9 +30,9 @@ module Jira
30
30
  "#{Thor::Shell::Color::CLEAR}"
31
31
  end
32
32
 
33
- def author(author)
33
+ def user(user)
34
34
  "#{Thor::Shell::Color::MAGENTA}"\
35
- "#{author}"\
35
+ "#{user}"\
36
36
  "#{Thor::Shell::Color::CLEAR}"
37
37
  end
38
38
 
@@ -65,7 +65,11 @@ module Jira
65
65
  def wrap(text)
66
66
  width = 80
67
67
  text.split("\n").collect do |line|
68
- line.length > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : line
68
+ if line.length > width
69
+ line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip
70
+ else
71
+ line
72
+ end
69
73
  end * "\n"
70
74
  end
71
75
 
@@ -17,3 +17,13 @@ module Jira
17
17
 
18
18
  end
19
19
  end
20
+
21
+ class String
22
+
23
+ def from_json
24
+ JSON.parse(self)
25
+ rescue
26
+ {}
27
+ end
28
+
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jira-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Lin Cheng
@@ -61,15 +61,17 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - bin/jira
63
63
  - lib/jira/api.rb
64
- - lib/jira/comment.rb
64
+ - lib/jira/commands/browse.rb
65
+ - lib/jira/commands/comment.rb
66
+ - lib/jira/commands/describe.rb
67
+ - lib/jira/commands/install.rb
68
+ - lib/jira/commands/log.rb
69
+ - lib/jira/commands/transition.rb
70
+ - lib/jira/commands/version.rb
65
71
  - lib/jira/constants.rb
66
72
  - lib/jira/core.rb
67
- - lib/jira/describe.rb
68
73
  - lib/jira/format.rb
69
- - lib/jira/install.rb
70
74
  - lib/jira/mixins.rb
71
- - lib/jira/transition.rb
72
- - lib/jira/version.rb
73
75
  - lib/jira.rb
74
76
  - README.md
75
77
  homepage: https://github.com/darrenli/jira-cli
@@ -1,10 +0,0 @@
1
- module Jira
2
- class CLI < Thor
3
-
4
- desc "transition", "Transitions the input ticket to the next state"
5
- def transition(ticket=nil)
6
- puts "Coming soon"
7
- end
8
-
9
- end
10
- end