Skip to content

Instantly share code, notes, and snippets.

@mbijon
Forked from anonymous/pivotal_export.php
Created May 25, 2011 23:37
Show Gist options
  • Save mbijon/992242 to your computer and use it in GitHub Desktop.
Save mbijon/992242 to your computer and use it in GitHub Desktop.
Expose Mantis bugs for PivotalTracker-import
<?php
/*
Mantis -> PivotalTracker export script
Based on scripts from this support thread:
- http://community.pivotaltracker.com/pivotal/topics/synchronize_pivotal_tracker_with_mantis
To configure:
1.) Put this script in your Mantis root folder (one that contains 'core.php')
2.) Create an "Other" integration in Pivotal
3.) In the integration set a Mantis user/pass that has read rights on the project
(script doesn't alert if user doesn't have read access)
4.) Set a base URL like: http://{Mantis domain}/view.php?id=
5.) Set a import API URL like: http://{Mantis domain}/pivotal_export.php?project={project_id from Mantis}
6.) Save the integration & use it from the "More" menu in Pivotal
*/
require_once( 'core.php' );
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) header('WWW-Authenticate: Basic realm="Please enter username and password:"');
else if (auth_attempt_script_login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
auth_ensure_user_authenticated();
if (!$_GET['project']) die("missing parameters");
$t_core_path = config_get( 'core_path' );
require_once( $t_core_path . 'filter_api.php' );
require_once( $t_core_path . 'csv_api.php' );
helper_begin_long_process();
$t_page_number = 1;
$t_per_page = -1;
$t_bug_count = null;
$t_page_count = null;
# Custom filter "80" hides both completed and resolved statuses. Remove array & set null to show resolved items
$t_custom_filter = array('hide_status' => 80);
$t_project_id = $_GET['project'];
# Get bug rows according to the current filter
$t_rows = filter_get_bug_rows( $t_page_number, $t_per_page, $t_page_count, $t_bug_count, $t_custom_filter, $t_project_id);
if ( $t_rows === false ) {
# Hides both completed and resolved statuses. To hide only completed status: 'view_all_set.php?type=0'
print_header_redirect( 'view_all_set.php?type=1&hide_status=80' );
}
# Send headers to browser to activate mime loading
header( 'Content-Type: text/xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<external_stories type=\"array\">\n";
# export the rows
foreach ( $t_rows as $t_row ) {
echo "<external_story>\n";
echo "<external_id>".$t_row->id."</external_id>";
echo "<name><![CDATA[".$t_row->summary."]]></name>";
echo "<description><![CDATA[".$t_row->description."]]></description>";
echo "<requested_by>".csv_format_reporter_id($t_row->reporter_id)."</requested_by>";
echo "<created_at type=\"datetime\">".date("Y/m/d H:i:s", $t_row->date_submitted)." UTC</created_at>";
echo "<story_type>".((get_enum_element('severity',$t_row->severity) == "feature") ? "feature" : "bug")."</story_type>";
#Pivotal story points assigned by following rows, only uncomment ONE
##echo "<estimate type=\"integer\">".(($t_row->eta-($t_row->eta%10))/10)."</estimate>"; // Calculates points, minimum = 1
echo "<estimate type=\"integer\">0</estimate>"; // Gives all bugs 0 points
# END story points
echo "</external_story>";
}
echo "</external_stories>";
} else {
header('WWW-Authenticate: Basic realm="Wrong username or password."',true,401);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment