bicho 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,4 +4,4 @@ Gemfile.lock
4
4
  pkg/*
5
5
  .yardoc
6
6
  *.rbc
7
-
7
+ *~
data/README.rdoc CHANGED
@@ -31,6 +31,12 @@ Plugins can be written to deal with specific bugzilla installations.
31
31
  puts bug.url
32
32
  end
33
33
 
34
+ You can give more than one bug or a named query, or both:
35
+
36
+ server.get(127043, 432423) => [....]
37
+ server.get("Named list") => [....]
38
+ server.get("Named list", 4423443) => [....]
39
+
34
40
  === ActiveRecord-like API
35
41
 
36
42
  To use the ActiveRecord like interface over the +Bug+ class, you need first
data/bicho.gemspec CHANGED
@@ -7,13 +7,14 @@ Gem::Specification.new do |s|
7
7
  s.version = Bicho::VERSION
8
8
  s.authors = ["Duncan Mac-Vicar P."]
9
9
  s.email = ["dmacvicar@suse.de"]
10
- s.homepage = ""
10
+ s.homepage = "http://github.com/dmacvicar/bicho"
11
11
  s.summary = %q{Library to access bugzilla}
12
12
  s.description = %q{Library to access bugzilla}
13
13
 
14
14
  s.add_dependency("inifile", ["~> 0.4.1"])
15
15
  s.add_dependency("trollop", [">= 1.16"])
16
16
  s.add_dependency("highline", ["~> 1.6.2"])
17
+ s.add_dependency("nokogiri")
17
18
 
18
19
 
19
20
  s.rubyforge_project = "bicho"
data/lib/bicho/bug.rb CHANGED
@@ -71,6 +71,12 @@ module Bicho
71
71
  "##{id} - #{summary} (#{url})"
72
72
  end
73
73
 
74
+ def [] name, subname = nil
75
+ v = @data[name.to_s]
76
+ v = v[subname.to_s] if subname # for 'internals' properties
77
+ v
78
+ end
79
+
74
80
  # URL where the bug can be viewed
75
81
  # Example: http://bugs.foo.com/2345
76
82
  def url
@@ -34,7 +34,7 @@ module Bicho::CLI::Commands
34
34
  def do(global_opts, opts, args)
35
35
  client = ::Bicho::Client.new(global_opts[:bugzilla])
36
36
  client.get_bugs(*args).each do |bug|
37
- t.say("#{t.color(bug.id, :headline)} #{bug.summary}")
37
+ t.say("#{t.color(bug.id.to_s, :headline)} #{bug.summary}")
38
38
  end
39
39
  return 0
40
40
  end
data/lib/bicho/client.rb CHANGED
@@ -25,6 +25,8 @@
25
25
  require 'inifile'
26
26
  require 'uri'
27
27
  require 'xmlrpc/client'
28
+ require 'nokogiri'
29
+ require 'net/https'
28
30
 
29
31
  require 'bicho/bug'
30
32
  require 'bicho/query'
@@ -59,12 +61,13 @@ module Bicho
59
61
 
60
62
  include Bicho::Logging
61
63
 
62
- attr_reader :url
64
+ attr_reader :url, :userid
63
65
 
64
66
  def initialize(url)
65
- url = URI.parse(url) if not url.is_a?(URI)
67
+ # Don't modify the original url
68
+ url = url.is_a?(URI) ? url.clone : URI.parse(url)
66
69
  # save the unmodified (by plugins) url
67
- @url = url.clone
70
+ @original_url = url.clone
68
71
 
69
72
  url.path = '/xmlrpc.cgi'
70
73
 
@@ -85,6 +88,20 @@ module Bicho
85
88
 
86
89
  @client = XMLRPC::Client.new_from_uri(url.to_s, nil, 900)
87
90
  @client.set_debug
91
+
92
+ # User.login sets the credentials cookie for subsequent calls
93
+ if @client.user && @client.password
94
+ ret = @client.call("User.login", { 'login' => @client.user, 'password' => @client.password, 'remember' => 0 } )
95
+ handle_faults(ret)
96
+ @userid = ret['id']
97
+ end
98
+
99
+ # Save modified url
100
+ @url = url
101
+ end
102
+
103
+ def cookie
104
+ @client.cookie
88
105
  end
89
106
 
90
107
  def handle_faults(ret)
@@ -114,10 +131,47 @@ module Bicho
114
131
  bugs
115
132
  end
116
133
 
134
+ # Given a named query's name, runs it
135
+ # on the server
136
+ # @returns [Array<String>] list of bugs
137
+ def expand_named_query(what)
138
+ if not @userid
139
+ raise "You need to be authenticated to use named queries"
140
+ end
141
+
142
+ logger.info("Expanding named query: '#{what}' with '#{cookie}'")
143
+ http = Net::HTTP.new(@url.host, @url.port)
144
+ http.use_ssl = true
145
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
146
+ http.set_debug_output(Bicho::LoggerIODevice.new)
147
+ request = Net::HTTP::Get.new("/buglist.cgi?cmdtype=runnamed&namedcmd=#{what}&ctype=atom", {"Cookie" => self.cookie} )
148
+ response = http.request(request)
149
+ case response
150
+ when Net::HTTPSuccess
151
+ bugs = []
152
+ xml = Nokogiri::XML.parse(response.body)
153
+ xml.root.xpath("//xmlns:entry/xmlns:link/@href", xml.root.namespace).each do |attr|
154
+ uri = URI.parse attr.value
155
+ bugs << uri.query.split("=")[1]
156
+ end
157
+ return bugs
158
+ when Net::HTTPRedirect
159
+ raise "HTTP redirect not supported in named_query"
160
+ else
161
+ raise "Error when expanding named query '#{what}': #{response}"
162
+ end
163
+ end
164
+
117
165
  # Retrieves one or more bugs by id
118
166
  def get_bugs(*ids)
119
167
  params = Hash.new
120
- params[:ids] = ids.collect(&:to_s)
168
+ params[:ids] = ids.collect(&:to_s).map do |what|
169
+ if what =~ /^[0-9]+$/
170
+ next what.to_i
171
+ else
172
+ next expand_named_query(what)
173
+ end
174
+ end.flatten
121
175
 
122
176
  bugs = []
123
177
  ret = @client.call("Bug.get", params)
data/lib/bicho/query.rb CHANGED
@@ -94,7 +94,7 @@ module Bicho
94
94
  if not @query_map.has_key?(param)
95
95
  @query_map[param] = Array.new
96
96
  end
97
- @query_map[param] = value
97
+ @query_map[param] = [@query_map[param], value].flatten
98
98
  end
99
99
 
100
100
  end
data/lib/bicho/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bicho
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.3"
3
3
  end
data/test/test_query.rb CHANGED
@@ -16,5 +16,15 @@ class Query_test < Test::Unit::TestCase
16
16
  assert ret.collect(&:id).include?(645150)
17
17
 
18
18
  end
19
+
20
+ def test_query_addition_of_attributes
21
+ ret = Bicho::Query.new.status("foo").status("bar")
22
+ assert_equal({"status" => ["foo", "bar"]}, ret.query_map)
23
+ end
24
+
25
+ def test_query_shortcuts
26
+ ret = Bicho::Query.new.open
27
+ assert_equal({"status" => [:new, :assigned, :needinfo, :reopened]}, ret.query_map)
28
+ end
19
29
 
20
30
  end
metadata CHANGED
@@ -1,79 +1,68 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: bicho
3
- version: !ruby/object:Gem::Version
4
- hash: 29
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 1
10
- version: 0.0.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Duncan Mac-Vicar P.
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-10 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-12-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: inifile
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &6670620 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 13
29
- segments:
30
- - 0
31
- - 4
32
- - 1
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.4.1
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: trollop
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *6670620
25
+ - !ruby/object:Gem::Dependency
26
+ name: trollop
27
+ requirement: &6670000 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 47
45
- segments:
46
- - 1
47
- - 16
48
- version: "1.16"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '1.16'
49
33
  type: :runtime
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: highline
53
34
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *6670000
36
+ - !ruby/object:Gem::Dependency
37
+ name: highline
38
+ requirement: &6669420 !ruby/object:Gem::Requirement
55
39
  none: false
56
- requirements:
40
+ requirements:
57
41
  - - ~>
58
- - !ruby/object:Gem::Version
59
- hash: 11
60
- segments:
61
- - 1
62
- - 6
63
- - 2
42
+ - !ruby/object:Gem::Version
64
43
  version: 1.6.2
65
44
  type: :runtime
66
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *6669420
47
+ - !ruby/object:Gem::Dependency
48
+ name: nokogiri
49
+ requirement: &6669020 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *6669020
67
58
  description: Library to access bugzilla
68
- email:
59
+ email:
69
60
  - dmacvicar@suse.de
70
- executables:
61
+ executables:
71
62
  - bicho
72
63
  extensions: []
73
-
74
64
  extra_rdoc_files: []
75
-
76
- files:
65
+ files:
77
66
  - .gitignore
78
67
  - Gemfile
79
68
  - MIT-LICENSE
@@ -95,39 +84,31 @@ files:
95
84
  - lib/bicho/version.rb
96
85
  - test/helper.rb
97
86
  - test/test_query.rb
98
- homepage: ""
87
+ homepage: http://github.com/dmacvicar/bicho
99
88
  licenses: []
100
-
101
89
  post_install_message:
102
90
  rdoc_options: []
103
-
104
- require_paths:
91
+ require_paths:
105
92
  - lib
106
- required_ruby_version: !ruby/object:Gem::Requirement
93
+ required_ruby_version: !ruby/object:Gem::Requirement
107
94
  none: false
108
- requirements:
109
- - - ">="
110
- - !ruby/object:Gem::Version
111
- hash: 3
112
- segments:
113
- - 0
114
- version: "0"
115
- required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
100
  none: false
117
- requirements:
118
- - - ">="
119
- - !ruby/object:Gem::Version
120
- hash: 3
121
- segments:
122
- - 0
123
- version: "0"
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
124
105
  requirements: []
125
-
126
106
  rubyforge_project: bicho
127
- rubygems_version: 1.8.6
107
+ rubygems_version: 1.8.11
128
108
  signing_key:
129
109
  specification_version: 3
130
110
  summary: Library to access bugzilla
131
- test_files:
111
+ test_files:
132
112
  - test/helper.rb
133
113
  - test/test_query.rb
114
+ has_rdoc: