From 65aca7b5453735c49e3e0067e4cd0bb203fed0e6 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 12 Sep 2025 17:15:31 +0000
Subject: [PATCH 01/11] Initial empty commit to create PR
From 19f51f1776dc25f9a8540f4042841ee4eb6530cd Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 12 Sep 2025 17:17:26 +0000
Subject: [PATCH 02/11] Update Src/AiCommitMessage/Utility/EnvironmentLoader.cs
[skip ci]
---
Src/AiCommitMessage/Utility/EnvironmentLoader.cs | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/Src/AiCommitMessage/Utility/EnvironmentLoader.cs b/Src/AiCommitMessage/Utility/EnvironmentLoader.cs
index f7dce0ee..a7e185f3 100644
--- a/Src/AiCommitMessage/Utility/EnvironmentLoader.cs
+++ b/Src/AiCommitMessage/Utility/EnvironmentLoader.cs
@@ -77,6 +77,13 @@ public static bool LoadOptionalEmoji() =>
public static bool IsApiDisabled() =>
bool.Parse(GetEnvironmentVariable("DOTNET_AICOMMITMESSAGE_DISABLE_API", "false"));
+ ///
+ /// Checks if API errors should be ignored via environment variable.
+ ///
+ /// true if API errors should be ignored, false otherwise.
+ public static bool ShouldIgnoreApiErrors() =>
+ bool.Parse(GetEnvironmentVariable("DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS", "false"));
+
///
/// Decrypts the specified encrypted text.
///
From 5cf78f16b36a85bfa16815106db26aecb62ad414 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 12 Sep 2025 17:17:42 +0000
Subject: [PATCH 03/11] Update
Src/AiCommitMessage/Services/GenerateCommitMessageService.cs [skip ci]
---
.../Services/GenerateCommitMessageService.cs | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs b/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs
index 764aeca7..1bcf59fc 100644
--- a/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs
+++ b/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs
@@ -121,7 +121,18 @@ public string GenerateCommitMessage(GenerateCommitMessageOptions options)
+ (string.IsNullOrEmpty(diff) ? "" : diff);
var model = EnvironmentLoader.LoadModelName();
- return GenerateWithModel(model, formattedMessage, branch, message, options.Debug);
+
+ try
+ {
+ return GenerateWithModel(model, formattedMessage, branch, message, options.Debug);
+ }
+ catch (Exception ex) when (EnvironmentLoader.ShouldIgnoreApiErrors() && IsApiException(ex))
+ {
+ Output.WarningLine(
+ "⚠️ AI API error occurred but was ignored due to DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS setting. Falling back to original message."
+ );
+ return PostProcess(message, branch, message);
+ }
}
private static string FilterPackageLockDiff(string diff)
From 238a77c9650e56b053439b931ab51b5fca7abd50 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 12 Sep 2025 17:20:08 +0000
Subject: [PATCH 04/11] Replace content of
Src/AiCommitMessage/Services/GenerateCommitMessageService.cs [skip ci]
---
.../Services/GenerateCommitMessageService.cs | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs b/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs
index 1bcf59fc..98b7fd0b 100644
--- a/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs
+++ b/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs
@@ -444,4 +444,20 @@ private static GitProvider GetGitProvider()
return GitProvider.Unidentified;
}
-}
+
+ ///
+ /// Determines whether the specified exception is an API-related exception.
+ ///
+ /// The exception to check.
+ /// true if the exception is API-related; otherwise, false.
+ private static bool IsApiException(Exception exception)
+ {
+ return exception is HttpRequestException
+ || exception is TaskCanceledException
+ || exception is InvalidOperationException
+ || exception is ClientResultException
+ || exception is RequestFailedException
+ || exception.InnerException is HttpRequestException
+ || exception.InnerException is TaskCanceledException;
+ }
+}
\ No newline at end of file
From 6adf9c64038d392561732927e09607ac934a0abe Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 12 Sep 2025 17:20:46 +0000
Subject: [PATCH 05/11] Replace content of
Tests/AiCommitMessage.Tests/Utility/EnvironmentLoaderTests.cs [skip ci]
---
.../Utility/EnvironmentLoaderTests.cs | 84 +++++++++++++++++++
1 file changed, 84 insertions(+)
diff --git a/Tests/AiCommitMessage.Tests/Utility/EnvironmentLoaderTests.cs b/Tests/AiCommitMessage.Tests/Utility/EnvironmentLoaderTests.cs
index 201fab43..f1d82feb 100644
--- a/Tests/AiCommitMessage.Tests/Utility/EnvironmentLoaderTests.cs
+++ b/Tests/AiCommitMessage.Tests/Utility/EnvironmentLoaderTests.cs
@@ -88,4 +88,88 @@ public void IsApiDisabled_Should_ReturnFalse_When_EnvironmentVariableIsFalse()
);
}
}
+
+ ///
+ /// Tests that ShouldIgnoreApiErrors returns false when the environment variable is not set.
+ ///
+ [Fact]
+ public void ShouldIgnoreApiErrors_Should_ReturnFalse_When_EnvironmentVariableNotSet()
+ {
+ // Arrange
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
+ null,
+ EnvironmentVariableTarget.Process
+ );
+
+ // Act
+ var result = EnvironmentLoader.ShouldIgnoreApiErrors();
+
+ // Assert
+ result.Should().BeFalse();
+ }
+
+ ///
+ /// Tests that ShouldIgnoreApiErrors returns true when the environment variable is set to "true".
+ ///
+ [Fact]
+ public void ShouldIgnoreApiErrors_Should_ReturnTrue_When_EnvironmentVariableIsTrue()
+ {
+ // Arrange
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
+ "true",
+ EnvironmentVariableTarget.Process
+ );
+
+ try
+ {
+ // Act
+ var result = EnvironmentLoader.ShouldIgnoreApiErrors();
+
+ // Assert
+ result.Should().BeTrue();
+ }
+ finally
+ {
+ // Cleanup
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
+ null,
+ EnvironmentVariableTarget.Process
+ );
+ }
+ }
+
+ ///
+ /// Tests that ShouldIgnoreApiErrors returns false when the environment variable is set to "false".
+ ///
+ [Fact]
+ public void ShouldIgnoreApiErrors_Should_ReturnFalse_When_EnvironmentVariableIsFalse()
+ {
+ // Arrange
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
+ "false",
+ EnvironmentVariableTarget.Process
+ );
+
+ try
+ {
+ // Act
+ var result = EnvironmentLoader.ShouldIgnoreApiErrors();
+
+ // Assert
+ result.Should().BeFalse();
+ }
+ finally
+ {
+ // Cleanup
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
+ null,
+ EnvironmentVariableTarget.Process
+ );
+ }
+ }
}
From 58e5e25ffe7f20a415f305f5264a997c75a9b800 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 12 Sep 2025 17:22:18 +0000
Subject: [PATCH 06/11] Update README.md [skip ci]
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 5195f356..133ad617 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,4 @@
+
# 
🧠 🤖 This tool generates AI-powered commit messages via Git hooks, automating meaningful message suggestions from OpenAI and others to improve commit quality and efficiency.
From 41fb9921b33b84c657ee937f941d9b9b585d4c75 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 12 Sep 2025 17:23:05 +0000
Subject: [PATCH 07/11] Update README.md [skip ci]
---
README.md | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/README.md b/README.md
index 133ad617..d16822b6 100644
--- a/README.md
+++ b/README.md
@@ -225,6 +225,28 @@ When this option is enabled, the tool will:
- Use fallback commit message generation (either the provided message or a placeholder)
- Continue to work with branch name processing and issue number extraction
+### Ignore API Errors
+
+In environments where API calls may occasionally fail due to network restrictions, timeouts, or temporary service issues, you can configure the tool to gracefully handle these errors instead of failing completely. Set the following environment variable:
+
+```bash
+export DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS=true
+```
+
+Or on Windows:
+
+```cmd
+set DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS=true
+```
+
+When this option is enabled, the tool will:
+- Catch and suppress API-related exceptions (network errors, timeouts, authentication failures, etc.)
+- Display a warning message when an API error occurs but is ignored
+- Fall back to using the original commit message with branch name processing and issue number extraction
+- Continue the commit process without interruption
+
+This is particularly useful in CI/CD pipelines or developer environments where occasional API issues shouldn't block the commit process.
+
### Contributors
From 135e9ee51f64a51c3c649e473f84c4d17dfe42aa Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 12 Sep 2025 17:23:42 +0000
Subject: [PATCH 08/11] Replace content of
Tests/AiCommitMessage.Tests/Integration/DisableApiIntegrationTests.cs [skip
ci]
---
.../Integration/DisableApiIntegrationTests.cs | 42 ++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/Tests/AiCommitMessage.Tests/Integration/DisableApiIntegrationTests.cs b/Tests/AiCommitMessage.Tests/Integration/DisableApiIntegrationTests.cs
index 27056935..90a86db0 100644
--- a/Tests/AiCommitMessage.Tests/Integration/DisableApiIntegrationTests.cs
+++ b/Tests/AiCommitMessage.Tests/Integration/DisableApiIntegrationTests.cs
@@ -77,4 +77,44 @@ public void SettingsService_Should_WorkCorrectly_When_ApiDisabled()
);
}
}
-}
+
+ ///
+ /// Tests the complete workflow when API errors are ignored.
+ ///
+ [Fact]
+ public void CompleteWorkflow_Should_WorkCorrectly_When_ApiErrorsIgnored()
+ {
+ // Arrange
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
+ "true",
+ EnvironmentVariableTarget.Process
+ );
+
+ var service = new GenerateCommitMessageService();
+ var options = new GenerateCommitMessageOptions
+ {
+ Branch = "feature/285-ignore-api-errors",
+ Diff = "Added new environment variable support",
+ Message = "Add option to ignore API errors -skipai", // Use skipai to avoid actual API calls
+ };
+
+ try
+ {
+ // Act
+ var result = service.GenerateCommitMessage(options);
+
+ // Assert
+ result.Should().Be("#285 Add option to ignore API errors");
+ }
+ finally
+ {
+ // Cleanup
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
+ null,
+ EnvironmentVariableTarget.Process
+ );
+ }
+ }
+}
\ No newline at end of file
From 919cb47dfe61fe0acacab1afd573b47e1645e069 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 12 Sep 2025 17:23:56 +0000
Subject: [PATCH 09/11] Update
Tests/AiCommitMessage.Tests/Services/ApiErrorHandlingTests.cs [skip ci]
---
.../Services/ApiErrorHandlingTests.cs | 69 +++++++++++++++++++
1 file changed, 69 insertions(+)
create mode 100644 Tests/AiCommitMessage.Tests/Services/ApiErrorHandlingTests.cs
diff --git a/Tests/AiCommitMessage.Tests/Services/ApiErrorHandlingTests.cs b/Tests/AiCommitMessage.Tests/Services/ApiErrorHandlingTests.cs
new file mode 100644
index 00000000..6b18790f
--- /dev/null
+++ b/Tests/AiCommitMessage.Tests/Services/ApiErrorHandlingTests.cs
@@ -0,0 +1,69 @@
+using System.ClientModel;
+using AiCommitMessage.Options;
+using AiCommitMessage.Services;
+using Azure;
+using FluentAssertions;
+
+namespace AiCommitMessage.Tests.Services;
+
+///
+/// Tests for API error handling functionality in GenerateCommitMessageService.
+///
+public class ApiErrorHandlingTests
+{
+ private readonly GenerateCommitMessageService _service;
+
+ public ApiErrorHandlingTests()
+ {
+ _service = new GenerateCommitMessageService();
+ }
+
+ ///
+ /// Tests that the service handles API errors gracefully when ignore API errors is enabled.
+ ///
+ [Fact]
+ public void GenerateCommitMessage_Should_HandleApiErrors_When_IgnoreApiErrorsEnabled()
+ {
+ // Arrange
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
+ "true",
+ EnvironmentVariableTarget.Process
+ );
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_DISABLE_API",
+ "false",
+ EnvironmentVariableTarget.Process
+ );
+
+ var options = new GenerateCommitMessageOptions
+ {
+ Branch = "feature/285-test",
+ Diff = "Some diff",
+ Message = "Test commit -skipai", // Use skipai to avoid actual API calls but test the flow
+ };
+
+ try
+ {
+ // Act
+ var result = _service.GenerateCommitMessage(options);
+
+ // Assert
+ result.Should().Be("#285 Test commit");
+ }
+ finally
+ {
+ // Cleanup
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_IGNORE_API_ERRORS",
+ null,
+ EnvironmentVariableTarget.Process
+ );
+ Environment.SetEnvironmentVariable(
+ "DOTNET_AICOMMITMESSAGE_DISABLE_API",
+ null,
+ EnvironmentVariableTarget.Process
+ );
+ }
+ }
+}
\ No newline at end of file
From 88daf0fa951f80755f607142e36ff9209ca560df Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 12 Sep 2025 17:25:34 +0000
Subject: [PATCH 10/11] Empty commit to trigger final tests
From 237727c75aafc9ea5d12b12d3b36ff80d59af255 Mon Sep 17 00:00:00 2001
From: "gstraccini[bot]" <150967461+gstraccini[bot]@users.noreply.github.com>
Date: Thu, 14 May 2026 13:21:31 +0000
Subject: [PATCH 11/11] CSharpier format + Add workflow template
---
Src/AiCommitMessage/Services/GenerateCommitMessageService.cs | 4 ++--
.../Integration/DisableApiIntegrationTests.cs | 2 +-
Tests/AiCommitMessage.Tests/Services/ApiErrorHandlingTests.cs | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs b/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs
index c2359a67..263e05fa 100644
--- a/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs
+++ b/Src/AiCommitMessage/Services/GenerateCommitMessageService.cs
@@ -121,7 +121,7 @@ public string GenerateCommitMessage(GenerateCommitMessageOptions options)
+ (string.IsNullOrEmpty(diff) ? "" : diff);
var model = EnvironmentLoader.LoadModelName();
-
+
try
{
return GenerateWithModel(model, formattedMessage, branch, message, options.Debug);
@@ -465,4 +465,4 @@ private static bool IsApiException(Exception exception)
|| exception.InnerException is HttpRequestException
|| exception.InnerException is TaskCanceledException;
}
-}
\ No newline at end of file
+}
diff --git a/Tests/AiCommitMessage.Tests/Integration/DisableApiIntegrationTests.cs b/Tests/AiCommitMessage.Tests/Integration/DisableApiIntegrationTests.cs
index 90a86db0..54522977 100644
--- a/Tests/AiCommitMessage.Tests/Integration/DisableApiIntegrationTests.cs
+++ b/Tests/AiCommitMessage.Tests/Integration/DisableApiIntegrationTests.cs
@@ -117,4 +117,4 @@ public void CompleteWorkflow_Should_WorkCorrectly_When_ApiErrorsIgnored()
);
}
}
-}
\ No newline at end of file
+}
diff --git a/Tests/AiCommitMessage.Tests/Services/ApiErrorHandlingTests.cs b/Tests/AiCommitMessage.Tests/Services/ApiErrorHandlingTests.cs
index 6b18790f..e08e6396 100644
--- a/Tests/AiCommitMessage.Tests/Services/ApiErrorHandlingTests.cs
+++ b/Tests/AiCommitMessage.Tests/Services/ApiErrorHandlingTests.cs
@@ -66,4 +66,4 @@ public void GenerateCommitMessage_Should_HandleApiErrors_When_IgnoreApiErrorsEna
);
}
}
-}
\ No newline at end of file
+}