Skip to content
Snippets Groups Projects
Commit 326a852e authored by Thomas Hackl's avatar Thomas Hackl
Browse files

updated dependencies

parent 62ce0160
No related branches found
No related tags found
No related merge requests found
......@@ -15,10 +15,14 @@
"php": ">=5.3.0",
"ext-mbstring": "*",
"ext-json": "*",
"m4tthumphrey/php-gitlab-api": "9.9.0",
"fguillot/json-rpc": "1.0.0",
"ulrichsg/getopt-php": "2.3.0"
"ulrichsg/getopt-php": "2.3.0",
"php-http/guzzle6-adapter": "^1.1"
},
"autoload": {
"psr-4": {"Trac2GitLab\\": "src/"}
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
This diff is collapsed.
......@@ -7,10 +7,12 @@ use Trac2GitLab\Migration;
use Ulrichsg\Getopt\Getopt;
use Ulrichsg\Getopt\Option;
define('GITLAB_PRIVATE_TOKEN', 'zBCqafqiWotFzaPYinQu');
$getopt = new Getopt(array(
array('t', 'trac', Getopt::REQUIRED_ARGUMENT, 'Trac URL'),
array('g', 'gitlab', Getopt::REQUIRED_ARGUMENT, 'GitLab URL'),
array('k', 'token', Getopt::REQUIRED_ARGUMENT, 'GitLab API private token'),
array('k', 'token', Getopt::OPTIONAL_ARGUMENT, 'GitLab API private token'),
array('p', 'project', Getopt::REQUIRED_ARGUMENT, 'GitLab project to which the tickets should be migrated'),
// Both are optional, but at least must be present:
......@@ -34,7 +36,7 @@ try {
}
// Validate the parameters
validateRequired($getopt, array('trac', 'gitlab', 'token', 'project'));
validateRequired($getopt, array('trac', 'gitlab', 'project'));
if (is_null($getopt->getOption('component')) && is_null($getopt->getOption('query'))) {
throw new UnexpectedValueException("At least one of 'component' or 'query' must have a value");
}
......@@ -53,7 +55,7 @@ try {
}
// Actually migrate
$migration = new Migration($getopt->getOption('gitlab'), $getopt->getOption('token'), $getopt->getOption('admin'), $getopt->getOption('trac'), $getopt->getOption('link'), $userMapping);
$migration = new Migration($getopt->getOption('gitlab'), $getopt->getOption('token') ?: GITLAB_PRIVATE_TOKEN, $getopt->getOption('admin'), $getopt->getOption('trac'), $getopt->getOption('link'), $userMapping);
// If we have a component, migrate it
if (!is_null($getopt->getOption('component'))) {
$issue_mapping = $migration->migrateComponent($getopt->getOption('component'), $getopt->getOption('project'));
......
......@@ -7,6 +7,7 @@ define('USER_FETCH_MAX_PAGES', 50);
use Gitlab\Client;
use Gitlab\Model\Issue;
use Gitlab\HttpClient\Builder;
/**
* GitLab communicator class
......@@ -28,7 +29,7 @@ class GitLab
*/
public function __construct($url, $token, $isAdmin) {
$this->url = $url;
$this->client = new Client($url . "/api/v3/");
$this->client = Client::create($url . '/api/v4/');
$this->client->authenticate($token, Client::AUTH_URL_TOKEN);
$this->isAdmin = $isAdmin;
}
......@@ -110,7 +111,25 @@ class GitLab
return $note;
}
public function createAttachment($projectId, $file) {
/**
* Attaches a file to an issue.
*
* @param mixed $projectId numerical ID or path to target project
* @param int $issueId the issue to add the file to
* @param string $file base64 representation of file, we'll see if that works.
* @param int $authorId the file author
*/
public function createIssueAttachment($projectId, $issueId, $file, $authorId) {
try {
// First, add file to project.
$data = $this->client->api('projects')->uploadFile($projectId, $file);
// Add the uploaded file as a note on the given issue.
return $this->createNote($projectId, $issueId, $data['markdown'], $authorId);
} catch (\Gitlab\Exception\RuntimeException $e) {
throw $e;
}
}
// Actually creates the issue
......
......@@ -110,7 +110,6 @@ class Migration
$dateUpdated = $ticket[3]['_ts'];
$attachments = $this->trac->getAttachments($originalTicketId);
print_r($attachments);
$issue = $this->gitLab->createIssue($gitLabProject, $title, $description, $dateCreated, $assigneeId, $creatorId, $labels);
......@@ -128,6 +127,20 @@ class Migration
}
echo "\tAlso created " . count($ticket[4]) . " note(s)\n";
}*/
/*
* Add files attached to Trac ticket to new Gitlab issue.
*/
foreach ($attachments as $a) {
$file = file_put_contents($a['filename'], $a['content']['__jsonclass__'][1]);
$this->gitLab->createIssueAttachment($gitLabProject, $issue['id'], $a['filename'], $a['author']);
unlink($a['filename']);
echo "\tAttached file " . $a['filename'] . " to issue " . $issue['id'] . ".\n";
}
}
return $mapping;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment