Skip to content

Commit

Permalink
Added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
credfeto committed Nov 20, 2020
1 parent ef9d297 commit c83a507
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/Credfeto.ChangeLog/ChangeLogChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ public static class ChangeLogChecker

public static async Task<bool> ChangeLogModifiedInReleaseSectionAsync(string changeLogFileName, string originBranchName)
{
changeLogFileName = GetFullChangeLogFilePath(changeLogFileName);
Console.WriteLine($"Changelog: {changeLogFileName}");
int? position = await ChangeLogReader.FindFirstReleaseVersionPositionAsync(changeLogFileName);

if (position == null)
{
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);

Expand All @@ -42,6 +45,7 @@ public static async Task<bool> ChangeLogModifiedInReleaseSectionAsync(string cha
}

string changeLogInRepoPath = FindChangeLogPositionInRepo(repo: repo, changeLogFileName: changeLogFileName);
Console.WriteLine($"Relative to Repo Root: {changeLogInRepoPath}");

int firstReleaseVersionIndex = position.Value;

Expand Down Expand Up @@ -91,6 +95,25 @@ public static async Task<bool> 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)
Expand Down

0 comments on commit c83a507

Please sign in to comment.