From 399e1e0d95199ac3c3dce23e7983222d59fb1200 Mon Sep 17 00:00:00 2001
From: Klaus Fischer <klaus.fischer@eloware.com>
Date: Tue, 17 Jan 2023 17:45:44 +0100
Subject: [PATCH] Added test for comit id

---
 FitConnect/FitConnect.csproj       | 7 +++++++
 FitConnect/ProjectSpecification.cs | 4 +++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/FitConnect/FitConnect.csproj b/FitConnect/FitConnect.csproj
index da9cb9f1..dfcb3473 100644
--- a/FitConnect/FitConnect.csproj
+++ b/FitConnect/FitConnect.csproj
@@ -49,6 +49,9 @@
         <EmbeddedResource Include="TrustedRootCertificates\PCA-1-Verwaltung-17.pem" />
         <None Remove="Certificates\PCA-1-Verwaltung-20.pem" />
         <EmbeddedResource Include="TrustedRootCertificates\PCA-1-Verwaltung-20.pem" />
+        <None Update="commitId.tmp">
+          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+        </None>
     </ItemGroup>
 
     <ItemGroup>
@@ -63,4 +66,8 @@
         <Compile Remove="Services\Models\v1\Api\ReplyChannel.cs" />
     </ItemGroup>
 
+    <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
+      <Exec Command="git rev-parse --short HEAD &gt; commitId.tmp" />
+    </Target>
+
 </Project>
diff --git a/FitConnect/ProjectSpecification.cs b/FitConnect/ProjectSpecification.cs
index 8e5a4e62..887899d0 100644
--- a/FitConnect/ProjectSpecification.cs
+++ b/FitConnect/ProjectSpecification.cs
@@ -18,7 +18,9 @@ internal static class ProjectSpecification {
 
     private static string? GetCommitId() {
         const string commitFileName = "commitId.tmp";
-        return File.Exists(commitFileName) ? File.ReadAllText(commitFileName) : null;
+        return File.Exists(commitFileName)
+            ? File.ReadAllLines(commitFileName).First()
+            : "development";
     }
 
     public static byte[] CalculateCallbackHmac(string callbackSecret, long timestamp, string body) {
-- 
GitLab