Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Changes to support a default for GitLogEntry #522

Merged
merged 4 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 102 additions & 29 deletions src/GitHub.Api/Git/GitLogEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,54 @@ public struct GitLogEntry
private const string Today = "Today";
private const string Yesterday = "Yesterday";

public string CommitID;
public string MergeA;
public string MergeB;
public string AuthorName;
public string AuthorEmail;
public string CommitEmail;
public string CommitName;
public string Summary;
public string Description;
public string TimeString;
public string CommitTimeString;
public List<GitStatusEntry> Changes;

public string ShortID
public static GitLogEntry Default = new GitLogEntry(String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, DateTimeOffset.MinValue, DateTimeOffset.MinValue, new List<GitStatusEntry>(), String.Empty, String.Empty);

public string commitID;
public string mergeA;
public string mergeB;
public string authorName;
public string authorEmail;
public string commitEmail;
public string commitName;
public string summary;
public string description;
public string timeString;
public string commitTimeString;
public List<GitStatusEntry> changes;

public GitLogEntry(string commitID,
string authorName, string authorEmail,
string commitName, string commitEmail,
string summary,
string description,
DateTimeOffset time, DateTimeOffset commitTime,
List<GitStatusEntry> changes,
string mergeA = null, string mergeB = null) : this()
{
get { return CommitID.Length < 7 ? CommitID : CommitID.Substring(0, 7); }
Guard.ArgumentNotNull(commitID, "commitID");
Guard.ArgumentNotNull(authorName, "authorName");
Guard.ArgumentNotNull(authorEmail, "authorEmail");
Guard.ArgumentNotNull(commitEmail, "commitEmail");
Guard.ArgumentNotNull(commitName, "commitName");
Guard.ArgumentNotNull(summary, "summary");
Guard.ArgumentNotNull(description, "description");
Guard.ArgumentNotNull(changes, "changes");

this.commitID = commitID;
this.authorName = authorName;
this.authorEmail = authorEmail;
this.commitEmail = commitEmail;
this.commitName = commitName;
this.summary = summary;
this.description = description;

Time = time;
CommitTime = commitTime;

this.changes = changes;

this.mergeA = mergeA ?? string.Empty;
this.mergeB = mergeB ?? string.Empty;
}

public string PrettyTimeString
Expand All @@ -49,37 +81,78 @@ public DateTimeOffset Time
{
if (!timeValue.HasValue)
{
timeValue = DateTimeOffset.Parse(TimeString);
DateTimeOffset result;
if (DateTimeOffset.TryParseExact(TimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture,DateTimeStyles.None, out result))
{
timeValue = result;
}
else
{
Time = DateTimeOffset.MinValue;
}
}

return timeValue.Value;
}
private set
{
timeString = value.ToString(Constants.Iso8601Format);
timeValue = value;
}
}

[NonSerialized] private DateTimeOffset? commitTimeValue;
public DateTimeOffset? CommitTime
public DateTimeOffset CommitTime
{
get
{
if (!timeValue.HasValue && !string.IsNullOrEmpty(CommitTimeString))
if (!commitTimeValue.HasValue)
{
commitTimeValue = DateTimeOffset.Parse(CommitTimeString);
DateTimeOffset result;
if (DateTimeOffset.TryParseExact(CommitTimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
{
commitTimeValue = result;
}
else
{
CommitTime = DateTimeOffset.MinValue;
}
}

return commitTimeValue;
return commitTimeValue.Value;
}
private set
{
commitTimeString = value.ToString(Constants.Iso8601Format);
commitTimeValue = value;
}
}

public void Clear()
{
CommitID = MergeA = MergeB = AuthorName = AuthorEmail = Summary = Description = "";
public string ShortID => CommitID.Length < 7 ? CommitID : CommitID.Substring(0, 7);

timeValue = DateTimeOffset.MinValue;
TimeString = timeValue.Value.ToString(DateTimeFormatInfo.CurrentInfo);
public string CommitID => commitID;

commitTimeValue = null;
CommitTimeString = null;
}
public string MergeA => mergeA;

public string MergeB => mergeB;

public string AuthorName => authorName;

public string AuthorEmail => authorEmail;

public string CommitEmail => commitEmail;

public string CommitName => commitName;

public string Summary => summary;

public string Description => description;

public string TimeString => timeString;

public string CommitTimeString => commitTimeString;

public List<GitStatusEntry> Changes => changes;

public override string ToString()
{
Expand Down
25 changes: 10 additions & 15 deletions src/GitHub.Api/OutputProcessors/LogEntryOutputProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,16 @@ private void ReturnGitLogEntry()

if (time.HasValue)
{
RaiseOnEntry(new GitLogEntry()
{
AuthorName = authorName,
CommitName = committerName,
MergeA = mergeA,
MergeB = mergeB,
Changes = changes,
AuthorEmail = authorEmail,
CommitEmail = committerEmail,
Summary = summary,
Description = description,
CommitID = commitId,
TimeString = time.Value.ToString(Constants.Iso8601Format),
CommitTimeString = committerTime.Value.ToString(Constants.Iso8601Format)
});
var gitLogEntry = new GitLogEntry(commitId,
authorName, authorEmail,
committerName, committerEmail,
summary,
description,
time.Value, committerTime.Value,
changes,
mergeA, mergeB);

RaiseOnEntry(gitLogEntry);
}

Reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,42 +42,29 @@ public async Task LogEntriesTest()

logEntries.AssertEqual(new[]
{
new GitLogEntry
{
AuthorEmail = "author@example.com",
CommitEmail = "author@example.com",
AuthorName = "Author Person",
CommitName = "Author Person",
Changes = new List<GitStatusEntry>
new GitLogEntry("018997938335742f8be694240a7c2b352ec0835f",
"Author Person", "author@example.com", "Author Person",
"author@example.com",
"Moving project files where they should be kept",
"Moving project files where they should be kept", firstCommitTime,
firstCommitTime, new List<GitStatusEntry>
{
new GitStatusEntry("Assets/TestDocument.txt".ToNPath(),
TestRepoMasterCleanUnsynchronized + "/Assets/TestDocument.txt".ToNPath(), "Assets/TestDocument.txt".ToNPath(),
GitFileStatus.Renamed, "TestDocument.txt")
},
CommitID = "018997938335742f8be694240a7c2b352ec0835f",
Description = "Moving project files where they should be kept",
Summary = "Moving project files where they should be kept",
TimeString = firstCommitTime.ToString(Constants.Iso8601Format),
CommitTimeString = firstCommitTime.ToString(Constants.Iso8601Format),
},
new GitLogEntry
{
AuthorEmail = "author@example.com",
CommitEmail = "author@example.com",
AuthorName = "Author Person",
CommitName = "Author Person",
Changes = new List<GitStatusEntry>
}),

new GitLogEntry("03939ffb3eb8486dba0259b43db00842bbe6eca1",
"Author Person", "author@example.com", "Author Person",
"author@example.com",
"Initial Commit",
"Initial Commit", secondCommitTime,
secondCommitTime, new List<GitStatusEntry>
{
new GitStatusEntry("TestDocument.txt".ToNPath(),
TestRepoMasterCleanUnsynchronized + "/TestDocument.txt".ToNPath(), "TestDocument.txt".ToNPath(),
GitFileStatus.Added),
},
CommitID = "03939ffb3eb8486dba0259b43db00842bbe6eca1",
Description = "Initial Commit",
Summary = "Initial Commit",
TimeString = secondCommitTime.ToString(Constants.Iso8601Format),
CommitTimeString = secondCommitTime.ToString(Constants.Iso8601Format),
},
}),
});
}

Expand All @@ -95,24 +82,17 @@ public async Task RussianLogEntriesTest()

logEntries.AssertEqual(new[]
{
new GitLogEntry
{
AuthorEmail = "author@example.com",
CommitEmail = "author@example.com",
AuthorName = "Author Person",
CommitName = "Author Person",
Changes = new List<GitStatusEntry>
new GitLogEntry("06d6451d351626894a30e9134f551db12c74254b",
"Author Person", "author@example.com", "Author Person",
"author@example.com",
"Я люблю github",
"Я люблю github", commitTime,
commitTime, new List<GitStatusEntry>
{
new GitStatusEntry(@"Assets\A new file.txt".ToNPath(),
TestRepoMasterCleanUnsynchronizedRussianLanguage + "/Assets/A new file.txt".ToNPath(), "Assets/A new file.txt".ToNPath(),
GitFileStatus.Added),
},
CommitID = "06d6451d351626894a30e9134f551db12c74254b",
Description = "Я люблю github",
Summary = "Я люблю github",
TimeString = commitTime.ToString(Constants.Iso8601Format),
CommitTimeString = commitTime.ToString(Constants.Iso8601Format),
}
}),
});
}

Expand Down
Loading