redmine-cli 0.1.5 → 0.1.6

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
  SHA512:
3
- metadata.gz: 896bdb7a8315493240aca6a624484c570f731c57d7f0791d68ee82e077618cd7e17347846b16362e85342de403647837cee7a6eed2d1b0c62a4c7be40e2b0a5c
4
- data.tar.gz: 5ebeb7bcba54ea0382a817a5879638e7e8becc8d8f8b56eee17fa4a8e74e1f99f1415d0f369b1ae40e6847025e577ffbbc7cddd8d0c39b757e2abada5ebc7641
3
+ metadata.gz: 4715cd84be2f4f9adfe2b9a598221eee36cdf4ef16414006319902bf79eb25c6e6a52fbe9a213d098803036567c0c49afa3e3fe2ea11c448d9b31a2de63f36f5
4
+ data.tar.gz: 7a03c0dd6effd5b996e82defbc26aa414894caf227e61d846dc364e695dd1852def7cb06f1daaec287e2acd65247d386058a4baea0e73d7bfc79b75d018410c9
5
5
  SHA1:
6
- metadata.gz: c40b6d47be90c4baae7ef1582f0d8b9a4d296a1e
7
- data.tar.gz: cfcea000850f572b241e52b8852f1d6121782e14
6
+ metadata.gz: 4ca6c9816ff3f2553537df71a283c5f41572bfaa
7
+ data.tar.gz: 347e907bd37c2cd28c97d9abfa0e7dbc7e94e3d6
@@ -4,6 +4,7 @@ require 'redmine-cli/config'
4
4
  require 'redmine-cli/resources'
5
5
  require 'redmine-cli/generators/install'
6
6
  require 'rubygems'
7
+ require 'ruby-debug'
7
8
  require 'interactive_editor'
8
9
  require 'yaml'
9
10
  require 'pp'
@@ -43,39 +44,51 @@ module Redmine
43
44
  collection.sort! {|i,j| i.priority.id <=> j.priority.id }
44
45
 
45
46
  # Retrieve the list of issue fields in selected_fields
46
- issues = collection.collect { |issue| selected_fields.collect {| key |
47
+ issues = collection.collect { |issue|
48
+ selected_fields.collect {|key|
47
49
 
48
- assignee = ""
49
- assignee = issue.assigned_to.name if issue.respond_to?(:assigned_to)
50
- version = issue.fixed_version.name if issue.respond_to?(:fixed_version)
50
+ assignee = ""
51
+ assignee = issue.assigned_to.name if issue.respond_to?(:assigned_to)
52
+ version = issue.fixed_version.name if issue.respond_to?(:fixed_version)
53
+
54
+ # Hack, because I don't feel like spending much time on this
55
+ if options.version
56
+ next unless version == options.version
57
+ end
51
58
 
52
- # Hack, because I don't feel like spending much time on this
53
- next unless version == options.version
59
+ # This section tries to fill in the field using various methods. First, we try to reference it as a built-in field for which we have a title, ref, and display method.
60
+ # If we don't have that, then we try to reference it as an attribute of the issue object.
61
+ # If at any point we try to reference something that gives us an IndexError, we assume that that is not a native field, and we try to look through the custom fields to find it.
62
+ # Finally, if that fails, we let the value simply be "".
63
+ #
64
+ val = ""
65
+
66
+ begin
67
+ # If this is a built-in field for which we have a title, ref, and display method, use that.
68
+ field = fields.fetch(key)
69
+ if field.display
70
+ value = issue.attributes.fetch(field.ref)
71
+ val = field.display.call(value)
72
+ else
73
+ f = fields.fetch(key).ref
74
+ val = issue.attributes.fetch(f)
75
+ end
76
+ rescue IndexError
77
+ # Otherwise, let's look for a custom field by that name.
78
+ if issue.attributes[:custom_fields].present?
79
+ issue.attributes[:custom_fields].collect { | field |
80
+ if field.attributes.fetch("name") == key
81
+ val = field.attributes.fetch("value")
82
+ end
83
+ }
84
+ end
85
+ ""
54
86
 
55
- begin
56
- # If this is a built-in field for which we have a title, ref, and display method, use that.
57
- field = fields.fetch(key)
58
- if field.display
59
- value = issue.attributes.fetch(field.ref)
60
- field.display.call(value)
61
- else
62
- f = fields.fetch(key).ref
63
- issue.attributes.fetch(f)
64
- end
65
- rescue IndexError
66
- # Otherwise, let's look for a custom field by that name.
67
- if issue.attributes[:custom_fields].present?
68
- issue.attributes[:custom_fields].collect { | field |
69
- if field.attributes.fetch("name") == key
70
- field.attributes.fetch("value")
71
- end
72
- }
73
87
  end
74
- ""
75
- #TODO: If the custom field doesn't exist, then we end up returning a blank value (not an error). I guess that's OK?
76
- end
77
88
 
78
- }}
89
+ val
90
+ }
91
+ }
79
92
 
80
93
  if issues.any?
81
94
  issues.insert(0, selected_fields.collect {| key |
@@ -3,13 +3,16 @@ require 'yaml'
3
3
 
4
4
  module Redmine
5
5
  module Cli
6
+ class NoConfigFileError < StandardError
7
+ end
8
+
6
9
  class << self
7
10
 
8
11
  def config
9
12
  begin
10
13
  generic_conf '.redmine'
11
14
  rescue Errno::ENOENT
12
- puts "You need to create the file .redmine in your home with your username, password and url"
15
+ raise NoConfigFileError
13
16
  exit 1
14
17
  end
15
18
  end
@@ -7,38 +7,42 @@ require 'pp'
7
7
  module Redmine
8
8
  module Cli
9
9
  class BaseResource < ActiveResource::Base
10
- self.site = Redmine::Cli::config.url
11
- self.user = Redmine::Cli::config.username
12
- self.password = Redmine::Cli::config.password
13
-
14
- class << self
15
- # HACK: Redmine API isn't ActiveResource-friendly out of the box, so
16
- # we need to pass nometa=1 to all requests since we don't care about
17
- # the metadata that gets passed back in the top level attributes.
18
- def find(*arguments)
19
- arguments[1] = arguments[1] || {}
20
- arguments[1][:params] = arguments[1][:params] || {}
21
- arguments[1][:params][:nometa] = 1
22
-
23
- super
24
- end
25
-
26
- def fetch_all(params = {})
27
- limit = 100
28
- offset = 0
29
-
30
- resources = []
31
-
32
- while((fetched_resources = self.all(:params => params.merge({:limit => limit, :offset => offset}))).any?)
33
- resources += fetched_resources
34
- offset += limit
35
- if fetched_resources.length < limit then
36
- break
10
+ begin
11
+ self.site = Redmine::Cli::config.url
12
+ self.user = Redmine::Cli::config.username
13
+ self.password = Redmine::Cli::config.password
14
+
15
+ class << self
16
+ # HACK: Redmine API isn't ActiveResource-friendly out of the box, so
17
+ # we need to pass nometa=1 to all requests since we don't care about
18
+ # the metadata that gets passed back in the top level attributes.
19
+ def find(*arguments)
20
+ arguments[1] = arguments[1] || {}
21
+ arguments[1][:params] = arguments[1][:params] || {}
22
+ arguments[1][:params][:nometa] = 1
23
+
24
+ super
25
+ end
26
+
27
+ def fetch_all(params = {})
28
+ limit = 100
29
+ offset = 0
30
+
31
+ resources = []
32
+
33
+ while((fetched_resources = self.all(:params => params.merge({:limit => limit, :offset => offset}))).any?)
34
+ resources += fetched_resources
35
+ offset += limit
36
+ if fetched_resources.length < limit then
37
+ break
38
+ end
37
39
  end
40
+
41
+ resources
38
42
  end
39
-
40
- resources
41
43
  end
44
+ rescue NoConfigFileError
45
+ puts "Warning: No .redmine file was found in your home directory. Use \"redmine install\" to create one."
42
46
  end
43
47
  end
44
48
 
@@ -1,5 +1,5 @@
1
1
  module Redmine
2
2
  module Cli
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redmine-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Dias
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2015-04-08 00:00:00 Z
12
+ date: 2015-04-27 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activeresource