From fc593bb27a09c87c4211e8678b880effefe52228 Mon Sep 17 00:00:00 2001
From: "L. Ellenbeck" <ellenbeck@itc.rwth-aachen.de>
Date: Thu, 23 Jan 2020 15:33:38 +0100
Subject: [PATCH] Working variation

---
 build.cake | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/build.cake b/build.cake
index 4ced2b4..6181f2b 100644
--- a/build.cake
+++ b/build.cake
@@ -138,7 +138,7 @@ Task("GitlabRelease")
 	var tagList = result.Content.ReadAsStringAsync().Result;
 	var jArray = JArray.Parse(tagList);
 	// null if not tags exists yet
-	var lastTag = jArray.FirstOrDefault();
+	var lastTag = jArray.Select(x => x["name"]).FirstOrDefault();
 
 	var url = $"https://git.rwth-aachen.de/{gitlabProjectPath}";
 	
@@ -165,12 +165,14 @@ Task("GitlabRelease")
 		logParam = $"{lastTag}..Head";
 	}
 
+	Information(lastTag);
+
 	IEnumerable<string> redirectedStandardOutput;
 	var exitCodeWithArgument =
 		StartProcess(
 			"git",
 			new ProcessSettings {
-				Arguments = $"log {logParam} --pretty=format:'%h %B'",
+				Arguments = $"log {logParam} --pretty=format:HASH%h:%B",
 				RedirectStandardOutput = true
 			},
 			out redirectedStandardOutput
@@ -187,14 +189,22 @@ Task("GitlabRelease")
 		{"Chore", new List<string>()},
 	};
 
+	var currentHash = "";
 	// Output last line of process output.
 	foreach(var line in redirectedStandardOutput) {
-		var index = line.IndexOf(" ");
-		var commitHash = line.Substring(0, index);
-		var commitMessage = line.Substring(index + 1);
+		var commitMessage = "";
+		if(line.StartsWith("HASH")) {
+			currentHash = line.Substring("HASH".Length);
+			currentHash = currentHash.Substring(0, currentHash.IndexOf(":"));
+			commitMessage = line.Substring(currentHash.Length + line.IndexOf(currentHash) + 1);
+		} else {
+			commitMessage = line;
+		}
+
 		foreach(var kv in prefixList) {
 			if(commitMessage.StartsWith($"{kv.Key}:")) {
-				kv.Value.Add($"* {commitMessage.Substring(kv.Key.Length + 1).Trim()} {commitHash}");
+				kv.Value.Add($"* {commitMessage.Substring(kv.Key.Length + 1).Trim()} {currentHash}");
+				break;
 			}
 		};
 	}
@@ -210,7 +220,7 @@ Task("GitlabRelease")
 	}
 	// correctly escape the json newlines
 	description = description.Replace("\n", "\\n");
-	Information("{0}", description);
+	Information("Description: {0}", description);
 	throw new Exception();
 
 	// create tag
-- 
GitLab