Skip to content

Commit

Permalink
More logging
Browse files Browse the repository at this point in the history
  • Loading branch information
credfeto committed Nov 20, 2020
1 parent c83a507 commit 3d1d0d0
Showing 1 changed file with 46 additions and 39 deletions.
85 changes: 46 additions & 39 deletions src/Credfeto.ChangeLog/ChangeLogChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,49 @@ public static async Task<bool> 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;
}
}

Expand All @@ -97,14 +104,14 @@ public static async Task<bool> 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)
Expand Down

0 comments on commit 3d1d0d0

Please sign in to comment.