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)
request(path, method='GET', headers=None, **kwargs)[source]

Perform a HTTP request.

Given a relative Bugzilla URL path, an optional request method, and arguments suitable for requests.Request(), perform a HTTP request.

class bugsy.BugsyException(msg, error_code=None)[source]

If while interacting with Bugzilla and we try do something that is not supported this error will be raised.

class bugsy.LoginException(msg, error_code=None)[source]

If a username and password are passed in but we don’t receive a token then this error will be raised.

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]
get_comments()[source]

Obtain comments for this bug.

Returns a list of Comment instances.

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"
to_dict()[source]

Return the raw dict that is used inside this object

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"
class bugsy.BugException(msg, error_code=None)[source]

If we try do something that is not allowed to a bug then this error is raised

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(tags)[source]

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.

author

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”).

remove_tags(tags)[source]

Add tags to the comments

tags

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.

Indices and tables