redminerb 0.2.3 → 0.3.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: 78b4c1082e72394b5aab415a8f9b1e19d93cdbcd
4
- data.tar.gz: 3d2b52e472d8df0671609bcfbea5517cb455a015
3
+ metadata.gz: da909c714880dbb6b5574f5231f23fc6b6746212
4
+ data.tar.gz: a441ec352a81a81fae4b9ba561fedd475984607d
5
5
  SHA512:
6
- metadata.gz: f7c4dd68bc9cc2c16612611ef5b39db474151b1b9de856525d122cebd789c1d7f3b9a4194fd080adea69fa8235ee0f77a9fd6bb3d8ea54a817c9edece6f06028
7
- data.tar.gz: 5c5a92008102dded2da0d9a0ffa202a3819cb808bd93ffe863f0e30e17a2cc63809af1397517a1ddb9543dbc89c95a7effd4d5cc32ceb0003c762b0953b98b5d
6
+ metadata.gz: f1950ab70ede6e2a8614098ea9137a8bb978c4999ca44baa9db5304e190561ff914294fa2aeba7539acc4467744bd0b2b6c1c92ea28b770e2db1a6b0457f96b2
7
+ data.tar.gz: e1676c311102229ef787b6a2c285925d7a2faf9f4959e64d8e9fb496e5910724bc9dfdf77f32d47efde1d3a8e1e01c9045db5413343cce6cb3629d529ceb077b
data/.rubocop.yml CHANGED
@@ -7,3 +7,5 @@ Style/TrailingWhitespace:
7
7
  Enabled: false
8
8
  Style/RedundantReturn:
9
9
  Enabled: false
10
+
11
+ # inherit_from: .rubocop_todo.yml
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.3, released 2015-09-22
2
+
3
+ * 'redminerb issues [show] <number>' to see an issue's info
4
+ * 'redminerb issues list' to see open issues
5
+
1
6
  == 0.2, released 2015-09-17
2
7
 
3
8
  * 'redminerb users create' to create a brand new user!
data/README.md CHANGED
@@ -34,8 +34,9 @@ Or install it yourself as:
34
34
 
35
35
  ## Usage
36
36
 
37
- The URL and the API key needed to access to your Redmine REST API need to be in
38
- in your environment or in the `~/.redminerb.yml`.
37
+ The URL and the API key of your Redmine REST API must be in your environment
38
+ using *REDMINERB_URL* and *REDMINERB_API_KEY*, or in the `~/.redminerb.yml` as values
39
+ of the *url* and *api_key* keys.
39
40
 
40
41
  For example, this `~/.redminerb.yml`:
41
42
 
@@ -47,6 +48,13 @@ Would be the same as having the following in your `.bashrc`:
47
48
  export REDMINERB_URL=http://localhost:3000/
48
49
  export REDMINERB_API_KEY=69b47d74e36a6757bac5d45f8398dd23bfa8f52c
49
50
 
51
+ GET request on a collection ressources give us the results as indicated by the
52
+ [Redmine pagination documentation](http://www.redmine.org/projects/redmine/wiki/Rest_api#Collection-resources-and-pagination). You can use the *--limit (-l)* and *--offset (-o)* options.
53
+
54
+ For example, you can see the third user of your Redmine with:
55
+
56
+ $ redminerb users -o 3 -l 1
57
+
50
58
  ### Configuration (config)
51
59
 
52
60
  To see the current configuration used by Redminerb we have the `config` command:
@@ -55,28 +63,35 @@ To see the current configuration used by Redminerb we have the `config` command:
55
63
  URL: http://localhost:3000/
56
64
  API-KEY: 69b47d74e36a6757bac5d45f8398dd23bfa8f52c
57
65
 
58
- *NOTICE: soon will be possible to specify this values using env. vars and this
59
- command will have more sense.*
60
-
61
66
  ### Users
62
67
 
63
- **IMPORTANT: Be sure that you API key have the right permissions in the server.**
68
+ The **users** command is the wrapper for part of the [Users resource](http://www.redmine.org/projects/redmine/wiki/Rest_Users) of the Redmine REST API.
69
+
70
+ **IMPORTANT: Be sure that your API key's user have the right permissions in the server.**
64
71
 
65
72
  #### List current users
66
73
 
67
- $ redminerb users # a.k.a. redminerb users list
74
+ **List** is the default subcommand of the *users* command:
75
+
76
+ $ redminerb users # i.e. 'redminerb users list'
68
77
 
69
78
  That should give you the current users on your Redmine server, one per line.
70
79
 
71
- By omission it gives you the ID, the login and the e-mail of the user. You can
72
- change that using the --fields option, that let you specify others separated
80
+ You can use the `--name` option to list users as described by the *name* filter of the API resource. The `-q` and `--query` are aliases for this option. For example:
81
+
82
+ $ redminerb users -q red # i.e. 'redminerb users list --name=red'
83
+
84
+ Will show us the users which login, first name, last name or email contains the 'red' word.
85
+
86
+ By omission *users list* gives you the ID, the login and the e-mail of the user. You can
87
+ change that using the *--fields (-f)* option, that let you specify others separated
73
88
  by semicolons. For example:
74
89
 
75
- $ redminerb users list --fields=id:mail
90
+ $ redminerb users -f id:mail
76
91
 
77
- Will return only the ID following by the user e-mail.
92
+ Will return only the ID following by the user's email.
78
93
 
79
- You can see all the available fields with `redminerb users me`.
94
+ You can see **all the fields available** with `redminerb users me`.
80
95
 
81
96
  #### Show our info in the Redmine server
82
97
 
@@ -88,10 +103,43 @@ the API key used to access the Rest API (hopefully your data :).
88
103
 
89
104
  #### Create new user
90
105
 
91
- $ redminerb users create --login "wadus" --password "ultrasecret" \
92
- --firstname="Wadux" --lastname="Wallace" \
106
+ To create a new user we should use the *create* subcommand:
107
+
108
+ $ redminerb users create --login wadus --password="ultrasecret" \
109
+ --firstname="Wadux" --lastname Wallace \
93
110
  --mail "wadus@waduxwallace.out"
94
111
 
112
+ The options have the following aliases (extracted from `redminerb users help create`):
113
+
114
+ l, --login=LOGIN
115
+ p, --password=PASSWORD
116
+ fn, --firstname=FIRSTNAME
117
+ ln, --lastname=LASTNAME
118
+ m, --mail=MAIL
119
+
120
+ So, the previous command is the same as the following:
121
+
122
+ $ redminerb users create -l wadus -p ultrasecret -fn Wadux -ln Wallace \
123
+ -m wadus@waduxwallace.out
124
+
125
+ #### List issues
126
+
127
+ $ redminerb issues list
128
+
129
+ #### Show an issue
130
+
131
+ Shows the info of an issue with a number or id.
132
+
133
+ $ redminerb issues [show] <number>
134
+
135
+ For example, to see the info of the issue #12532 we'd launch:
136
+
137
+ $ redminerb issues show 12539
138
+
139
+ *show* is the default subcommand, so the following order has the same output as the following:
140
+
141
+ $ redminerb issues 12539
142
+
95
143
  ## Development
96
144
 
97
145
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,30 @@
1
+ # Copyright (c) The Cocktail Experience S.L. (2015)
2
+ require 'erb'
3
+ require_relative '../issues'
4
+
5
+ module Redminerb
6
+ module Cli
7
+ # Thor's 'issues' subcommand definition
8
+ class Issues < Thor
9
+ default_command :show
10
+
11
+ desc 'list', 'Shows open issues in our Redmine'
12
+ option :offset, aliases: :o
13
+ option :limit, aliases: :l
14
+ def list
15
+ Redminerb.init!
16
+ Redminerb::Issues.list(options).each do |issue|
17
+ puts "[#{issue.id}] ".blue + issue.subject.green
18
+ end
19
+ end
20
+
21
+ desc 'show <number>', 'Shows the data of the issue which id match with #<number>'
22
+ def show(issue_id)
23
+ Redminerb.init!
24
+ issue = Redminerb::Issues.read(issue_id)
25
+ template = Redminerb::Template.read(:issue)
26
+ puts ERB.new(template).result(binding)
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,35 +1,42 @@
1
1
  # Copyright (c) The Cocktail Experience S.L. (2015)
2
- module Redminerb
3
- # 'users' Thor subcommand definition
4
- class Users < Thor
5
- default_command :list
2
+ require_relative '../users'
6
3
 
7
- desc 'list', 'Shows the current users in our Redmine'
8
- option :fields, banner: 'id:login:email'
9
- def list
10
- Redminerb.init!
11
- fields = options[:fields] || 'id:login:mail'
12
- Redminerb.client.users.each do |user|
13
- puts fields.split(':').map {|f| user.send(f)}.join("\t").green
4
+ module Redminerb
5
+ module Cli
6
+ # 'users' Thor subcommand definition
7
+ class Users < Thor
8
+ default_command :list
9
+
10
+ desc 'list', 'Shows the current users in our Redmine'
11
+ option :fields, aliases: :f, banner: 'id:login:email'
12
+ option :name, aliases: [:q, '--query'], banner: '<FILTER>'
13
+ option :offset, aliases: :o
14
+ option :limit, aliases: :l
15
+ def list
16
+ Redminerb.init!
17
+ fields = options.delete(:fields) || 'id:login:mail'
18
+ Redminerb::Users.list(options).each do |user|
19
+ puts fields.split(':').map {|f| user.send(f)}.join("\t").green
20
+ end
14
21
  end
15
- end
16
-
17
- desc 'create', 'Creates a user.'
18
- option :login, required: true
19
- option :password, required: true
20
- option :firstname, required: true
21
- option :lastname, required: true
22
- option :mail, required: true
23
- def create
24
- Redminerb.init!
25
- puts Redminerb.client.create_user(options).green
26
- end
27
-
28
- desc 'me', 'Shows the info of the owner of the API key'
29
- def me
30
- Redminerb.init!
31
- Redminerb.client.me.each do |field, value|
32
- puts "#{field}: ".blue + value.to_s.green
22
+
23
+ desc 'create', 'Creates a user.'
24
+ option :login, aliases: :l, required: true
25
+ option :password, aliases: :p, required: true
26
+ option :firstname, aliases: :fn, required: true
27
+ option :lastname, aliases: :ln, required: true
28
+ option :mail, aliases: :m, required: true
29
+ def create
30
+ Redminerb.init!
31
+ puts Redminerb::Users.create(options).green
32
+ end
33
+
34
+ desc 'me', 'Shows the info of the owner of the API key'
35
+ def me
36
+ Redminerb.init!
37
+ Redminerb::Users.me.each do |field, value|
38
+ puts "#{field}: ".blue + value.to_s.green
39
+ end
33
40
  end
34
41
  end
35
42
  end
data/lib/redminerb/cli.rb CHANGED
@@ -3,6 +3,7 @@ require 'thor'
3
3
  require 'colorize'
4
4
  require_relative '../redminerb'
5
5
  require_relative 'cli/users'
6
+ require_relative 'cli/issues'
6
7
 
7
8
  module Redminerb
8
9
  # Thor's command class
@@ -19,6 +20,8 @@ module Redminerb
19
20
 
20
21
  # The subcommad's classes are defined in lib/redminerb/cli
21
22
  desc 'users [list]', "Manage Redmine's users"
22
- subcommand 'users', Users
23
+ subcommand 'users', Cli::Users
24
+ desc 'issues [list]', "Manage Redmine's issues"
25
+ subcommand 'issues', Cli::Issues
23
26
  end
24
27
  end
@@ -1,7 +1,6 @@
1
1
  # Copyright (c) The Cocktail Experience S.L. (2015)
2
2
  require 'faraday'
3
3
  require 'json'
4
- require 'ostruct'
5
4
 
6
5
  module Redminerb
7
6
  # HTTP client to communicate w/ the Redmine server.
@@ -17,59 +16,15 @@ module Redminerb
17
16
  @connection.basic_auth(cfg.api_key, cfg.api_key)
18
17
  end
19
18
 
20
- # Get the users of our Redmine as OpenStruct objects.
21
- #
22
- # Example:
23
- # Redminerb.init!
24
- # Redminerb.client.users.each do |user|
25
- # puts user.firstname
26
- # end
27
- #
28
- # See lib/reminerb/cli/user.rb code to see other example/s.
29
-
30
- def users
31
- get_json('/users.json')['users'].map do |user|
32
- OpenStruct.new user
33
- end
34
- end
35
-
36
- # Creates a brand new user with the given params. In lib/reminerb/cli/user.rb
37
- # you can see which ones are required (or running 'redminerb users create'
38
- # from the command line).
39
- #
40
- # Example (missing required params):
41
- # Redminerb.init!
42
- # Redminerb.client.create_user login: 'wadus'
43
-
44
- def create_user(params)
45
- response = post_json('/users.json', user: params)
46
-
47
- if response.success?
48
- 'Created'
49
- else
50
- raise_error! response
51
- end
52
- end
53
-
54
- # Returns a hash with the info of the user's account behind the API key that
55
- # is used by the script to access the Redmine's REST API.
56
- #
57
- # Example (missing required params):
58
- # Redminerb.init!
59
- # me = Redminerb.client.me
60
- # puts me['login'] + ': ' + me['mail']
61
-
62
- def me
63
- get_json('/users/current.json')['user']
64
- end
65
-
66
- private
67
-
68
19
  # Makes a GET request of the given 'path' param and returns the body of the
69
20
  # response parsed as JSON.
70
- def get_json(path)
21
+ def get_json(path, params = {})
71
22
  Redminerb.init_required!
72
- res = @connection.get(path)
23
+ res = @connection.get do |req|
24
+ req.url path
25
+ req.headers['Content-Type'] = 'application/json'
26
+ req.body = params.to_json if params.any?
27
+ end
73
28
  JSON.parse(res.body)
74
29
  rescue JSON::ParserError => e
75
30
  raise e, "HTTP status code #{res.status}"
@@ -77,6 +32,7 @@ module Redminerb
77
32
 
78
33
  # Makes a POST request to 'path' with 'params' in JSON format.
79
34
  def post_json(path, params)
35
+ Redminerb.init_required!
80
36
  @connection.post do |req|
81
37
  req.url path
82
38
  req.headers['Content-Type'] = 'application/json'
@@ -85,7 +41,7 @@ module Redminerb
85
41
  end
86
42
 
87
43
  # It raises an exception giving the validation messages for 422 responses
88
- def raise_error!(res)
44
+ def self.raise_error!(res)
89
45
  if res.status == 422
90
46
  begin
91
47
  errors = JSON.parse(res.body)['errors']
@@ -0,0 +1,35 @@
1
+ # Copyright (c) The Cocktail Experience S.L. (2015)
2
+ require 'ostruct'
3
+
4
+ module Redminerb
5
+ # Issues resource wrapper
6
+ class Issues
7
+ class << self
8
+ # Get Redmine's issues as OpenStruct objects.
9
+ #
10
+ # Example:
11
+ # Redminerb.init!
12
+ # Redminerb::Issues.list.each do |issue|
13
+ # puts "#{issue.id}: #{issue.subject}"
14
+ # end
15
+ #
16
+
17
+ def list(params)
18
+ Redminerb.client.get_json('/issues.json', params)['issues'].map do |issue|
19
+ OpenStruct.new issue
20
+ end
21
+ end
22
+
23
+ # Get an issue's info as an OpenStruct object.
24
+ #
25
+ # Example:
26
+ # Redminerb.init!
27
+ # issue = Redminerb::Issues.read(34)
28
+ # puts "#{issue.id}: #{issue.subject}"
29
+ #
30
+ def read(id)
31
+ OpenStruct.new Redminerb.client.get_json("/issues/#{id}.json")['issue']
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ # Copyright (c) The Cocktail Experience S.L. (2015)
2
+ require 'ostruct'
3
+
4
+ module Redminerb
5
+ # Class to read Redminerb's ERB templates
6
+ class Template
7
+ class << self
8
+ # Returns the content of the given ERB file in the templates directory.
9
+ #
10
+ # Example:
11
+ # Redminerb::Template.read(:issue) # Returns the content of templates/issue.erb
12
+ #
13
+
14
+ def read(name)
15
+ File.read(filepath(name))
16
+ end
17
+
18
+ private
19
+
20
+ def filepath(name)
21
+ File.join(File.dirname(__FILE__)[0..-15], 'templates', "#{name}.erb")
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,55 @@
1
+ # Copyright (c) The Cocktail Experience S.L. (2015)
2
+ require 'ostruct'
3
+
4
+ module Redminerb
5
+ # Users resource wrapper
6
+ class Users
7
+ class << self
8
+ # Get the users of our Redmine as OpenStruct objects.
9
+ #
10
+ # Example:
11
+ # Redminerb.init!
12
+ # Redminerb::Users.list.each do |user|
13
+ # puts user.firstname
14
+ # end
15
+ #
16
+ # See lib/reminerb/cli/user.rb code to see other example/s.
17
+
18
+ def list(params)
19
+ Redminerb.client.get_json('/users.json', params)['users'].map do |user|
20
+ OpenStruct.new user
21
+ end
22
+ end
23
+
24
+ # Creates a brand new user with the given params. In lib/reminerb/cli/user.rb
25
+ # you can see which ones are required (or running 'redminerb users create'
26
+ # from the command line).
27
+ #
28
+ # Example (that will miss required params :_(:
29
+ # Redminerb.init!
30
+ # Redminerb::Users.create login: 'wadus'
31
+
32
+ def create(params)
33
+ response = Redminerb.client.post_json('/users.json', user: params)
34
+
35
+ if response.success?
36
+ 'Created'
37
+ else
38
+ Redminerb::Client.raise_error! response
39
+ end
40
+ end
41
+
42
+ # Returns a hash with the info of the user's account behind the API key that
43
+ # is used by the script to access the Redmine's REST API.
44
+ #
45
+ # Example:
46
+ # Redminerb.init!
47
+ # me = Redminerb::Users.me
48
+ # puts me['login'] + ': ' + me['mail']
49
+
50
+ def me
51
+ Redminerb.client.get_json('/users/current.json')['user']
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,4 +1,4 @@
1
1
  # Copyright (c) The Cocktail Experience S.L. (2015)
2
2
  module Redminerb
3
- VERSION = '0.2.3'
3
+ VERSION = '0.3.0'
4
4
  end
data/lib/redminerb.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  # Copyright (c) The Cocktail Experience S.L. (2015)
2
+ require 'terminfo'
2
3
  require_relative 'redminerb/version'
3
4
  require_relative 'redminerb/config'
4
5
  require_relative 'redminerb/client'
5
6
  require_relative 'redminerb/cli'
7
+ require_relative 'redminerb/template'
6
8
 
7
9
  # Main module
8
10
  module Redminerb
@@ -46,4 +48,8 @@ module Redminerb
46
48
  def client
47
49
  @client
48
50
  end
51
+
52
+ def separator
53
+ @separator ||= ('-' * TermInfo.screen_columns).green
54
+ end
49
55
  end
data/redminerb.gemspec CHANGED
@@ -33,6 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency 'thor'
34
34
  spec.add_dependency 'colorize'
35
35
  spec.add_dependency 'faraday'
36
+ spec.add_dependency 'ruby-terminfo'
36
37
 
37
38
  spec.add_development_dependency 'bundler', '~> 1.10'
38
39
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -0,0 +1,12 @@
1
+ <%= Redminerb.separator %>
2
+ <%= "[#{issue.tracker['name']}]".blue + "[#{issue.project['name']}:##{issue.id}]".green %> <%= issue.subject %>
3
+ <%= Redminerb.separator %>
4
+ Author: <%= issue.author['name'].red %>
5
+ Assigned to: <%= issue.assigned_to['name'].red %>
6
+ Status: <%= issue.status['name'].red %>
7
+ Priority: <%= issue.priority['name'].red %>
8
+ <%= Redminerb.separator %>
9
+ <%= issue.description %>
10
+ <%= Redminerb.separator %>
11
+ <%= Redminerb.config.url + "issues/#{issue.id}" %>
12
+ <%= Redminerb.separator %>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redminerb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Garcia Samblas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-18 00:00:00.000000000 Z
11
+ date: 2015-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-terminfo
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
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: bundler
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -160,11 +174,16 @@ files:
160
174
  - exe/redminerb
161
175
  - lib/redminerb.rb
162
176
  - lib/redminerb/cli.rb
177
+ - lib/redminerb/cli/issues.rb
163
178
  - lib/redminerb/cli/users.rb
164
179
  - lib/redminerb/client.rb
165
180
  - lib/redminerb/config.rb
181
+ - lib/redminerb/issues.rb
182
+ - lib/redminerb/template.rb
183
+ - lib/redminerb/users.rb
166
184
  - lib/redminerb/version.rb
167
185
  - redminerb.gemspec
186
+ - templates/issue.erb
168
187
  homepage: http://github.com/nando/redminerb
169
188
  licenses: []
170
189
  metadata: {}