Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added markup translation for code-blocks, problematic non-ascii

characters, % signs
  • Loading branch information...
commit 5e6894fdca33f50a239774d61f4e21dab9b44951 1 parent ff401bc
@lukaseder lukaseder authored
Showing with 19 additions and 5 deletions.
  1. +19 −5 trac2github.php
View
24 trac2github.php
@@ -106,9 +106,11 @@
if (empty($row['owner']) || !isset($users_list[$row['owner']])) {
$row['owner'] = $username;
}
+
+ // There is a strange issue with summaries containing percent signs...
$resp = github_add_issue(array(
- 'title' => $row['summary'],
- 'body' => empty($row['description']) ? 'None' : $row['description'],
+ 'title' => preg_replace("/%/", '[pct]', $row['summary']),
+ 'body' => empty($row['description']) ? 'None' : translate_markup($row['description']),
'assignee' => isset($users_list[$row['owner']]) ? $users_list[$row['owner']] : $row['owner'],
'milestone' => $milestones[crc32($row['milestone'])]
));
@@ -119,8 +121,8 @@
if ($row['status'] == 'closed') {
// Close the issue
$resp = github_update_issue($resp['number'], array(
- 'title' => $row['summary'],
- 'body' => empty($row['description']) ? 'None' : $row['description'],
+ 'title' => preg_replace("/%/", '[pct]', $row['summary']),
+ 'body' => empty($row['description']) ? 'None' : translate_markup($row['description']),
'assignee' => isset($users_list[$row['owner']]) ? $users_list[$row['owner']] : $row['owner'],
'milestone' => $milestones[crc32($row['milestone'])],
'state' => 'closed'
@@ -146,7 +148,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']], translate_markup($text));
if (isset($resp['url'])) {
// OK
echo "Added comment {$resp['url']}\n";
@@ -201,4 +203,16 @@ function github_update_issue($issue, $data) {
return json_decode(github_post("/repos/$project/$repo/issues/$issue", json_encode($data), true), true);
}
+function translate_markup($data) {
+ // Replace code blocks with an associated language
+ $data = preg_replace('/\{\{\{(\s*#!(\w+))?/m', '```$2', $data);
+ $data = preg_replace('/\}\}\}/', '```', $data);
+
+ // Avoid non-ASCII characters, as that will cause trouble with json_encode()
+ $data = preg_replace('/[^(\x00-\x7F)]*/','', $data);
+
+ // Possibly translate other markup as well?
+ return $data;
+}
+
?>
Please sign in to comment.
Something went wrong with that request. Please try again.