Class: RubyBugzilla
- Inherits:
-
Object
- Object
- RubyBugzilla
- Defined in:
- lib/ruby_bugzilla.rb,
lib/ruby_bugzilla/version.rb
Constant Summary collapse
- CMD =
`which bugzilla`.chomp
- COOKIES_FILE =
File.('~/.bugzillacookies')
- VERSION =
"0.4.2"
Instance Attribute Summary collapse
-
#bugzilla_request_uri ⇒ Object
readonly
Returns the value of attribute bugzilla_request_uri.
-
#bugzilla_uri ⇒ Object
Returns the value of attribute bugzilla_uri.
-
#last_command ⇒ Object
Returns the value of attribute last_command.
-
#password ⇒ Object
Returns the value of attribute password.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_login! ⇒ Object
-
#initialize(bugzilla_uri, username, password) ⇒ RubyBugzilla
constructor
A new instance of RubyBugzilla.
- #inspect ⇒ Object
- #installed? ⇒ Boolean
- #logged_in? ⇒ Boolean
- #login ⇒ Object
-
#modify(bug_ids, options) ⇒ String
Modify an existing bug or set of bugs.
-
#query(options) ⇒ String
Query for existing bugs.
Constructor Details
#initialize(bugzilla_uri, username, password) ⇒ RubyBugzilla
Returns a new instance of RubyBugzilla.
27 28 29 30 31 32 33 34 |
# File 'lib/ruby_bugzilla.rb', line 27 def initialize(bugzilla_uri, username, password) raise "python-bugzilla not installed" unless installed? raise ArgumentError, "username and password must be set" if username.nil? || password.nil? self.bugzilla_uri = bugzilla_uri self.username = username self.password = password end |
Instance Attribute Details
#bugzilla_request_uri ⇒ Object (readonly)
Returns the value of attribute bugzilla_request_uri.
20 21 22 |
# File 'lib/ruby_bugzilla.rb', line 20 def bugzilla_request_uri @bugzilla_request_uri end |
#bugzilla_uri ⇒ Object
Returns the value of attribute bugzilla_uri.
19 20 21 |
# File 'lib/ruby_bugzilla.rb', line 19 def bugzilla_uri @bugzilla_uri end |
#last_command ⇒ Object
Returns the value of attribute last_command.
19 20 21 |
# File 'lib/ruby_bugzilla.rb', line 19 def last_command @last_command end |
#password ⇒ Object
Returns the value of attribute password.
19 20 21 |
# File 'lib/ruby_bugzilla.rb', line 19 def password @password end |
#username ⇒ Object
Returns the value of attribute username.
19 20 21 |
# File 'lib/ruby_bugzilla.rb', line 19 def username @username end |
Class Method Details
.clear_login! ⇒ Object
15 16 17 |
# File 'lib/ruby_bugzilla.rb', line 15 def self.clear_login! File.delete(COOKIES_FILE) if File.exists?(COOKIES_FILE) end |
.installed? ⇒ Boolean
7 8 9 |
# File 'lib/ruby_bugzilla.rb', line 7 def self.installed? File.exists?(CMD) end |
.logged_in? ⇒ Boolean
11 12 13 |
# File 'lib/ruby_bugzilla.rb', line 11 def self.logged_in? File.exists?(COOKIES_FILE) end |
Instance Method Details
#clear_login! ⇒ Object
48 49 50 |
# File 'lib/ruby_bugzilla.rb', line 48 def clear_login! self.class.clear_login! end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/ruby_bugzilla.rb', line 36 def inspect super.gsub(/@password=\".+?\", /, "") end |
#installed? ⇒ Boolean
40 41 42 |
# File 'lib/ruby_bugzilla.rb', line 40 def installed? self.class.installed? end |
#logged_in? ⇒ Boolean
44 45 46 |
# File 'lib/ruby_bugzilla.rb', line 44 def logged_in? self.class.logged_in? end |
#login ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ruby_bugzilla.rb', line 52 def login if logged_in? self.last_command = nil return "Already Logged In" end params = {} params["--debug"] = nil params["login"] = [username, password] begin execute(params) rescue clear_login! # A failed login attempt could result in a corrupt COOKIES_FILE raise end end |
#modify(bug_ids, options) ⇒ String
Modify an existing bug or set of bugs
Examples:
# Set the status of multiple bugs to RELEASE_PENDING
bz.modify([948970, 948971], :status => "RELEASE_PENDING")
# Add a comment
bz.modify("948972", :comment => "whatevs")
# Set the status to POST and add a comment
bz.modify(948970, :status => "POST", :comment => "Fixed in shabla")
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ruby_bugzilla.rb', line 117 def modify(bug_ids, ) bug_ids = Array(bug_ids) raise ArgumentError, "bug_ids and options must be specified" if bug_ids.empty? || .empty? raise ArgumentError, "bug_ids must be numeric" unless bug_ids.all? {|id| id.to_s =~ /^\d+$/ } params = {} params["modify"] = bug_ids (params, ) execute(params) end |
#query(options) ⇒ String
Query for existing bugs
Example:
# Query for all NEW bugs, and return the output in a specific format.
puts bz.query(
:bug_status => "NEW",
:outputformat => "BZ_ID: %{id} STATUS: %{bug_status} SUMMARY: %{summary}"
)
# BZ_ID: 1234 STATUS: NEW SUMMARY: Something went wrong.
# BZ_ID: 1235 STATUS: NEW SUMMARY: Another thing went wrong.
89 90 91 92 93 94 95 96 97 |
# File 'lib/ruby_bugzilla.rb', line 89 def query() raise ArgumentError, "options must be specified" if .empty? params = {} params["query"] = nil (params, ) execute(params) end |