Skip to content

Commit

Permalink
Adressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dhoehna committed Sep 25, 2024
1 parent f90a5c8 commit 5a8051b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ namespace DevHome.RepositoryManagement.Models;

public class Commit
{
public static readonly Commit DefaultCommit = new(string.Empty, TimeSpan.FromMinutes(0), string.Empty);
public static readonly Commit DefaultCommit = new(string.Empty, DateTime.MinValue, string.Empty);

public string Author { get; }

public TimeSpan TimeSinceCommit { get; }
public DateTime CommitDateTime { get; }

public string SHA { get; }

public Commit(string author, TimeSpan timeSinceCommit, string sHA)
public Commit(string author, DateTime commitDateTime, string sHA)
{
Author = author;
TimeSinceCommit = timeSinceCommit;
CommitDateTime = commitDateTime;
SHA = sHA;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public string GetLocalBranchName(string repositoryLocation)
{
try
{
var repository = new LibGit2Sharp.Repository(repositoryLocation);
using var repository = new LibGit2Sharp.Repository(repositoryLocation);
return repository.Head.FriendlyName;
}
catch (Exception ex)
Expand All @@ -83,7 +83,7 @@ public string GetRepositoryUrl(string repositoryLocation)
{
try
{
var repository = new LibGit2Sharp.Repository(repositoryLocation);
using var repository = new LibGit2Sharp.Repository(repositoryLocation);
return repository.Network.Remotes.First().Url;
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private List<RepositoryManagementItemViewModel> ConvertToLineItems(List<(Reposit
lineItem.HasCommitInformation = true;
lineItem.LatestCommitAuthor = commit.Author;
lineItem.LatestCommitSHA = commit.SHA;
lineItem.MinutesSinceLatestCommit = Convert.ToInt32(commit.TimeSinceCommit.TotalMinutes);
lineItem.MinutesSinceLatestCommit = Convert.ToInt32((DateTime.Now - commit.CommitDateTime).TotalMinutes);
}

lineItem.HasAConfigurationFile = repository.HasAConfigurationFile;
Expand Down Expand Up @@ -351,18 +351,16 @@ private Commit GetLatestCommitInformation(string repositoryLocation, Guid source
return Commit.DefaultCommit;
}

TimeSpan timeElapsed = DateTime.UtcNow - DateTime.UnixEpoch;

DateTime latestCommitDateTime;

// latestCommitDateTime can be in the future causing diff(now - latestCommitDateTime)
// to be negative. Show the negative value. Be transparent.
// also, the future date might have been on purpose.
if (DateTime.TryParse(latestCommitChangedDate.ToString(), out latestCommitDateTime))
// The future date might have been on purpose.
if (!DateTime.TryParse(latestCommitChangedDate.ToString(), out latestCommitDateTime))
{
timeElapsed = DateTime.UtcNow - latestCommitDateTime;
latestCommitAuthorName = DateTime.MinValue;
}

return new(latestCommitAuthorName.ToString(), timeElapsed, latestCommitSHA.ToString());
return new(latestCommitAuthorName.ToString(), latestCommitDateTime, latestCommitSHA.ToString());
}
}

0 comments on commit 5a8051b

Please sign in to comment.