jira-cli 0.0.5 → 0.0.6

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: b826964d62b495e6d3be063a47c450f57045ac66
4
- data.tar.gz: 330405878fa794dbb8870a29e04f6168bb13294c
3
+ metadata.gz: 317a2980fd40942f189582860e629ec9b7ae6c74
4
+ data.tar.gz: d39be85a427cdb978a596b590fdf8101c09a3201
5
5
  SHA512:
6
- metadata.gz: 5dfb2fb820a72b9644e51759ac43745f586c56ab4a35637e02554e4b7d7042040c7ad1289be38fc935345c050ceef081cd5f8ffa7a7a93457a84458d6be0f948
7
- data.tar.gz: 4688e54ca3153f165e20dfbda4e1d715bbf7132c8c7d1403ed4237b7d01dcf89a76f6a432c9d33e5cd96c5d1cf4e94e8c17fc1dec02d09ca0c5bba3525f1c7cf
6
+ metadata.gz: 74509f9851e7c59807417a42f54f763bbcab7232d1920ef115bf69ab6d3eebe376831eaef90125d5c50aaf7660ea38f594479e0f8f458c8e23031563b0f4553d
7
+ data.tar.gz: 5fcee4eb59837605287cf6c7e30671110941f4f82baf7351643988676bac2f7ab23ec4a71ffc54e0b8b8918aedf249e210348c913c70b2d44f5ee301e276eebe
@@ -1,13 +1,16 @@
1
+ # dependencies
1
2
  require 'thor'
2
- require 'fileutils'
3
+ # core logic
3
4
  require 'jira/constants'
4
5
  require 'jira/core'
5
6
  require 'jira/api'
6
7
  require 'jira/format'
7
8
  require 'jira/mixins'
9
+ # command logic
8
10
  require 'jira/version'
9
11
  require 'jira/install'
10
- require 'jira/lookup'
12
+ require 'jira/describe'
13
+ require 'jira/comment'
11
14
 
12
15
  module Jira
13
16
  class CLI < Thor
@@ -16,8 +16,8 @@ module Jira
16
16
  #
17
17
  # @return [JSON] parsed API response
18
18
  #
19
- def get(path)
20
- response = @client.get(self.endpoint(path))
19
+ def get(path, params={})
20
+ response = @client.get(self.endpoint(path), params, self.headers)
21
21
  JSON.parse(response.body)
22
22
  end
23
23
 
@@ -29,8 +29,8 @@ module Jira
29
29
  #
30
30
  # @return [JSON] parsed API response
31
31
  #
32
- def post(path, params)
33
- response = @client.post(self.endpoint(path), params)
32
+ def post(path, params={})
33
+ response = @client.post(self.endpoint(path), params, self.headers)
34
34
  JSON.parse(response.body)
35
35
  end
36
36
 
@@ -47,5 +47,14 @@ module Jira
47
47
  "#{Jira::Core.url}/rest/api/2/#{path}"
48
48
  end
49
49
 
50
+ #
51
+ # Returns the default API headers
52
+ #
53
+ # @return [Hash] API headers
54
+ #
55
+ def headers
56
+ { 'Content-Type' => 'application/json' }
57
+ end
58
+
50
59
  end
51
60
  end
@@ -0,0 +1,46 @@
1
+ module Jira
2
+ class CLI < Thor
3
+
4
+ desc "comment", "Add a comment to the input ticket"
5
+ def comment(ticket=nil)
6
+ ticket ||= `git rev-parse --abbrev-ref HEAD`.strip
7
+ comment = self.cli.ask("Leave a comment for ticket #{ticket}:")
8
+ if comment.strip.empty?
9
+ puts "No comment posted."
10
+ else
11
+ json = @api.post("issue/#{ticket}/comment", { body: comment }.to_json)
12
+ if json['errorMessages'].nil?
13
+ puts "Successfully posted your comment."
14
+ else
15
+ puts json['errorMessages'].first
16
+ end
17
+ end
18
+ end
19
+
20
+ desc "comments", "Lists the comments of the input ticket"
21
+ def comments(ticket=nil)
22
+ ticket ||= `git rev-parse --abbrev-ref HEAD`.strip
23
+ json = @api.get("issue/#{ticket}")
24
+ if json['errorMessages'].nil?
25
+
26
+ comments = json['fields']['comment']['comments']
27
+ if comments.count > 0
28
+ comments.each do |comment|
29
+ author = comment['author']['displayName']
30
+ time = Time.parse(comment['created'])
31
+ body = comment['body']
32
+
33
+ puts "#{Jira::Format.author(author)} @ "\
34
+ "#{Jira::Format.time(time)}:\n"\
35
+ "#{Jira::Format.comment(body)}"
36
+ end
37
+ else
38
+ puts "There are no comments on issue #{ticket}."
39
+ end
40
+ else
41
+ puts json['errorMessages'].first
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  module Jira
2
2
 
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.6"
4
4
 
5
5
  end
@@ -3,8 +3,8 @@ module Jira
3
3
 
4
4
  desc "describe", "Describes the input ticket"
5
5
  def describe(ticket=nil)
6
- ticket || `git rev-parse --abbrev-ref HEAD`
7
- description(ticket.strip)
6
+ ticket ||= `git rev-parse --abbrev-ref HEAD`
7
+ puts description(ticket.strip)
8
8
  end
9
9
 
10
10
  desc "all", "Describes all local branches that match JIRA ticketing syntax"
@@ -44,16 +44,6 @@ module Jira
44
44
  puts output
45
45
  end
46
46
 
47
- desc "comment", "Add a comment to the input ticket"
48
- def comment(ticket=nil)
49
- say "Coming soon"
50
- end
51
-
52
- desc "transition", "Transitions the input ticket to the next state"
53
- def transition(ticket=nil)
54
- say "Coming soon"
55
- end
56
-
57
47
  protected
58
48
 
59
49
  #
@@ -30,6 +30,45 @@ module Jira
30
30
  "#{Thor::Shell::Color::CLEAR}"
31
31
  end
32
32
 
33
+ def author(author)
34
+ "#{Thor::Shell::Color::MAGENTA}"\
35
+ "#{author}"\
36
+ "#{Thor::Shell::Color::CLEAR}"
37
+ end
38
+
39
+ def time(time)
40
+ "#{Thor::Shell::Color::BLUE}"\
41
+ "#{time.strftime("%l:%M%P on %b %d, %Y").strip}"\
42
+ "#{Thor::Shell::Color::CLEAR}"
43
+ end
44
+
45
+ def comment(comment)
46
+ comment = self.wrap(comment)
47
+ comment.gsub!(/\[~[a-z]+\]/, '[[[\0]]]')
48
+ comment.gsub!(
49
+ '[[[[~',
50
+ "#{Thor::Shell::Color::BOLD}"\
51
+ "#{Thor::Shell::Color::WHITE}"\
52
+ "("\
53
+ "#{Thor::Shell::Color::MAGENTA}"\
54
+ "@"
55
+ )
56
+ comment.gsub!(
57
+ ']]]]',
58
+ "#{Thor::Shell::Color::WHITE}"\
59
+ ")"\
60
+ "#{Thor::Shell::Color::CLEAR}"
61
+ )
62
+ return comment
63
+ end
64
+
65
+ def wrap(text)
66
+ width = 80
67
+ text.split("\n").collect do |line|
68
+ line.length > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : line
69
+ end * "\n"
70
+ end
71
+
33
72
  end
34
73
  end
35
74
  end
@@ -0,0 +1,10 @@
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
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.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darren Lin Cheng
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-06 00:00:00.000000000 Z
11
+ date: 2013-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -61,12 +61,14 @@ extra_rdoc_files: []
61
61
  files:
62
62
  - bin/jira
63
63
  - lib/jira/api.rb
64
+ - lib/jira/comment.rb
64
65
  - lib/jira/constants.rb
65
66
  - lib/jira/core.rb
67
+ - lib/jira/describe.rb
66
68
  - lib/jira/format.rb
67
69
  - lib/jira/install.rb
68
- - lib/jira/lookup.rb
69
70
  - lib/jira/mixins.rb
71
+ - lib/jira/transition.rb
70
72
  - lib/jira/version.rb
71
73
  - lib/jira.rb
72
74
  - README.md