From abf6dcd7065534272c455d256cca471edcf5a43a Mon Sep 17 00:00:00 2001
From: Christoph Alt <christoph.alt@fau.de>
Date: Thu, 9 Nov 2023 18:52:14 +0100
Subject: [PATCH] added a feature to the git git infos from api so that the
 commit can be also choosen from a env variable

---
 cbutil/gitlab_api.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/cbutil/gitlab_api.py b/cbutil/gitlab_api.py
index 1cb98d7..abb39dc 100644
--- a/cbutil/gitlab_api.py
+++ b/cbutil/gitlab_api.py
@@ -1,4 +1,5 @@
 import logging
+import os
 from typing import Union
 
 import requests
@@ -48,8 +49,14 @@ def get_git_infos_from_api(instance_url, project_id: Project_id,
                            *,
                            branch='main',
                            commit_key="commit",
-                           commit_msg_key="commit_message"):
-    last_commit = get_last_commit(instance_url, project_id, branch=branch)
+                           commit_msg_key="commit_message",
+                           commit_env_key=None):
+    last_commit = ""
+    if commit_env_key:
+        last_commit = os.getenv(commit_env_key, None)
+
+    if not last_commit:
+        last_commit = get_last_commit(instance_url, project_id, branch=branch)
     commit, commit_msg = get_commit_infos_from_api(last_commit)
     commit_msg = remove_newline(commit_msg)
     return {commit_key: commit, commit_msg_key: commit_msg}
-- 
GitLab