From 408072d436541ecaef3c42210b8d0305bdb2a4b2 Mon Sep 17 00:00:00 2001 From: Thomas Hackl <thomas.hackl@uni-passau.de> Date: Sat, 14 Jul 2018 17:10:52 +0200 Subject: [PATCH] replace image links in ticket description --- src/GitLab.php | 15 ++++++++++++++- src/Migration.php | 9 ++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/GitLab.php b/src/GitLab.php index 3b78dec..3cef1ac 100644 --- a/src/GitLab.php +++ b/src/GitLab.php @@ -125,7 +125,20 @@ class GitLab $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); + $note = $this->createNote($projectId, $issueId, $data['markdown'], $authorId); + + // Update possible mentions of this file in issue description. + $issue = $this->client->api('issues')->show($projectId, $issueId); + + $description = str_replace( + '[[br]]', + '<br>', + preg_replace('/!\[image\]\((.+),.*\)/U', $data['markdown'], $issue['description']) + ); + + $this->client->api('issues')->update($projectId, $issueId, ['description' => $description]); + + return $note; } catch (\Gitlab\Exception\RuntimeException $e) { throw $e; diff --git a/src/Migration.php b/src/Migration.php index 86f1e16..bc6cc31 100644 --- a/src/Migration.php +++ b/src/Migration.php @@ -128,9 +128,12 @@ class Migration echo "\tAlso created " . count($ticket[4]) . " note(s)\n"; }*/ - /* - * Add files attached to Trac ticket to new Gitlab issue. - */ + // Map old image filenames to new markdown links + $images = []; + + /* + * Add files attached to Trac ticket to new Gitlab issue. + */ foreach ($attachments as $a) { file_put_contents($a['filename'], base64_decode($a['content'])); -- GitLab