Skip to content

Instantly share code, notes, and snippets.

@mojowill
Created June 11, 2017 17:41
Show Gist options
  • Save mojowill/8c1a72898fb930fa6d2b1fda376f62dc to your computer and use it in GitHub Desktop.
Save mojowill/8c1a72898fb930fa6d2b1fda376f62dc to your computer and use it in GitHub Desktop.
Github to Remine
<?php
// Github Details
$github_org = 'organisation'; //Github Organisation Name
$github_repo = 'repository'; //Github Repository Name
$github_user = 'username'; //Github Username
$github_password = 'password'; //Github Password
// Get from Github
$issues_url = "https://$github_user:$github_password@api.github.com/repos/$github_org/$github_repo/issues?state=closed?per_page=100&quot;;
$json = file_get_contents( $issues_url );
$data = json_decode( $json, true );
// Push to Redmine
/* Uses PHP Active Resouce https://github.com/lux/phpactiveresource/wiki */
require_once ( 'ActiveResource.php' );
class Issue extends ActiveResource {
var $site = 'http://username:password@my.redmineurl.com/';
var $request_format = 'xml';
}
foreach ( $data as $row ) {
$subject = $row['title'];
$description = $row['body'];
$issue = new Issue(
array(
'subject' => $subject,
'description' => $description,
'project_id' => 'vt1', // Project ID of Vtesse Website
'assigned_to_id' => 3, //User ID of Will
'status_id' => 5, //Status ID, 5 = CLOSED, 1 = NEW
)
);
$issue->save();
echo $issue->id . ' created successfully<br />';
$issue_id = $issue->id;
// Add comments as updates
if ($row['comments'] > 0 ) {
$commentid = $row['number'];
$comment_url = "https://$github_user:$github_password@api.github.com/repos/$github_org/$github_repo/issues/$commentid/comments";
$json2 = file_get_contents( $comment_url );
$comments = json_decode( $json2, true );
foreach ( $comments as $comment_row ) {
$comment_notes = $comment_row['body'];
$issue->find( $issue_id );
$issue->set( 'notes', $comment_notes )->save();
echo 'Comment added';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment