Created
June 11, 2017 17:41
-
-
Save mojowill/8c1a72898fb930fa6d2b1fda376f62dc to your computer and use it in GitHub Desktop.
Github to Remine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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:[email protected]/repos/$github_org/$github_repo/issues?state=closed?per_page=100"; | |
$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:[email protected]/'; | |
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:[email protected]/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