Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Revert to a one-file version

  • Loading branch information...
commit 503123e8389021823e4fa2ecd9acaa75dc3f8017 1 parent 33271f1
@trustmaster authored
View
3  bin/generate_revision_map.sh
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-git svn log --oneline --show-commit | sed -r "s/^r([0-9]+) +\| +([a-f0-9]+) +\|.*$/\1 \2/g"
View
4 bin/get_svn_user_list.sh
@@ -1,4 +0,0 @@
-#!/bin/sh
-
-svn log | grep -E "^r[0-9]+ \| " | awk '{print $3}' | sort | uniq
-
View
17 config.php.sample
@@ -1,17 +0,0 @@
-<?php
-
-/**
- * Sample configuration file, copy this to config.php and edit
- */
-
-$github = new Github(
- $username = 'username',
- $password = 'password',
- $repo = 'user/reponame');
-
-Trac::init(
- $host = 'localhost',
- $db = 'trac',
- $user = 'Trac MySQL user',
- $password = 'Trac MySQL password');
-
View
5 credentials.php
@@ -1,5 +0,0 @@
-<?php
-
-$username = 'Put your github username here';
-$password = 'Put your github password here';
-
View
7 git_users.php
@@ -1,7 +0,0 @@
-<?php
-
-class GitUsers {
- public static function fromTrac($tracUser) {
- return "danielbeardsley";
- }
-}
View
59 github.php
@@ -1,59 +0,0 @@
-<?php
-class Github {
- public $repo;
-
- private $username;
- private $password;
-
- public function __construct($username, $password, $repo) {
- $this->username = $username;
- $this->password = $password;
- $this->repo = $repo;
- }
-
- public function post($url, $json, $patch = false) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_USERPWD, "$this->username:$this->password");
- curl_setopt($ch, CURLOPT_URL, "https://api.github.com$url");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
- if ($patch) {
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
- }
- $ret = curl_exec($ch);
- if(!$ret) {
- trigger_error(curl_error($ch));
- }
-
- if (($code = curl_getinfo($ch, CURLINFO_HTTP_CODE)) && ($code < 200 || $code > 299)) {
- fwrite(STDERR, "Unsuccessful API Request:\n". $ret);
- }
-
- curl_close($ch);
- return $ret;
- }
-
- public function add_milestone($data) {
- return json_decode($this->post("/repos/$this->repo/milestones",
- json_encode($data)), true);
- }
-
- public function add_issue($data) {
- return json_decode($this->post("/repos/$this->repo/issues",
- json_encode($data)), true);
- }
-
- public function add_comment($issue, $body) {
- return json_decode($this->post("/repos/$this->repo/issues/$issue/comments",
- json_encode(array('body' => $body))), true);
- }
-
- public function update_issue($issue, $data) {
- return json_decode($this->post("/repos/$this->repo/issues/$issue",
- json_encode($data), true), true);
- }
-}
-
View
71 labels.php
@@ -1,71 +0,0 @@
-<?php
-
-/**
- * Generates a list of unique labels and adds them to github
- */
-class Labels {
- private static $columnNames = array(
- 'component',
- 'resolution',
- 'priority',
- 'component'
- );
-
- public static function createIfMissing() {
- $labels = array();
- foreach(self::$columnNames as $column) {
- $labels = array_merge($labels,
- self::getLabelsForColumn($column));
- }
-
- foreach ($labels as $label) {
-
- }
- }
-
- private static function getUniques($column) {
- $q_unique = "SELECT DISTINCT `$column` FROM tickets;";
- return Trac::query($q_unique);
- }
-
- private static function getLabelsForColumn($columnName) {
- $values = self::getUniques($columnName);
- foreach($values as $value) {
- $labels[] = call_user_func(array('LabelTransformer', $columnName), $value);
- }
- return $labels;
- }
-}
-
-/**
- * Provides functions to transform Trac fields into Gitub Issue Labels
- */
-class LabelTransformer {
- public static function component($component) {
- return array(
- 'name' => "C-" . $component,
- 'color' => "#ddddd"
- );
- }
-
- public static function priority($priority) {
- return array(
- 'name' => "P-" . $priority,
- 'color' => "#ddddd"
- );
- }
-
- public static function resolution($resolution) {
- return array(
- 'name' => "C-" . $resolution,
- 'color' => "#ddddd"
- );
- }
-
- public static function type($type) {
- return array(
- 'name' => "C-" . $type,
- 'color' => "#ddddd"
- );
- }
-}
View
7 milestones.php
@@ -1,7 +0,0 @@
-<?php
-
-class Milestones {
- public static function gitId($tracMilestone) {
- return null;//"danielbeardsley";
- }
-}
View
61 ticket.php
@@ -1,61 +0,0 @@
-<?php
-require("git_users.php");
-require("milestones.php");
-
-class Ticket {
- public static $github;
-
- private $id;
- private $attr;
-
- public static function loadFromTrac($id) {
- $q_select = "SELECT * FROM `ticket` WHERE `id` = $id";
- $result = Trac::queryRow($q_select);
- return $result ? new self($result) : null;
- }
-
- public function __construct($dbAttributes) {
- $this->attr = $dbAttributes;
- $this->id = $this->attr['id'];
- }
-
- public function toIssueJson() {
- $json = array(
- 'title' => $this->attr['summary'],
- 'body' => $this->translateDescription(),
- 'assignee' => GitUsers::fromTrac($this->attr['owner']) ?: $this->attr['owner'],
- 'milestone' => Milestones::gitId($this->attr['milestone']),
- 'labels' => $this->getLabels()
- );
-
- return $json;
- }
-
- public function saveToGithub() {
- self::$github->add_issue($this->toIssueJson());
- if ($this->attr['status'] == 'closed') {
- self::$github->update_issue($this->id, array('state' => 'closed'));
- }
- }
-
- private function translateDescription() {
- // more on this later
- $desc = $this->attr['description'];
- $desc = str_replace("\r\n", "\n", $desc);
- return $dec;
- }
-
- private function getLabels() {
- $labels = array();
- if ($comp = $this->attr['component'])
- $labels[] = "C-{$comp}";
- if ($resolution = $this->attr['resolution'])
- $labels[] = "R-{$resolution}";
- if (($status = $this->attr['status']) && $status != 'closed' && $status != 'assigned')
- $labels[] = $status;
- if ($priority = $this->attr['priority'])
- $labels[] = "P-{$priority}";
-
- return $labels;
- }
-}
View
25 trac.php
@@ -1,25 +0,0 @@
-<?php
-
-class Trac {
- private static $db;
-
- public static function init($host, $dbname, $user, $password) {
- self::$db = new PDO(
- 'mysql:host='.$host.
- ';dbname='.$dbname,
- $user,
- $password);
- }
-
- public static function query($statement) {
- $resultSet = self::$db->query($statement);
-
- return $resultSet->fetchAll();
- }
-
- public static function queryRow($statement) {
- $resultSet = self::$db->query($statement);
-
- return $resultSet->fetch();
- }
-}
View
104 trac2github.php
@@ -1,16 +1,61 @@
<?php
+/**
+ * @package trac2github
+ * @version 1.0.1
+ * @author Vladimir Sibirov
+ * @copyright (c) Vladimir Sibirov 2011
+ * @license BSD
+ */
-require("github.php");
-require("trac.php");
-require("ticket.php");
-require("config.php");
+// Edit configuration below
+$username = 'Put your github username here';
+$password = 'Put your github password here';
+$project = 'Organization or User name';
+$repo = 'Repository name';
+
+// All users must be valid github logins!
+$users_list = array(
+ 'TracUsermame' => 'GithubUsername',
+ 'Trustmaster' => 'trustmaster',
+ 'John.Done' => 'johndoe'
+);
+
+$mysqlhost_trac = 'Trac MySQL host';
+$mysqluser_trac = 'Trac MySQL user';
+$mysqlpassword_trac = 'Trac MySQL password';
+$mysqldb_trac = 'Trac MySQL database name';
+
+// Do not convert milestones at this run
+$skip_milestones = false;
+
+// Do not convert tickets
+$skip_tickets = false;
+$ticket_offset = 0; // Start at this offset if limit > 0
+$ticket_limit = 0; // Max tickets per run if > 0
+
+// Do not convert comments
+$skip_comments = true;
+$comments_offset = 0; // Start at this offset if limit > 0
+$comments_limit = 0; // Max comments per run if > 0
+
+// Paths to milestone/ticket cache if you run it multiple times with skip/offset
+$save_milestones = '/tmp/trac_milestones.list';
+$save_tickets = '/tmp/trac_tickets.list';
+
+// Uncomment to refresh cache
+// @unlink($save_milestones);
+// @unlink($save_tickets);
+
+// DO NOT EDIT BELOW
error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors', 1);
set_time_limit(0);
-$github = new Github($username, $password);
+$trac_db = new PDO('mysql:host='.$mysqlhost_trac.';dbname='.$mysqldb_trac, $mysqluser_trac, $mysqlpassword_trac);
+
+echo 'Connected to Trac';
$milestones = array();
if (file_exists($save_milestones)) {
@@ -23,7 +68,7 @@
$mnum = 1;
foreach ($res->fetchAll() as $row) {
//$milestones[$row['name']] = ++$mnum;
- $resp = $github->add_milestone(array(
+ $resp = github_add_milestone(array(
'title' => $row['name'],
'state' => $row['completed'] == 0 ? 'open' : 'closed',
'description' => empty($row['description']) ? 'None' : $row['description'],
@@ -60,7 +105,7 @@
if (empty($row['owner']) || !isset($users_list[$row['owner']])) {
$row['owner'] = $username;
}
- $resp = $github->add_issue(array(
+ $resp = github_add_issue(array(
'title' => $row['summary'],
'body' => empty($row['description']) ? 'None' : $row['description'],
'assignee' => isset($users_list[$row['owner']]) ? $users_list[$row['owner']] : $row['owner'],
@@ -72,7 +117,7 @@
echo "Ticket #{$row['id']} converted to issue #{$resp['number']}\n";
if ($row['status'] == 'closed') {
// Close the issue
- $resp = $github->update_issue($resp['number'], array(
+ $resp = github_update_issue($resp['number'], array(
'title' => $row['summary'],
'body' => empty($row['description']) ? 'None' : $row['description'],
'assignee' => isset($users_list[$row['owner']]) ? $users_list[$row['owner']] : $row['owner'],
@@ -100,7 +145,7 @@
$res = $trac_db->query("SELECT * FROM `ticket_change` where `field` = 'comment' AND `newvalue` != '' ORDER BY `ticket`, `time` $limit");
foreach ($res->fetchAll() as $row) {
$text = strtolower($row['author']) == strtolower($username) ? $row['newvalue'] : '**Author: ' . $row['author'] . "**\n" . $row['newvalue'];
- $resp = $github->add_comment($tickets[$row['ticket']], $text);
+ $resp = github_add_comment($tickets[$row['ticket']], $text);
if (isset($resp['url'])) {
// OK
echo "Added comment {$resp['url']}\n";
@@ -114,4 +159,45 @@
echo "Done whatever possible, sorry if not.\n";
+function github_post($url, $json, $patch = false) {
+ global $username, $password;
+ $ch = curl_init();
+ curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
+ curl_setopt($ch, CURLOPT_URL, "https://api.github.com$url");
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+ curl_setopt($ch, CURLOPT_HEADER, false);
+ curl_setopt($ch, CURLOPT_POST, true);
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
+ if ($patch) {
+ curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
+ }
+ $ret = curl_exec($ch);
+ if(!$ret) {
+ trigger_error(curl_error($ch));
+ }
+ curl_close($ch);
+ return $ret;
+}
+
+function github_add_milestone($data) {
+ global $project, $repo;
+ return json_decode(github_post("/repos/$project/$repo/milestones", json_encode($data)), true);
+}
+
+function github_add_issue($data) {
+ global $project, $repo;
+ return json_decode(github_post("/repos/$project/$repo/issues", json_encode($data)), true);
+}
+
+function github_add_comment($issue, $body) {
+ global $project, $repo;
+ return json_decode(github_post("/repos/$project/$repo/issues/$issue/comments", json_encode(array('body' => $body))), true);
+}
+
+function github_update_issue($issue, $data) {
+ global $project, $repo;
+ return json_decode(github_post("/repos/$project/$repo/issues/$issue", json_encode($data), true), true);
+}
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.