From c83a507d0468a61d097002a843fc067c491ee269 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Fri, 20 Nov 2020 01:18:24 +0000 Subject: [PATCH] Added logging --- src/Credfeto.ChangeLog/ChangeLogChecker.cs | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Credfeto.ChangeLog/ChangeLogChecker.cs b/src/Credfeto.ChangeLog/ChangeLogChecker.cs index 8f010a44..c9b28ab5 100644 --- a/src/Credfeto.ChangeLog/ChangeLogChecker.cs +++ b/src/Credfeto.ChangeLog/ChangeLogChecker.cs @@ -15,6 +15,8 @@ public static class ChangeLogChecker public static async Task ChangeLogModifiedInReleaseSectionAsync(string changeLogFileName, string originBranchName) { + changeLogFileName = GetFullChangeLogFilePath(changeLogFileName); + Console.WriteLine($"Changelog: {changeLogFileName}"); int? position = await ChangeLogReader.FindFirstReleaseVersionPositionAsync(changeLogFileName); if (position == null) @@ -22,11 +24,12 @@ public static async Task ChangeLogModifiedInReleaseSectionAsync(string cha return false; } - string changelogDir = Path.GetDirectoryName(changeLogFileName)!; + string changelogDir = GetChangeLogDirectory(changeLogFileName); + Console.WriteLine($"Changelog Folder: {changelogDir}"); using (Repository repo = OpenRepository(changelogDir)) { - string? sha = repo.Head.Tip.Sha; + string sha = repo.Head.Tip.Sha; Branch? originBranch = repo.Branches.FirstOrDefault(b => b.FriendlyName == originBranchName); @@ -42,6 +45,7 @@ public static async Task ChangeLogModifiedInReleaseSectionAsync(string cha } string changeLogInRepoPath = FindChangeLogPositionInRepo(repo: repo, changeLogFileName: changeLogFileName); + Console.WriteLine($"Relative to Repo Root: {changeLogInRepoPath}"); int firstReleaseVersionIndex = position.Value; @@ -91,6 +95,25 @@ public static async Task ChangeLogModifiedInReleaseSectionAsync(string cha return true; } + private static string GetFullChangeLogFilePath(string changeLogFileName) + { + string? path = Path.GetDirectoryName(changeLogFileName); + + if (path != null) + { + return changeLogFileName; + } + + return Path.Combine(Directory.GetCurrentDirectory(), path2: changeLogFileName); + } + + private static string GetChangeLogDirectory(string changeLogFileName) + { + string? path = Path.GetDirectoryName(changeLogFileName); + + return path ?? Directory.GetCurrentDirectory(); + } + private static string FindChangeLogPositionInRepo(Repository repo, string changeLogFileName) { return changeLogFileName.Substring(repo.Info.WorkingDirectory.Length)