Welcome to Bugsy!¶
Bugsy is a tool that allows you to programmatically work with Bugzilla using its native REST API.
To use you will do
import bugsy
bugzilla = bugsy.Bugsy()
bug = bugzilla.get(123456)
bug123456.status = 'RESOLVED'
bug123456.resolution = 'FIXED'
bugzilla.put(bug123456)
Installing Bugsy¶
To install Bugsy, simply run this simple command in your terminal of choice
Pip
pip install bugsy
If you don’t have pip installed then do
easy_install
easy_install pip
pip install bugsy
Bugsy is actively developed on GitHub, where the code is always available.
You can either clone the public repository:
$ git clone git://github.com/AutomatedTester/bugsy.git
Or, download the tarball:
Once you have a copy of the source, you can embed it in your own Python package, or install it into your site-packages easily:
Using Bugsy¶
Getting a bug from Bugzilla¶
Getting a bug is quite simple. Create a Bugsy object and then get the bug number that you want.
import bugsy
bugzilla = bugsy.Bugsy()
bug = bugzilla.get(123456)
Creating a new bug¶
To create a new bug, create a Bug object, populate it with the items that you need and then use the Bugsy object to put the bug into Bugzilla
import bugsy
bug = bugsy.Bug()
bug.summary = "I really realy love cheese"
bug.add_comment("and I really want sausages with it!")
bugzilla = bugsy.Bugsy("username", "password")
bugzilla.put(bug)
bug.id #returns the bug id from Bugzilla
Searching Bugzilla¶
To search for bugs you will need to create a Bugsy
object and then you can call
search_for and chain the search. The Search
API is a Fluent API
- you just chain the items that you need and then call search when the search is complete.
import bugsy
bugzilla = bugsy.Bugsy()
bugs = bugzilla.search_for\
.keywords("checkin-needed")\
.include_fields("flags")\
.search()
More details can be found in from the Search
class
Comments¶
Getting comments from a bug
import bugsy
bugzilla = bugsy.Bugsy()
bug = bugzilla.get(123456)
comments = bug.get_comments()
comments[0].text # Returns "I <3 Sausages"
Adding comments to a bug
import bugsy
bugzilla = bugsy.Bugsy()
bug = bugzilla.get(123456)
bug.add_comment("And I love bacon too!")
To see further details look at:
Bugsy
¶
-
class
bugsy.
Bugsy
(username=None, password=None, userid=None, cookie=None, api_key=None, bugzilla_url='https://bugzilla.mozilla.org/rest')[source]¶ Bugsy allows easy getting and putting of Bugzilla bugs
-
__init__
(username=None, password=None, userid=None, cookie=None, api_key=None, bugzilla_url='https://bugzilla.mozilla.org/rest')[source]¶ Initialises a new instance of Bugsy
Parameters: - username – Username to login with. Defaults to None
- password – Password to login with. Defaults to None
- userid – User ID to login with. Defaults to None
- cookie – Cookie to login with. Defaults to None
- apikey – API key to use. Defaults to None.
- bugzilla_url – URL endpoint to interact with. Defaults to
https://bugzilla.mozilla.org/rest
If a api_key is passed in, Bugsy will use this for authenticating requests. While not required to perform requests, if a username is passed in along with api_key, we will validate that the api key is valid for this username. Otherwise the api key is blindly used later.
If a username AND password are passed in Bugsy will try get a login token from Bugzilla. If we can’t login then a LoginException will be raised.
If a userid AND cookie are passed in Bugsy will create a login token from them. If no username was passed in it will then try to get the username from Bugzilla.
-
__weakref__
¶ list of weak references to the object (if defined)
-
authenticated
¶ True if this instance is authenticated against the server.
>>> bugzilla = Bugsy() >>> assert not bugzilla.authenticated
-
get
(bug_number)[source]¶ Get a bug from Bugzilla. If there is a login token created during object initialisation it will be part of the query string passed to Bugzilla
Parameters: bug_number – Bug Number that will be searched. If found will return a Bug object. >>> bugzilla = Bugsy() >>> bug = bugzilla.get(123456)
-
put
(bug)[source]¶ This method allows you to create or update a bug on Bugzilla. You will have had to pass in a valid username and password to the object initialisation and recieved back a token.
Parameters: bug – A Bug object either created by hand or by using get() If there is no valid token then a BugsyException will be raised. If the object passed in is not a Bug then a BugsyException will be raised.
>>> bugzilla = Bugsy() >>> bug = bugzilla.get(123456) >>> bug.summary = "I like cheese and sausages" >>> bugzilla.put(bug)
-
Bug
¶
-
class
bugsy.
Bug
(bugsy=None, **kwargs)[source]¶ This represents a Bugzilla Bug
-
OS
¶ Property for getting or setting the OS that the bug occured on
>>> bug.OS "All"
-
__init__
(bugsy=None, **kwargs)[source]¶ Defaults are set if there are no kwargs passed in. To pass in a dict create the Bug object like the following
Parameters: bugsy – Bugsy instance to use to connect to Bugzilla. >>> bug = Bug(**myDict)
-
__weakref__
¶ list of weak references to the object (if defined)
-
add_comment
(comment)[source]¶ Adds a comment to a bug. If the bug object does not have a bug ID (ie you are creating a bug) then you will need to also call put on the
Bugsy
class.>>> bug.add_comment("I like sausages") >>> bugzilla.put(bug)
If it does have a bug id then this will immediately post to the server
>>> bug.add_comment("I like eggs too")
More examples can be found at: https://github.com/AutomatedTester/Bugsy/blob/master/example/add_comments.py
-
assigned_to
¶ Property for getting the bug assignee
>>> bug.assigned_to "automatedtester@mozilla.com"
-
blocks
¶ Property to get the bug numbers that block on the current bug. It returns multiple bug numbers in a list.
>>> bug.blocks [123456, 678901]
-
cc
¶ Property to get the cc list for the bug. It returns emails for people
>>> bug.cc [u'dburns@mozilla.com', u'automatedtester@mozilla.com']
-
component
¶ Property for getting the bug component
>>> bug.component General
-
depends_on
¶ Property to get the bug numbers that depend on the current bug. It returns multiple bug numbers in a list.
>>> bug.depends_on [123456, 678901]
-
id
¶ Property for getting the ID of a bug.
>>> bug.id 123456
-
keywords
¶ Property to get the keywords list for the bug. It returns multiple keywords in a list.
>>> bug.keywords [u"ateam-marionette-runner", u"regression"]
-
platform
¶ Property for getting the bug platform
>>> bug.platform "ARM"
-
product
¶ Property for getting the bug product
>>> bug.product Core
-
resolution
¶ Property for getting or setting the bug resolution
>>> bug.resolution "FIXED"
-
status
¶ Property for getting or setting the bug status
>>> bug.status "REOPENED"
-
summary
¶ Property for getting and setting the bug summary
>>> bug.summary "I like cheese"
-
update
()[source]¶ Update this object with the latest changes from Bugzilla
>>> bug.status 'NEW' #Changes happen on Bugzilla >>> bug.update() >>> bug.status 'FIXED'
-
version
¶ Property for getting the bug platform
>>> bug.version "TRUNK"
-
Comment
¶
Changed in version 0.3.
-
class
bugsy.
Comment
(bugsy=None, **kwargs)[source]¶ Represents a single Bugzilla comment.
To get comments you need to do the following
>>> bugs = bugzilla.search_for.keywords("checkin-needed").search() >>> comments = bugs[0].get_comments() >>> # Returns the comment 0 of the first checkin-needed bug >>> comments[0].text
Add tags to the comments
-
attachment_id
¶ If the comment was made on an attachment, return the ID of that attachment. Otherwise it will return None.
Return the login name of the comment’s author.
-
bug_id
¶ Return the ID of the bug that this comment is on.
-
creation_time
¶ Return the time (in Bugzilla’s timezone) that the comment was added.
-
creator
¶ Return the login name of the comment’s author.
-
id
¶ Return the comment id that is associated with Bugzilla.
-
is_private
¶ Return True if this comment is private (only visible to a certain group called the “insidergroup”).
Add tags to the comments
Return a set of comment tags currently set for the comment.
-
text
¶ Return the text that is in this comment
>>> comment.text # David really likes cheese apparently
-
time
¶ This is exactly same as
creation_time
.For compatibility, time is still usable. However, please note that time may be deprecated and removed in a future release.
Prefer
creation_time
instead.
Search
¶
Changed in version 0.2.
-
class
bugsy.
Search
(bugsy)[source]¶ This allows searching for bugs in Bugzilla
-
__init__
(bugsy)[source]¶ Initialises the search object
Parameters: bugsy – Bugsy instance to use to connect to Bugzilla.
-
__weakref__
¶ list of weak references to the object (if defined)
-
assigned_to
(*args)[source]¶ When search() is called it will search for bugs assigned to these users
Parameters: args – items passed in will be turned into a list Returns: Search
>>> bugzilla.search_for.assigned_to("dburns@mozilla.com")
-
bug_number
(bug_numbers)[source]¶ When you want to search for a bugs and be able to change the fields returned.
Parameters: bug_numbers – A string for the bug number or a list of strings Returns: Search
>>> bugzilla.search_for.bug_number(['123123', '123456'])
-
component
(*components)[source]¶ When search() is called it will limit results to items in a component.
Parameters: component – items passed in will be turned into a list Returns: Search
-
include_fields
(*args)[source]¶ Include fields is the fields that you want to be returned when searching. These are in addition to the fields that are always included below.
Parameters: args – items passed in will be turned into a list Returns: Search
>>> bugzilla.search_for.include_fields("flags")
- The following fields are always included in search:
- ‘version’, ‘id’, ‘summary’, ‘status’, ‘op_sys’, ‘resolution’, ‘product’, ‘component’, ‘platform’
-
keywords
(*args)[source]¶ When search() is called it will search for the keywords passed in here
Parameters: args – items passed in will be turned into a list Returns: Search
>>> bugzilla.search_for.keywords("checkin-needed")
-
product
(*products)[source]¶ When search is called, it will limit the results to items in a Product.
Parameters: product – items passed in will be turned into a list Returns: Search
-
search
()[source]¶ Call the Bugzilla endpoint that will do the search. It will take the information used in other methods on the Search object and build up the query string. If no bugs are found then an empty list is returned.
>>> bugs = bugzilla.search_for\ ... .keywords("checkin-needed")\ ... .include_fields("flags")\ ... .search()
-
summary
(*args)[source]¶ When search is called it will search for bugs with the words passed into the methods
Parameters: args – items passed in will be turned into a list Returns: Search
>>> bugzilla.search_for.summary("663399")
-