Skip to content

ArthurD/PHP-FogBugz-API-Wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHP FogBugz API Wrapper / Helper

This set of scripts and helper methods was written for my own use in getting several tasks accomplished.

We made use of the FogBugz API in order to do two things:

Move our existing LightHouse App tickets into FogBugz as new Cases (see bonus LightHouse API section below)
Create a custom GitHub Hook script that allows us to modify the ticket using our commit messages

Requirements, Dependencies, & Use

Requirements & Dependencies

In order to use these scripts you’ll need PHP5+ that has been built with support for CURL & SimpleXML. The curl.php script is simply a helper class that I commonly use to issue curl commands and that I’ve included with these scripts…

Use

You may freely use or modify the code as you see fit for any purpose. If you make useful additions or modifications that may benefit others I’d definitely like to get them into the repo, just let me know! If you have any questions I’ll try to help but no promises! The code is distributed as-is, use at your own risk!

The ‘fogbugz-api.php’ Class

This class is the meat of the scripts, all interaction with FogBugz is contained here. Below are the methods that are available to use with brief descriptions of each. Also, see the ‘create-new-case.php’ file for examples. To instantiate a new FogBugz connection with the class, you would call it like so.

$fogbugz = new FogBugz($your_fogbugz_api_url, $your_fogbugz_username, $your_fogbugz_password);

This will open a new connection to FogBugz via their API and log you in so that you can begin using the API to issue commands. Upon session termination the class destructor will be called which will also call the logout() method in order to log your session out of the FogBugz API.

createCase() – Create a new FogBugz Case

$fogbugz->createCase($title, $project, $area, $category, $priority_id, $body, $assignedTo_id = false);

$title, $project, $area, $category, $body must all be provided as STRINGS (no HTML allowed even in $body)!

$priority_id and (optional) $assignedTo_id must be provided as INTEGERS! When present, $assignedTo_id will be used to automatically assign the new Case to the specified user on creation.

addCaseReply() – Add a Reply to a FogBugz Case

$fogbugz->addCaseReply($case_id, $body, $as_user_id = null);

This is the same as resolveCase(), the only difference being that the status of the case remains unchanged and only an edit is applied.

triggerCommit() – Attach a Commit to a FogBugz Case

$fogbugz->triggerCommit($case_id, $payload);

Adds a commit to the given $case_id. The $payload should be an array with the following key/value pairs:

$payload[‘sFile’] = ‘filename_of_edited_file’;
$payload[‘sPrev’] = ‘Old_ChangeSet_ID’;
$payload[‘sNew’] = ‘New_ChangeSet_ID’;

resolveCase() – Resolves a FogBugz Case

$fogbugz->resolveCase($case_id, $body=null, $resolved_as_id = null);

If you supply a $body, that text will be entered in to the reply that marks the case as ‘Resolved’.

If you supply a $resolved_as_id, the user ID that you provide will be the user that marks the FogBugz case as resolved (MUST be using an FogBugz Admin login for this to work!)

getCases() – Fetch FogBugz Cases

I didn’t end up really using this method for our work, so it’s largely un-tested. Check the code for more info.

Custom GitHub Hook (github-custom-hook.php)

Make the required settings changes, upload this file to a server, and then add a custom hook URL within the GitHub admin panel that points to it. When properly setup you can attach any commit to a Case by using a commit message like this:

git commit -m "Adds feature X as requested.  [#122]"

This would tag the commit to the Case #122. You can also use a commit message to mark a Case as resolved using the following command:

git commit -m "Adds feature Y as requested. [#122 resolved]"

With minor modifications you can easily add or modify the functionality and the the syntax of the commands.

About

A very rough and dirty "Wrapper" / Implementation of the FogBugz API written in PHP.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages