mosespa 1.2.1 → 1.4.2

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: 7ab9e50e834b09d2a822bbc34ac6cf4ace9f6649
4
- data.tar.gz: 43447a48f053dc9920cef38746e71042ae243932
3
+ metadata.gz: dd0208471aa893e7d2d538489efb87b67017987a
4
+ data.tar.gz: b8eb649271ee7e8be1dd3177119c891625c9ec62
5
5
  SHA512:
6
- metadata.gz: a6da23a9675d6a222ee66f4fdf7aa8e92c2e56bcb1a319195fd7997fd3374d9c9959cf5a5c44a842d8c9b515acae9cb013b5bebb32ce9890c4f7bcec71ed34b4
7
- data.tar.gz: 22d6896338e4b0b8deee5201fc930aee7d7461f0db3e2b5952682d81f03eb6403d5bde09ece0db45305da147086a2aa9a948ac0031be2cbe1ba7cbb646b24479
6
+ metadata.gz: e93f05829781190b5e9af8df9918e9eb42be50c814c3878ac60a612efd64bc7819d41ffae5bc7f3360efab0a8ae6a3ef4a19495e3c387ca7809d730d553b1102
7
+ data.tar.gz: ec1bf09581306fd832f169c4473af9b37539a9d335356943cd4ce56629b7696819948462d99e4b7ab54d5125cc7028b494c0257924d58120ff7e478610330cc7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gemspec
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mosespa (1.4.2)
5
+ colorize
6
+ jira-ruby
7
+ table_print
8
+ trollop
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (3.2.17)
14
+ i18n (~> 0.6, >= 0.6.4)
15
+ multi_json (~> 1.0)
16
+ colorize (0.7.3)
17
+ i18n (0.6.9)
18
+ jira-ruby (0.1.10)
19
+ activesupport
20
+ oauth
21
+ multi_json (1.10.1)
22
+ oauth (0.4.7)
23
+ table_print (1.5.2)
24
+ trollop (2.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ mosespa!
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  mosespa
2
2
  =======
3
3
 
4
+ [![gem version](https://badge.fury.io/rb/mosespa.png)](http://badge.fury.io/rb/mosespa)
5
+ [![dependency status](https://gemnasium.com/kamaradclimber/mosespa.png)](https://gemnasium.com/kamaradclimber/mosespa)
6
+
4
7
  mosespa is very small lib on top of jira-ruby gem to interact with jira on command-line.
5
8
  This uses the REST interface of jira.
6
9
 
@@ -37,7 +40,7 @@ To see more information such as comments : ```mosespa show COOK-2878 --verbose``
37
40
  To add a comment:
38
41
  ```mosespa comment COOK-2878 It does not merge properly can you rebase```
39
42
 
40
- If some characters are nice to bash:
43
+ If some characters aren't nice to bash:
41
44
  ```mosespa comment COOK-2878 "It does not merge properly, could you rebase?"```
42
45
 
43
46
  ### Creating tickets
@@ -58,6 +61,17 @@ To search for any jql:
58
61
 
59
62
  ```mosespa search 'reporter in (currentUser())'```
60
63
 
64
+ If you add search in your config file under named_search section:
65
+
66
+ ```
67
+ named_search:
68
+ mine: assignee = currentUser()
69
+ watched: watcher = currentUser()
70
+ ```
71
+
72
+ you'll be able to search easily with ```mosespa search watched```
73
+
74
+
61
75
  Installation
62
76
  ------------
63
77
 
@@ -20,6 +20,7 @@ global_opts = Trollop::options do
20
20
  opt :login, "Set the username to connectio to jira", :short => '-l', :type => String
21
21
  opt :debug, "Output all possible information"
22
22
  opt :config, "Configuration file location", :short => '-f', :default => default_config
23
+ opt :colorize, "If relevant, add color to output", :short => '-c'
23
24
  stop_on SUB_COMMANDS
24
25
  end
25
26
 
@@ -65,15 +66,17 @@ options = {
65
66
  :site => global_opts[:url] || config['url'],
66
67
  :auth_type => :basic,
67
68
  :context_path => '',
68
- :use_ssl => false
69
+ :use_ssl => config['use_ssl'] || true,
70
+ :ssl_verify_mode => config['ssl_verify_mode'] || OpenSSL::SSL::VERIFY_PEER,
69
71
  }
70
72
 
71
73
 
72
74
  client = JIRA::Client.new(options)
73
75
 
74
76
  $stderr.puts "Main argument is #{main_arg}" if global_opts[:debug]
75
- case main_arg
76
- when /[[:alpha:]]+-[[:digit:]]+/ #ticket
77
+
78
+ case cmd
79
+ when 'show','comment', 'browse'
77
80
  $stderr.puts "Using ticket mode" if global_opts[:debug]
78
81
  begin
79
82
  issue = main_arg
@@ -83,7 +86,7 @@ when /[[:alpha:]]+-[[:digit:]]+/ #ticket
83
86
  $stderr.puts e.inspect if global_opts[:debug]
84
87
  abort("Invalid issue? (use --debug to have more information)")
85
88
  end
86
- when /[[:alpha:]]+$/ #project
89
+ when 'create'
87
90
  $stderr.puts "Using project mode" if global_opts[:debug]
88
91
  begin
89
92
  project_id = main_arg
@@ -92,11 +95,16 @@ when /[[:alpha:]]+$/ #project
92
95
  $stderr.puts e.inspect if global_opts[:debug]
93
96
  abort("Invalid project?(use --debug to have more information")
94
97
  end
95
- else # only search normally
98
+ when 'search'
99
+ s = Mosespa::Search.new(client, config)
96
100
  begin
97
- tickets = client.Issue.jql(search_str)
101
+ tickets = s.search(search_str)
98
102
  rescue JIRA::HTTPError => e
99
103
  $stderr.puts e.inspect if global_opts[:debug]
104
+ $stderr.puts e.code if global_opts[:debug]
105
+ $stderr.puts e.response if global_opts[:debug]
106
+ $stderr.puts e.message if global_opts[:debug]
107
+
100
108
  abort("No result for this search ?")
101
109
  end
102
110
  end
@@ -106,7 +114,7 @@ end
106
114
  m = Mosespa::Mosespa.new
107
115
  case cmd
108
116
  when 'show'
109
- m.show(ticket, global_opts[:debug], cmd_opts[:verbose])
117
+ m.show(ticket, global_opts[:debug], cmd_opts[:verbose], global_opts[:colorize] || config['colorize'])
110
118
  when 'comment'
111
119
  m.comment(ticket, comment)
112
120
  when 'create'
@@ -114,5 +122,5 @@ when 'create'
114
122
  when 'browse'
115
123
  m.browse((options[:site] + '/browse/'+ticket.key))
116
124
  when 'search'
117
- m.search(tickets, global_opts[:debug], cmd_opts[:verbose])
125
+ s.print_search
118
126
  end
@@ -0,0 +1,109 @@
1
+ require 'thread'
2
+ require 'colorize'
3
+ require 'tempfile'
4
+
5
+ module Mosespa
6
+ class Mosespa
7
+ def show(ticket, json, verbose, colorize)
8
+ p = Puts.new(colorize)
9
+ if json
10
+ puts ticket.to_json
11
+ else
12
+ puts "#{ticket.key} (#{ticket.status.name}) #{ticket.summary}"
13
+ if verbose
14
+ puts ticket.summary
15
+ ticket.comments.each do |c|
16
+ p.puts(c.author['name'], c.body)
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ def browse(url)
23
+ `#{ENV['BROWSER']} #{url}`
24
+ end
25
+
26
+ def comment(ticket, comment)
27
+ c = ticket.comments.build
28
+ c.save({'body' => comment})
29
+ end
30
+
31
+ def create(client, project, summary, description)
32
+ file = Tempfile.new('mosespa')
33
+ need_external_editor = summary.nil?
34
+ if need_external_editor
35
+ task_type, summary, description = create_get_options(file, project,'Task' ,summary, description)
36
+ $stderr.puts "Ticket type was: #{task_type}"
37
+ $stderr.puts "Summary was: #{summary}"
38
+ end
39
+ fail "Won't create a ticket without summary" if summary.nil? or summary.empty?
40
+ t = client.Issue.build
41
+ request = {'summary' => summary, 'description' => description, 'project' => {'key' => project.key}, 'issuetype' => {'name'=> task_type || 'Task'} }
42
+ begin
43
+ resp = t.save!({'fields' =>request})
44
+ rescue Exception => e
45
+ $stderr.puts "Error while creating your ticket"
46
+ $stderr.puts "Your ticket information was saved in #{file.path}" if need_external_editor
47
+ raise e
48
+ end
49
+ puts "Created #{t.key}"
50
+ file.unlink
51
+ end
52
+
53
+ def create_get_options(file, project, task_type, summary, description)
54
+ file.write(summary || "Task:")
55
+ file.write("\n")
56
+ file.write("\n")
57
+ file.write(description ||"")
58
+ file.write("\n")
59
+ file.write("# Here you can edit the ticket you want to create\n")
60
+ file.write("# Line starting with a # will be ignored\n")
61
+ file.write("# The format is the same as a git commit\n")
62
+ file.write("\n")
63
+ file.write("# Summary line follows this template : [TaskType]: [Title]\n")
64
+ file.write("# This means that if you write: Story: Create a prototype of SOA\n")
65
+ file.write("# You'll get a new story about creating a SOA prototype")
66
+ file.write("# The summary line is always followed by an empty line and may be followed by a description")
67
+ file.write("\n\n")
68
+ file.write("# /* vim: set filetype=gitcommit : */")
69
+ file.close #need to flush
70
+ file.open
71
+ system "$EDITOR #{file.path}"
72
+ all = file.read.lines.reject {|l| l.start_with? "#"}.map {|l| l.chop}
73
+ summary = all[0]
74
+ m = /^(\w+):(.*)/.match(summary)
75
+ task_type, summary = m.to_a.drop(1) if m
76
+
77
+ description = all.drop(2).join("\n")
78
+ $stderr.puts "Type: #{task_type}"
79
+ $stderr.puts "summary: #{summary}"
80
+ $stderr.puts "description: #{description}"
81
+ file.close
82
+ [task_type, summary, description]
83
+ end
84
+ end
85
+
86
+
87
+ class Puts
88
+ def initialize(colorize)
89
+ @colorize = colorize
90
+ @colors = Hash.new
91
+ @available_colors = Queue.new
92
+ String.colors
93
+ .select{ |c| not [:black, :light_black, :white].include? c}
94
+ .each { |c| @available_colors.push c }
95
+ end
96
+
97
+ def puts(author, text)
98
+ if @colorize
99
+ unless @colors.has_key? author
100
+ a_color = @available_colors.pop
101
+ @colors[author] = a_color
102
+ end
103
+ c = @colors[author]
104
+ author = author.colorize( c )
105
+ end
106
+ $stdout.puts "#{author}: #{text}"
107
+ end
108
+ end
109
+ end
@@ -1,110 +1,2 @@
1
- require 'thread'
2
- require 'colorize'
3
- require 'tempfile'
4
-
5
- module Mosespa
6
- class Mosespa
7
- def show(ticket, json, verbose)
8
- p = Puts.new
9
- if json
10
- puts ticket.to_json
11
- else
12
- puts "#{ticket.key} (#{ticket.status.name}) #{ticket.summary}"
13
- if verbose
14
- puts ticket.summary
15
- ticket.comments.each do |c|
16
- p.puts(c.author['name'], c.body)
17
- end
18
- end
19
- end
20
- end
21
-
22
- def browse(url)
23
- `#{ENV['BROWSER']} #{url}`
24
- end
25
-
26
- def comment(ticket, comment)
27
- c = ticket.comments.build
28
- c.save({'body' => comment})
29
- end
30
-
31
- def search(tickets, json, verbose)
32
- tickets.each { |t| show(t, json, verbose) }
33
- end
34
-
35
- def create(client, project, summary, description)
36
- file = Tempfile.new('mosespa')
37
- need_external_editor = summary.nil?
38
- if need_external_editor
39
- task_type, summary, description = create_get_options(file, project,'Task' ,summary, description)
40
- $stderr.puts "Ticket type was: #{task_type}"
41
- $stderr.puts "Summary was: #{summary}"
42
- end
43
- fail "Won't create a ticket without summary" if summary.nil? or summary.empty?
44
- t = client.Issue.build
45
- request = {'summary' => summary, 'description' => description, 'project' => {'key' => project.key}, 'issuetype' => {'name'=> task_type || 'Task'} }
46
- begin
47
- resp = t.save!({'fields' =>request})
48
- rescue Exception => e
49
- $stderr.puts "Error while creating your ticket"
50
- $stderr.puts "Your ticket information was saved in #{file.path}" if need_external_editor
51
- raise e
52
- end
53
- puts "Created #{t.key}"
54
- file.unlink
55
- end
56
-
57
- def create_get_options(file, project, task_type, summary, description)
58
- file.write(summary || "Task:")
59
- file.write("\n")
60
- file.write("\n")
61
- file.write(description ||"")
62
- file.write("\n")
63
- file.write("# Here you can edit the ticket you want to create\n")
64
- file.write("# Line starting with a # will be ignored\n")
65
- file.write("# The format is the same as a git commit\n")
66
- file.write("\n")
67
- file.write("# Summary line follows this template : [TaskType]: [Title]\n")
68
- file.write("# This means that if you write: Story: Create a prototype of SOA\n")
69
- file.write("# You'll get a new story about creating a SOA prototype")
70
- file.write("# The summary line is always followed by an empty line and may be followed by a description")
71
- file.write("\n\n")
72
- file.write("# /* vim: set filetype=gitcommit : */")
73
- file.close #need to flush
74
- file.open
75
- system "$EDITOR #{file.path}"
76
- all = file.read.lines.reject {|l| l.start_with? "#"}.map {|l| l.chop}
77
- summary = all[0]
78
- m = /^(\w+):(.*)/.match(summary)
79
- task_type, summary = m.to_a.drop(1) if m
80
-
81
- description = all.drop(2).join("\n")
82
- $stderr.puts "Type: #{task_type}"
83
- $stderr.puts "summary: #{summary}"
84
- $stderr.puts "description: #{description}"
85
- file.close
86
- [task_type, summary, description]
87
- end
88
- end
89
-
90
-
91
- class Puts
92
- def initialize()
93
- @colors = Hash.new
94
- @available_colors = Queue.new
95
- String.colors
96
- .select{ |c| not [:black, :light_black, :white].include? c}
97
- .each { |c| @available_colors.push c }
98
- end
99
-
100
- def puts(author, text)
101
- unless @colors.has_key? author
102
- a_color = @available_colors.pop
103
- @colors[author] = a_color
104
- end
105
- c = @colors[author]
106
- author = author.colorize( c )
107
- $stdout.puts "#{author}: #{text}"
108
- end
109
- end
110
- end
1
+ require_relative 'm.rb'
2
+ require_relative 'search.rb'
@@ -0,0 +1,43 @@
1
+ require 'colorize'
2
+ require 'table_print'
3
+
4
+ module Mosespa
5
+ class Search
6
+ def initialize(jira_client, config)
7
+ @client = jira_client
8
+ @named_search = config['named_search'] || {}
9
+ end
10
+
11
+ def search(search_string)
12
+ real_search = @named_search[search_string] || search_string
13
+ @issues = @client.Issue.jql(real_search).sort_by { |i| i.updated }
14
+ end
15
+
16
+ def print_search
17
+ tp @issues,
18
+ "key",
19
+ {:updated => {:formatters => [DateColorFormatter.new]}},
20
+ "status.name",
21
+ "summary"
22
+ end
23
+ end
24
+
25
+ class DateColorFormatter
26
+ def format(value)
27
+ date = Time.parse(value)
28
+ now = Time.now
29
+ two_weeks_ago = now - 14*86400
30
+ one_month_ago = now - 30*86400
31
+
32
+ c = if date > two_weeks_ago
33
+ :green
34
+ else if date > one_month_ago
35
+ :yellow
36
+ else
37
+ :red
38
+ end end
39
+ date.strftime('%D').colorize( c )
40
+ end
41
+ end
42
+
43
+ end
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "mosespa"
6
- s.version = '1.2.1'
6
+ s.version = '1.4.2'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Grégoire Seux"]
9
9
  s.license = "Apache License v2"
@@ -18,4 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.add_dependency "jira-ruby"
19
19
  s.add_dependency 'trollop'
20
20
  s.add_dependency 'colorize'
21
+ s.add_dependency 'table_print'
21
22
  end
metadata CHANGED
@@ -1,55 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mosespa
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grégoire Seux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-03 00:00:00.000000000 Z
11
+ date: 2014-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jira-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: trollop
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: colorize
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: table_print
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  description: ''
@@ -60,12 +74,16 @@ executables:
60
74
  extensions: []
61
75
  extra_rdoc_files: []
62
76
  files:
63
- - .gitignore
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - Gemfile.lock
64
80
  - LICENSE
65
81
  - README.md
66
82
  - bin/completion_mosespa
67
83
  - bin/mosespa
84
+ - lib/m.rb
68
85
  - lib/mosespa.rb
86
+ - lib/search.rb
69
87
  - mosespa.gemspec
70
88
  homepage: http://github.com/kamaradclimber/mosespa
71
89
  licenses:
@@ -77,17 +95,17 @@ require_paths:
77
95
  - lib
78
96
  required_ruby_version: !ruby/object:Gem::Requirement
79
97
  requirements:
80
- - - '>='
98
+ - - ">="
81
99
  - !ruby/object:Gem::Version
82
100
  version: '0'
83
101
  required_rubygems_version: !ruby/object:Gem::Requirement
84
102
  requirements:
85
- - - '>='
103
+ - - ">="
86
104
  - !ruby/object:Gem::Version
87
105
  version: '0'
88
106
  requirements: []
89
107
  rubyforge_project:
90
- rubygems_version: 2.0.3
108
+ rubygems_version: 2.2.2
91
109
  signing_key:
92
110
  specification_version: 4
93
111
  summary: Play on command line with JIRA