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

Commit e4b68dc

Browse files
Merge branch 'fixes/git-log-entry-default' into enhancements/history-list-view
2 parents 80627b9 + 742e048 commit e4b68dc

File tree

2 files changed

+38
-62
lines changed

2 files changed

+38
-62
lines changed

src/GitHub.Api/Git/GitLogEntry.cs

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public struct GitLogEntry
1111
private const string Today = "Today";
1212
private const string Yesterday = "Yesterday";
1313

14-
public static GitLogEntry Default = new GitLogEntry(String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, String.Empty, new List<GitStatusEntry>(), String.Empty, String.Empty);
14+
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);
1515

1616
public string commitID;
1717
public string mergeA;
@@ -61,43 +61,6 @@ public GitLogEntry(string commitID,
6161
this.mergeB = mergeB ?? string.Empty;
6262
}
6363

64-
public GitLogEntry(string commitID,
65-
string authorName, string authorEmail,
66-
string commitName, string commitEmail,
67-
string summary,
68-
string description,
69-
string timeString, string commitTimeString,
70-
List<GitStatusEntry> changes,
71-
string mergeA = null, string mergeB = null) : this()
72-
{
73-
Guard.ArgumentNotNull(commitID, "commitID");
74-
Guard.ArgumentNotNull(authorName, "authorName");
75-
Guard.ArgumentNotNull(authorEmail, "authorEmail");
76-
Guard.ArgumentNotNull(commitEmail, "commitEmail");
77-
Guard.ArgumentNotNull(commitName, "commitName");
78-
Guard.ArgumentNotNull(summary, "summary");
79-
Guard.ArgumentNotNull(description, "description");
80-
Guard.ArgumentNotNull(timeString, "timeString");
81-
Guard.ArgumentNotNull(commitTimeString, "commitTimeString");
82-
Guard.ArgumentNotNull(changes, "changes");
83-
84-
this.commitID = commitID;
85-
this.authorName = authorName;
86-
this.authorEmail = authorEmail;
87-
this.commitEmail = commitEmail;
88-
this.commitName = commitName;
89-
this.summary = summary;
90-
this.description = description;
91-
92-
this.timeString = timeString;
93-
this.commitTimeString = commitTimeString;
94-
95-
this.changes = changes;
96-
97-
this.mergeA = mergeA ?? string.Empty;
98-
this.mergeB = mergeB ?? string.Empty;
99-
}
100-
10164
public string PrettyTimeString
10265
{
10366
get
@@ -118,7 +81,15 @@ public DateTimeOffset Time
11881
{
11982
if (!timeValue.HasValue)
12083
{
121-
timeValue = DateTimeOffset.ParseExact(TimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None);
84+
DateTimeOffset result;
85+
if (DateTimeOffset.TryParseExact(TimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture,DateTimeStyles.None, out result))
86+
{
87+
timeValue = result;
88+
}
89+
else
90+
{
91+
Time = DateTimeOffset.MinValue;
92+
}
12293
}
12394

12495
return timeValue.Value;
@@ -137,7 +108,15 @@ public DateTimeOffset CommitTime
137108
{
138109
if (!commitTimeValue.HasValue)
139110
{
140-
commitTimeValue = DateTimeOffset.ParseExact(CommitTimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None);
111+
DateTimeOffset result;
112+
if (DateTimeOffset.TryParseExact(CommitTimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None, out result))
113+
{
114+
commitTimeValue = result;
115+
}
116+
else
117+
{
118+
CommitTime = DateTimeOffset.MinValue;
119+
}
141120
}
142121

143122
return commitTimeValue.Value;

src/tests/UnitTests/IO/GitLogEntryListTests.cs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ public void ListOf1ShouldEqualListOf1()
8585
"Summary",
8686
"Description",
8787
commitTime, commitTime,
88-
new List<GitStatusEntry>(new[]
88+
new List<GitStatusEntry>
8989
{
90-
new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added,
91-
"SomeOriginalPath"),
92-
}),
90+
new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"),
91+
},
9392
"MergeA", "MergeB")
9493
};
9594

@@ -125,11 +124,10 @@ public void ListOf2ShouldEqualListOf2()
125124
"AuthorName", "AuthorEmail",
126125
"Summary", "Description",
127126
commitTime, commitTime,
128-
new List<GitStatusEntry>(new[]
127+
new List<GitStatusEntry>
129128
{
130-
new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added,
131-
"SomeOriginalPath"),
132-
}),
129+
new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath"),
130+
},
133131
"MergeA", "MergeB"),
134132
new GitLogEntry("`CommitID",
135133
"`AuthorName", "`AuthorEmail",
@@ -143,28 +141,27 @@ public void ListOf2ShouldEqualListOf2()
143141

144142
var otherEntries = new[]
145143
{
146-
new GitLogEntry("`CommitID",
147-
"`AuthorName", "`AuthorEmail",
148-
"`AuthorName", "`AuthorEmail",
149-
"`Summary",
150-
"`Description",
151-
commitTime, commitTime,
152-
new List<GitStatusEntry>(new[]
153-
{
154-
new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added,
155-
"SomeOriginalPath"),
156-
}),
157-
"`MergeA", "`MergeB"),
158144
new GitLogEntry("CommitID",
159145
"AuthorName", "AuthorEmail",
160146
"AuthorName", "AuthorEmail",
161147
"Summary",
162148
"Description",
163149
commitTime, commitTime,
164-
new List<GitStatusEntry>(),
165-
"MergeA", "MergeB")
150+
new List<GitStatusEntry> {
151+
new GitStatusEntry("SomePath", "SomeFullPath", "SomeProjectPath", GitFileStatus.Added, "SomeOriginalPath")
152+
},
153+
"MergeA", "MergeB"),
154+
new GitLogEntry("`CommitID",
155+
"`AuthorName", "`AuthorEmail",
156+
"`AuthorName", "`AuthorEmail",
157+
"`Summary",
158+
"`Description",
159+
commitTime, commitTime,
160+
new List<GitStatusEntry>(),
161+
"`MergeA", "`MergeB")
166162
};
167163

164+
168165
entries.AssertEqual(otherEntries);
169166
}
170167

0 commit comments

Comments
 (0)