jira-cli 0.0.9 → 0.1.0

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: cde1ac20a643d00b9b6d3308c49a84b94db85281
4
- data.tar.gz: 807d024db48e5b22661a588aa6290c2ba65c3cfc
3
+ metadata.gz: 0ca6267c77e326c0be178c9b35257a49553174d2
4
+ data.tar.gz: a0320f7c4ae0fc4196c6b4386b7efd3da643f98d
5
5
  SHA512:
6
- metadata.gz: a1c9306b45a7f7126bafda539d153d6d20fecff6dd566b7c21007ab8b33f5ec2a3aa2f7f9e1ca80c830c22ae8e4a31c7a72b0afd91378c31da9feeaaba4e401a
7
- data.tar.gz: 9d0cda918e9e06385c4ae62c5872a506c7c80104a4f250507ef4a1efc143623de42ae4f152d600e4a70836104437b5021cb068701ea3d1b290b259ad3aebd0fd
6
+ metadata.gz: 176917e6f4b0eb6773ea0ee302788b0b5957215ffa1deb3c48233c3d0ad867dce4a9f065b4cf8c829d83eb05de010cdc28d85e200de3a7df870db8557b5b1f54
7
+ data.tar.gz: 3578a7a0559bf7c51ff21a28d519a47ef571ab1c163f6d6cfcad1e3c8fb29fc091bcfb537938ebc838029cb531282dd823df554423e674aaca3218ce2c36930b
data/bin/jira CHANGED
@@ -1,5 +1,11 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  require 'jira'
4
-
5
- Jira::CLI.start
4
+ begin
5
+ Jira::CLI.start
6
+ rescue GitException
7
+ puts "JIRA commands can only be run within a git repository."
8
+ rescue InstallationException
9
+ puts "Please run #{Jira::Format.summary('jira install')} before "\
10
+ "running this command."
11
+ end
data/lib/jira.rb CHANGED
@@ -6,6 +6,7 @@ require 'jira/core'
6
6
  require 'jira/api'
7
7
  require 'jira/format'
8
8
  require 'jira/mixins'
9
+ require 'jira/exceptions'
9
10
  # include jira/commands/*
10
11
  Dir.glob(
11
12
  File.dirname(File.absolute_path(__FILE__)) + '/jira/commands/*',
@@ -17,9 +18,17 @@ module Jira
17
18
 
18
19
  def initialize(args=[], options={}, config={})
19
20
  super
20
- Jira::Core.setup
21
- self.api
21
+ self.suppress{ Jira::Core.setup }
22
+ self.suppress{ self.api }
22
23
  end
23
24
 
25
+ protected
26
+
27
+ def suppress
28
+ yield
29
+ rescue GitException
30
+ rescue InstallationException
31
+ end
32
+
24
33
  end
25
34
  end
@@ -7,6 +7,7 @@ module Jira
7
7
  if comment.strip.empty?
8
8
  puts "No comment posted."
9
9
  else
10
+ comment.gsub!(/\@[a-zA-Z]+/,'[~\0]').gsub!('[~@','[~')
10
11
  self.api.post("issue/#{ticket}/comment", { body: comment }) do |json|
11
12
  puts "Successfully posted your comment."
12
13
  end
@@ -0,0 +1,14 @@
1
+ module Jira
2
+ class CLI < Thor
3
+
4
+ desc "commit", "Commits uncommitted work with the ticket name and summary."
5
+ def commit(ticket=Jira::Core.ticket)
6
+ if Jira::Core.ticket?(ticket)
7
+ self.api.get("issue/#{ticket}") do |json|
8
+ `git commit -m '#{ticket}. #{json['fields']['summary'].periodize}'`
9
+ end
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -6,8 +6,6 @@ module Jira
6
6
  if Jira::Core.ticket?(ticket)
7
7
  output = description(ticket.strip, false, true)
8
8
  puts output if !output.strip.empty?
9
- else
10
- puts "The ticket #{ticket} is not a valid JIRA ticket."
11
9
  end
12
10
  end
13
11
 
@@ -22,7 +20,7 @@ module Jira
22
20
  branches = `git branch`.strip.split("\n")
23
21
  branches.each do |branch|
24
22
  ticket = branch.delete('*').strip
25
- if Jira::Core.ticket?(ticket)
23
+ if Jira::Core.ticket?(ticket, false)
26
24
  if branch.include?('*')
27
25
  tickets[:current] = ticket
28
26
  else
@@ -30,6 +30,7 @@ module Jira
30
30
  self.api.post("issue", params) do |json|
31
31
  ticket = json['key']
32
32
  `git checkout -b #{ticket} 2> /dev/null`
33
+ `git checkout #{ticket} 2> /dev/null`
33
34
  puts "\nTicket and branch #{Jira::Format.ticket(ticket)} created."
34
35
  return
35
36
  end
@@ -13,7 +13,7 @@ module Jira
13
13
  self.cli.choose do |menu|
14
14
  menu.index = :number
15
15
  menu.index_suffix = ") "
16
- menu.header = "Transition #{Jira::Format.ticket(ticket)} to:"
16
+ menu.header = "Transition #{Jira::Format.ticket(ticket)} to"
17
17
  menu.prompt = "Transition to: "
18
18
  options.keys.each do |choice|
19
19
  menu.choice choice do
@@ -1,5 +1,5 @@
1
1
  module Jira
2
2
 
3
- VERSION = "0.0.9"
3
+ VERSION = "0.1.0"
4
4
 
5
5
  end
data/lib/jira/core.rb CHANGED
@@ -42,14 +42,20 @@ module Jira
42
42
 
43
43
  #
44
44
  # Determines whether or not the input ticket matches the expected JIRA
45
- # ticketing syntax.
45
+ # ticketing syntax. Outputs a warning that the input ticket isn't a valid
46
+ # ticket.
46
47
  #
47
48
  # @param ticket [String] input ticket name
49
+ # @param verbose [Boolean] verbose output of the ticket warning
48
50
  #
49
51
  # @return [Boolean] whether input string matches JIRA ticket syntax
50
52
  #
51
- def ticket?(ticket)
52
- !!ticket.to_s[/^[a-zA-Z]+-[0-9]+$/]
53
+ def ticket?(ticket, verbose=true)
54
+ !!ticket.to_s[/^[a-zA-Z]+-[0-9]+$/] and return true
55
+ if verbose
56
+ puts "#{Jira::Format.ticket(ticket)} is not a valid JIRA ticket."
57
+ end
58
+ return false
53
59
  end
54
60
 
55
61
  ### Relevant Paths
@@ -73,10 +79,7 @@ module Jira
73
79
  #
74
80
  def root_path
75
81
  return @root_path if !@root_path.nil?
76
- if !system('git rev-parse 2> /dev/null')
77
- puts "JIRA commands can only be run within a git repository."
78
- abort
79
- end
82
+ raise GitException.new if !system('git rev-parse 2> /dev/null')
80
83
  @root_path ||= `git rev-parse --show-toplevel`.strip
81
84
  end
82
85
 
@@ -89,7 +92,7 @@ module Jira
89
92
  # @return [String] JIRA password
90
93
  #
91
94
  def auth
92
- self.read(self.auth_path).split(':')
95
+ @auth ||= self.read(self.auth_path).split(':')
93
96
  end
94
97
 
95
98
  ### Core Actions
@@ -99,6 +102,7 @@ module Jira
99
102
  #
100
103
  def discard_memoized
101
104
  @url = nil
105
+ @auth = nil
102
106
  @username = nil
103
107
  @password = nil
104
108
  end
@@ -121,10 +125,7 @@ module Jira
121
125
  # @param path [String] path to validate
122
126
  #
123
127
  def validate_path!(path)
124
- if !File.exists?(path)
125
- say "Please run `jira install` before running this command."
126
- abort
127
- end
128
+ raise InstallationException.new if !File.exists?(path)
128
129
  end
129
130
 
130
131
  end
@@ -0,0 +1,2 @@
1
+ class InstallationException < Exception; end
2
+ class GitException < Exception; end
data/lib/jira/mixins.rb CHANGED
@@ -31,4 +31,8 @@ class String
31
31
  JSON.parse(self) rescue {}
32
32
  end
33
33
 
34
+ def periodize
35
+ self.strip[-1] == "." ? self : self + "."
36
+ end
37
+
34
38
  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.9
4
+ version: 0.1.0
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 00:00:00.000000000 Z
11
+ date: 2013-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -63,6 +63,7 @@ files:
63
63
  - lib/jira/api.rb
64
64
  - lib/jira/commands/browse.rb
65
65
  - lib/jira/commands/comment.rb
66
+ - lib/jira/commands/commit.rb
66
67
  - lib/jira/commands/describe.rb
67
68
  - lib/jira/commands/install.rb
68
69
  - lib/jira/commands/log.rb
@@ -72,6 +73,7 @@ files:
72
73
  - lib/jira/commands/version.rb
73
74
  - lib/jira/constants.rb
74
75
  - lib/jira/core.rb
76
+ - lib/jira/exceptions.rb
75
77
  - lib/jira/format.rb
76
78
  - lib/jira/mixins.rb
77
79
  - lib/jira.rb