Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/razzeee/trac2github
Browse files Browse the repository at this point in the history
  • Loading branch information
razzeee committed Oct 18, 2016
2 parents c4b77db + c084c42 commit ce23846
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions trac2github.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// All users must be valid github logins!
$users_list = array(
'TracUsermame' => 'GithubUsername',
'TracUsername' => 'GithubUsername',
'Trustmaster' => 'trustmaster',
'John.Done' => 'johndoe'
);
Expand Down Expand Up @@ -119,9 +119,6 @@
// Set PDO to throw exceptions on error.
$trac_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Boolean used to divide times by 1000000 when using Postgres where times are stored in microsecs (bigint)
$time_in_us=($pdo_driver == 'pgsql' || $pdo_driver == 'sqlite');

echo "Connected to Trac\n";

//if restriction to certain components is added, put this in the SQL string
Expand All @@ -144,7 +141,7 @@
continue;
}
//$milestones[$row['name']] = ++$mnum;
$epochInSecs = (int) ($row['due']/($time_in_us? 1000000:1));
$epochInSecs = (int) ($row['due']/1000000);
echo "due : ".date('Y-m-d\TH:i:s\Z', $epochInSecs)."\n";
$resp = github_add_milestone(array(
'title' => $row['name'],
Expand Down Expand Up @@ -198,7 +195,7 @@
$existing_labels[] = urldecode($l['name']);
}
foreach ($res->fetchAll() as $row) {
$label_name = $row['label_type'] . ': ' . $row['name'];
$label_name = $row['label_type'] . ': ' . str_replace(",", "", $row['name']);
if (array_key_exists($label_name, $remap_labels)) {
$label_name = $remap_labels[$label_name];
}
Expand Down Expand Up @@ -290,7 +287,7 @@
}

$body = make_body($row['description']);
$timestamp = date("j M Y H:i e", $row['time']/($time_in_us? 1000000:1));
$timestamp = date("j M Y H:i e", $row['time']/1000000);
$body = '**Reported by ' . obfuscate_email($row['reporter']) . ' on ' . $timestamp . "**\n" . $body;

if (empty($row['milestone'])) {
Expand Down Expand Up @@ -359,15 +356,15 @@ function trac_orig_value($ticket, $field) {
}

function add_changes_for_ticket($ticket, $ticketLabels) {
global $trac_db, $tickets, $labels, $users_list, $milestones, $skip_comments, $time_in_us, $verbose;
global $trac_db, $tickets, $labels, $users_list, $milestones, $skip_comments, $verbose;
$res = $trac_db->query("SELECT ticket_change.* FROM ticket_change, ticket WHERE ticket.id = ticket_change.ticket AND ticket = $ticket ORDER BY ticket, time, field <> 'comment'");
foreach ($res->fetchAll() as $row) {
if ($verbose) print_r($row);
if (!isset($tickets[$row['ticket']])) {
echo "Skipping comment " . $row['time'] . " on unknown ticket " . $row['ticket'] . "\n";
continue;
}
$timestamp = date("j M Y H:i e", $row['time']/($time_in_us? 1000000:1));
$timestamp = date("j M Y H:i e", $row['time']/1000000);
if ($row['field'] == 'comment') {
if ($row['newvalue'] != '') {
$text = '**Comment by ' . $row['author'] . ' on ' . $timestamp . "**\n" . $row['newvalue'];
Expand Down Expand Up @@ -395,7 +392,7 @@ function add_changes_for_ticket($ticket, $ticketLabels) {
));
} else if (false and $row['field'] == 'description') { // TODO?
$body = make_body($row['newvalue']);
$timestamp = date("j M Y H:i e", $row['time']/($time_in_us? 1000000:1));
$timestamp = date("j M Y H:i e", $row['time']/1000000);
// TODO:
//$body = '**Reported by ' . obfuscate_email($row['reporter']) . ' on ' . $timestamp . "**\n" . $body;

Expand Down Expand Up @@ -506,7 +503,7 @@ function github_get_milestones() {
function github_get_labels() {
global $project, $repo, $verbose;
if ($verbose) print_r($body);
return json_decode(github_req("/repos/$project/$repo/labels?per_page=100", false, false, false), true);
return array_merge(json_decode(github_req("/repos/$project/$repo/labels?per_page=100", false, false, false), true), json_decode(github_req("/repos/$project/$repo/labels?page=2&per_page=100", false, false, false), true));
}

function make_body($description) {
Expand Down

0 comments on commit ce23846

Please sign in to comment.