From 9816bbf95556e601cb353e26a57f503b72765b96 Mon Sep 17 00:00:00 2001
From: Thomas Hackl <thomas.hackl@uni-passau.de>
Date: Sat, 14 Jul 2018 18:19:18 +0200
Subject: [PATCH] note creation for non-admin users

---
 src/GitLab.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/GitLab.php b/src/GitLab.php
index 77194bd..58c9592 100644
--- a/src/GitLab.php
+++ b/src/GitLab.php
@@ -159,7 +159,13 @@ class GitLab
 			return $note;
 
         } catch (\Gitlab\Exception\RuntimeException $e) {
-			throw $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) {
+                $note = $this->doCreateNote($projectId, $issueId, $data['markdown'], $authorId, false);
+            } else {
+                // If adding has failed for some other reason, propagate the exception back
+                throw $e;
+            }
 		}
     }
 
-- 
GitLab