From 2b79c1a3222a1fe9b524a7781365766bdefd9a08 Mon Sep 17 00:00:00 2001
From: Thomas Hackl <thomas.hackl@uni-passau.de>
Date: Sat, 14 Jul 2018 19:51:53 +0200
Subject: [PATCH] respect sensitive tickets

---
 src/GitLab.php    | 10 +++++++---
 src/Migration.php |  8 ++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/GitLab.php b/src/GitLab.php
index 58c9592..3069ddb 100644
--- a/src/GitLab.php
+++ b/src/GitLab.php
@@ -68,12 +68,13 @@ class GitLab
      * @param  int      $assigneeId   Numeric user id of the user asigned to the issue. Can be null.
      * @param  int      $authorId     Numeric user id of the user who created the issue. Only used in admin mode. Can be null.
      * @param  array    $labels       Array of string labels to be attached to the issue. Analoguous to trac keywords.
+	 * @param  bool     $confidential Is this issue confidential?
      * @return  Gitlab\Model\Issue
 	 */
-	public function createIssue($projectId, $title, $description, $createdAt, $assigneeId, $authorId, $labels) {
+	public function createIssue($projectId, $title, $description, $createdAt, $assigneeId, $authorId, $labels, $confidential = false) {
 		try {
 			// Try to add, potentially as an admin (SUDO authorId)
-			$issue = $this->doCreateIssue($projectId, $title, $description, $createdAt, $assigneeId, $authorId, $labels, $this->isAdmin);
+			$issue = $this->doCreateIssue($projectId, $title, $description, $createdAt, $assigneeId, $authorId, $labels, $confidential, $this->isAdmin);
 		} catch (\Gitlab\Exception\RuntimeException $e) {
 			// If adding has failed because of SUDO (author does not have access to the project), create an issue without SUDO (as the Admin user whose token is configured)
 			if ($this->isAdmin) {
@@ -170,7 +171,7 @@ class GitLab
     }
 
 	// Actually creates the issue
-	private function doCreateIssue($projectId, $title, $description, $createdAt, $assigneeId, $authorId, $labels, $isAdmin) {
+	private function doCreateIssue($projectId, $title, $description, $createdAt, $assigneeId, $authorId, $labels, $confidential, $isAdmin) {
 		$issueProperties = array(
 			'title' => $title,
 			'description' => $description,
@@ -178,6 +179,9 @@ class GitLab
 			'labels' => $labels,
             'created_at' => $createdAt
 		);
+		if ($confidential) {
+			$issueProperties['confidential'] = true;
+        }
 		if ($isAdmin) {
 			$issueProperties['sudo'] = $authorId;
 		}
diff --git a/src/Migration.php b/src/Migration.php
index 49354d6..25300b9 100644
--- a/src/Migration.php
+++ b/src/Migration.php
@@ -108,12 +108,16 @@ class Migration
 			$labels = $ticket[3]['keywords'];
             $dateCreated = $ticket[3]['time']['__jsonclass__'][1];
             $dateUpdated = $ticket[3]['_ts'];
+            $confidential = $ticket[3]['sensitive'];
 
             $attachments = $this->trac->getAttachments($originalTicketId);
 
-			$issue = $this->gitLab->createIssue($gitLabProject, $title, $description, $dateCreated, $assigneeId, $creatorId, $labels);
+			$issue = $this->gitLab->createIssue($gitLabProject, $title,
+				$description, $dateCreated, $assigneeId, $creatorId, $labels,
+				$confidential);
 
-			echo 'Created a GitLab issue #' . $issue['iid'] . ' for Trac ticket #' . $originalTicketId . ' : ' . $this->gitLab->getUrl() . '/' . $gitLabProject . '/issues/' . $issue['iid'] . "\n";
+			echo 'Created a GitLab issue #' . $issue['iid'] . ' for Trac ticket #' . $originalTicketId . ' : ' .
+				$this->gitLab->getUrl() . '/' . $gitLabProject . '/issues/' . $issue['iid'] . "\n";
 
             $mapping[$originalTicketId] = $issue['iid'];
 
-- 
GitLab