diff --git a/GitCommitAnalyser/AiClusterLabeler.cs b/GitCommitAnalyser.Core/AiClusterLabeler.cs similarity index 98% rename from GitCommitAnalyser/AiClusterLabeler.cs rename to GitCommitAnalyser.Core/AiClusterLabeler.cs index d2af450..c01d212 100644 --- a/GitCommitAnalyser/AiClusterLabeler.cs +++ b/GitCommitAnalyser.Core/AiClusterLabeler.cs @@ -1,12 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Http; using System.Text.Json; -using System.Threading.Tasks; - -namespace GitCommitAnalyser +namespace GitCommitAnalyser.Core { public enum ClusterLabelingMode { diff --git a/GitCommitAnalyser/Analyser.cs b/GitCommitAnalyser.Core/Analyser.cs similarity index 99% rename from GitCommitAnalyser/Analyser.cs rename to GitCommitAnalyser.Core/Analyser.cs index f3cd5d8..30d1944 100644 --- a/GitCommitAnalyser/Analyser.cs +++ b/GitCommitAnalyser.Core/Analyser.cs @@ -3,7 +3,7 @@ using System.Text.Json; using Microsoft.ML; -namespace GitCommitAnalyser +namespace GitCommitAnalyser.Core { public class CommitMLData { @@ -22,7 +22,7 @@ public class CommitPredictionWithData : CommitMLData } - internal class Analyser + public class Analyser { private const string FeaturesColumnName = "Features"; diff --git a/GitCommitAnalyser/CommitFetcher.cs b/GitCommitAnalyser.Core/CommitFetcher.cs similarity index 96% rename from GitCommitAnalyser/CommitFetcher.cs rename to GitCommitAnalyser.Core/CommitFetcher.cs index 72a4c9f..c2e153a 100644 --- a/GitCommitAnalyser/CommitFetcher.cs +++ b/GitCommitAnalyser.Core/CommitFetcher.cs @@ -1,13 +1,7 @@ -using DotNetEnv; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Text.Json; -using System.Threading.Tasks; using Octokit; -namespace GitCommitAnalyser +namespace GitCommitAnalyser.Core { public class CommitFetcher { diff --git a/GitCommitAnalyser.Core/CommitLabeler.cs b/GitCommitAnalyser.Core/CommitLabeler.cs new file mode 100644 index 0000000..8f943e7 --- /dev/null +++ b/GitCommitAnalyser.Core/CommitLabeler.cs @@ -0,0 +1,40 @@ +using Microsoft.ML; + +namespace GitCommitAnalyser.Core +{ + public class CommitLabeler + { + private readonly PredictionEngine _predictionEngine; + private readonly Dictionary _clusterNames; + + public CommitLabeler(MLContext mlContext, ITransformer model, Dictionary clusterNames = null) + { + _predictionEngine = mlContext.Model.CreatePredictionEngine(model); + _clusterNames = clusterNames; + } + + public uint PredictClusterId(CommitMLData inputData) + { + var prediction = _predictionEngine.Predict(inputData); + return prediction.PredictedClusterId; + } + + public string FormatCommitMessage(string commitName) + { + var inputData = new CommitMLData + { + CommitName = commitName, + CommitDescription = string.Empty, + Repository = "InteractiveInput" + }; + + var predictedClusterId = PredictClusterId(inputData); + + string label = _clusterNames != null && _clusterNames.TryGetValue(predictedClusterId, out var name) + ? name + : $"Cluster_{predictedClusterId}"; + + return $"{label}: {commitName}"; + } + } +} \ No newline at end of file diff --git a/GitCommitAnalyser.Core/GitCommitAnalyser.Core.csproj b/GitCommitAnalyser.Core/GitCommitAnalyser.Core.csproj new file mode 100644 index 0000000..125f4c9 --- /dev/null +++ b/GitCommitAnalyser.Core/GitCommitAnalyser.Core.csproj @@ -0,0 +1,9 @@ + + + + net9.0 + enable + enable + + + diff --git a/GitCommitAnalyser.sln b/GitCommitAnalyser.sln index 3659eae..f47a000 100644 --- a/GitCommitAnalyser.sln +++ b/GitCommitAnalyser.sln @@ -1,10 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.14.37301.10 d17.14 +VisualStudioVersion = 17.14.37301.10 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitCommitAnalyser", "GitCommitAnalyser\GitCommitAnalyser.csproj", "{CB822809-34E5-4F65-A442-ED6EAF5D5ED2}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitCommitAnalyser.Core", "GitCommitAnalyser.Core\GitCommitAnalyser.Core.csproj", "{07A694AB-12C1-4FC4-9A03-E36520D092A8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {CB822809-34E5-4F65-A442-ED6EAF5D5ED2}.Debug|Any CPU.Build.0 = Debug|Any CPU {CB822809-34E5-4F65-A442-ED6EAF5D5ED2}.Release|Any CPU.ActiveCfg = Release|Any CPU {CB822809-34E5-4F65-A442-ED6EAF5D5ED2}.Release|Any CPU.Build.0 = Release|Any CPU + {07A694AB-12C1-4FC4-9A03-E36520D092A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {07A694AB-12C1-4FC4-9A03-E36520D092A8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {07A694AB-12C1-4FC4-9A03-E36520D092A8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {07A694AB-12C1-4FC4-9A03-E36520D092A8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/GitCommitAnalyser/AppOrchestrator.cs b/GitCommitAnalyser/AppOrchestrator.cs index 5cc9a9d..399f070 100644 --- a/GitCommitAnalyser/AppOrchestrator.cs +++ b/GitCommitAnalyser/AppOrchestrator.cs @@ -1,8 +1,5 @@ -using System; -using System.IO; -using System.Threading.Tasks; using Microsoft.ML; - +using GitCommitAnalyser.Core; namespace GitCommitAnalyser { public class AppOrchestrator diff --git a/GitCommitAnalyser/CommitInteractiveLabeler.cs b/GitCommitAnalyser/CommitInteractiveLabeler.cs index e639004..c18a21d 100644 --- a/GitCommitAnalyser/CommitInteractiveLabeler.cs +++ b/GitCommitAnalyser/CommitInteractiveLabeler.cs @@ -1,24 +1,17 @@ -using System; -using System.Collections.Generic; using Microsoft.ML; +using GitCommitAnalyser.Core; namespace GitCommitAnalyser { public class CommitInteractiveLabeler { private readonly MLContext _mlContext; - private readonly ITransformer _model; - private readonly Dictionary _clusterNames; - private readonly PredictionEngine _predictionEngine; + private readonly CommitLabeler _predictor; public CommitInteractiveLabeler(MLContext mlContext, ITransformer model, Dictionary clusterNames) { _mlContext = mlContext; - _model = model; - _clusterNames = clusterNames; - - // Create a Prediction Engine for single-item inference - _predictionEngine = _mlContext.Model.CreatePredictionEngine(_model); + _predictor = new CommitLabeler(mlContext, model, clusterNames); } public void StartInteractiveLoop() @@ -41,33 +34,9 @@ public void StartInteractiveLoop() break; } - var formattedCommit = FormatCommitMessage(input); + var formattedCommit = _predictor.FormatCommitMessage(input); Console.WriteLine($"Formatted => {formattedCommit}\n"); } } - - public string FormatCommitMessage(string commitName) - { - // Prepare the input data for the ML.NET model - var inputData = new CommitMLData - { - CommitName = commitName, - CommitDescription = string.Empty, - Repository = "InteractiveInput" - }; - - // Predict which cluster it belongs to - var prediction = _predictionEngine.Predict(inputData); - - // Fetch the human-readable label from the Gemini cached Dictionary - string label = _clusterNames != null && _clusterNames.TryGetValue(prediction.PredictedClusterId, out var name) - ? name - : $"Cluster_{prediction.PredictedClusterId}"; - - // Map spaces to hyphens/underscores if you want a strict prefix, - // but keeping it as the Gemini-provided label string works directly. - // Result: "Bug Fix / UI: fixed the button alignment" - return $"{label}: {commitName}"; - } } } diff --git a/GitCommitAnalyser/GitCommitAnalyser.csproj b/GitCommitAnalyser/GitCommitAnalyser.csproj index 2279729..54bf1f5 100644 --- a/GitCommitAnalyser/GitCommitAnalyser.csproj +++ b/GitCommitAnalyser/GitCommitAnalyser.csproj @@ -14,4 +14,8 @@ + + + + diff --git a/GitCommitAnalyser/intructions.txt b/GitCommitAnalyser/intructions.txt new file mode 100644 index 0000000..e69de29