diff --git a/src/Credfeto.ChangeLog/ChangeLogChecker.cs b/src/Credfeto.ChangeLog/ChangeLogChecker.cs index c9b28ab5..1d9b4f15 100644 --- a/src/Credfeto.ChangeLog/ChangeLogChecker.cs +++ b/src/Credfeto.ChangeLog/ChangeLogChecker.cs @@ -53,42 +53,49 @@ public static async Task ChangeLogModifiedInReleaseSectionAsync(string cha newTree: repo.Head.Tip.Tree, new CompareOptions {ContextLines = 0, InterhunkLines = 0, IncludeUnmodified = false}); - foreach (var change in changes) + PatchEntryChanges? change = changes.FirstOrDefault(candidate => candidate.Path == changeLogInRepoPath); + + if (change != null) { - if (change.Path == changeLogInRepoPath) - { - string patchDetails = change.Patch; - Console.WriteLine(patchDetails); - - MatchCollection matches = HunkPositionRegex.Matches(patchDetails); - - foreach (Match? match in matches) - { - if (match == null) - { - continue; - } - - int changeStart = Convert.ToInt32(match.Groups["CurrentFileStart"] - .Value); - - if (!int.TryParse(s: match.Groups["CurrentFileChangeLength"] - .Value, - out int changeLength)) - { - changeLength = 1; - } - - int changeEnd = changeStart + changeLength; - - if (changeEnd >= firstReleaseVersionIndex) - { - return false; - } - } - - return true; - } + return CheckForChangesAfterFirstRelease(change: change, firstReleaseVersionIndex: firstReleaseVersionIndex); + } + + Console.WriteLine("Could not find change in diff"); + } + + return true; + } + + private static bool CheckForChangesAfterFirstRelease(PatchEntryChanges change, int firstReleaseVersionIndex) + { + Console.WriteLine("Change Details"); + string patchDetails = change.Patch; + Console.WriteLine(patchDetails); + + MatchCollection matches = HunkPositionRegex.Matches(patchDetails); + + foreach (Match? match in matches) + { + if (match == null) + { + continue; + } + + int changeStart = Convert.ToInt32(match.Groups["CurrentFileStart"] + .Value); + + if (!int.TryParse(s: match.Groups["CurrentFileChangeLength"] + .Value, + out int changeLength)) + { + changeLength = 1; + } + + int changeEnd = changeStart + changeLength; + + if (changeEnd >= firstReleaseVersionIndex) + { + return false; } } @@ -97,14 +104,14 @@ public static async Task ChangeLogModifiedInReleaseSectionAsync(string cha private static string GetFullChangeLogFilePath(string changeLogFileName) { - string? path = Path.GetDirectoryName(changeLogFileName); + FileInfo changeLog = new FileInfo(changeLogFileName); - if (path != null) + if (!changeLog.Exists) { - return changeLogFileName; + throw new InvalidChangeLogException($"Could not find {changeLogFileName}"); } - return Path.Combine(Directory.GetCurrentDirectory(), path2: changeLogFileName); + return changeLog.FullName; } private static string GetChangeLogDirectory(string changeLogFileName)