jira-cli 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jira.rb +5 -2
- data/lib/jira/api.rb +13 -4
- data/lib/jira/comment.rb +46 -0
- data/lib/jira/constants.rb +1 -1
- data/lib/jira/{lookup.rb → describe.rb} +2 -12
- data/lib/jira/format.rb +39 -0
- data/lib/jira/transition.rb +10 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 317a2980fd40942f189582860e629ec9b7ae6c74
|
4
|
+
data.tar.gz: d39be85a427cdb978a596b590fdf8101c09a3201
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74509f9851e7c59807417a42f54f763bbcab7232d1920ef115bf69ab6d3eebe376831eaef90125d5c50aaf7660ea38f594479e0f8f458c8e23031563b0f4553d
|
7
|
+
data.tar.gz: 5fcee4eb59837605287cf6c7e30671110941f4f82baf7351643988676bac2f7ab23ec4a71ffc54e0b8b8918aedf249e210348c913c70b2d44f5ee301e276eebe
|
data/lib/jira.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
# dependencies
|
1
2
|
require 'thor'
|
2
|
-
|
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/
|
12
|
+
require 'jira/describe'
|
13
|
+
require 'jira/comment'
|
11
14
|
|
12
15
|
module Jira
|
13
16
|
class CLI < Thor
|
data/lib/jira/api.rb
CHANGED
@@ -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
|
data/lib/jira/comment.rb
ADDED
@@ -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
|
data/lib/jira/constants.rb
CHANGED
@@ -3,8 +3,8 @@ module Jira
|
|
3
3
|
|
4
4
|
desc "describe", "Describes the input ticket"
|
5
5
|
def describe(ticket=nil)
|
6
|
-
ticket
|
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
|
#
|
data/lib/jira/format.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|