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

Commit e283f76

Browse files
Changes to support a default for GitLogEntry
1 parent fda7f6f commit e283f76

File tree

6 files changed

+346
-420
lines changed

6 files changed

+346
-420
lines changed

src/GitHub.Api/Git/GitLogEntry.cs

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

14-
public string CommitID;
15-
public string MergeA;
16-
public string MergeB;
17-
public string AuthorName;
18-
public string AuthorEmail;
19-
public string CommitEmail;
20-
public string CommitName;
21-
public string Summary;
22-
public string Description;
23-
public string TimeString;
24-
public string CommitTimeString;
25-
public List<GitStatusEntry> Changes;
26-
27-
public string ShortID
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);
15+
16+
public string commitID;
17+
public string mergeA;
18+
public string mergeB;
19+
public string authorName;
20+
public string authorEmail;
21+
public string commitEmail;
22+
public string commitName;
23+
public string summary;
24+
public string description;
25+
public string timeString;
26+
public string commitTimeString;
27+
public List<GitStatusEntry> changes;
28+
29+
public GitLogEntry(string commitID,
30+
string authorName, string authorEmail,
31+
string commitName, string commitEmail,
32+
string summary,
33+
string description,
34+
DateTimeOffset time, DateTimeOffset commitTime,
35+
List<GitStatusEntry> changes,
36+
string mergeA = null, string mergeB = null) : this()
2837
{
29-
get { return CommitID.Length < 7 ? CommitID : CommitID.Substring(0, 7); }
38+
Guard.ArgumentNotNull(commitID, "commitID");
39+
Guard.ArgumentNotNull(authorName, "authorName");
40+
Guard.ArgumentNotNull(authorEmail, "authorEmail");
41+
Guard.ArgumentNotNull(commitEmail, "commitEmail");
42+
Guard.ArgumentNotNull(commitName, "commitName");
43+
Guard.ArgumentNotNull(summary, "summary");
44+
Guard.ArgumentNotNull(description, "description");
45+
Guard.ArgumentNotNull(changes, "changes");
46+
47+
this.commitID = commitID;
48+
this.authorName = authorName;
49+
this.authorEmail = authorEmail;
50+
this.commitEmail = commitEmail;
51+
this.commitName = commitName;
52+
this.summary = summary;
53+
this.description = description;
54+
55+
Time = time;
56+
CommitTime = commitTime;
57+
58+
this.changes = changes;
59+
60+
this.mergeA = mergeA ?? string.Empty;
61+
this.mergeB = mergeB ?? string.Empty;
62+
}
63+
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;
3099
}
31100

32101
public string PrettyTimeString
@@ -49,37 +118,62 @@ public DateTimeOffset Time
49118
{
50119
if (!timeValue.HasValue)
51120
{
52-
timeValue = DateTimeOffset.Parse(TimeString);
121+
timeValue = DateTimeOffset.ParseExact(TimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None);
53122
}
54-
123+
55124
return timeValue.Value;
56125
}
126+
private set
127+
{
128+
timeString = value.ToString(Constants.Iso8601Format);
129+
timeValue = value;
130+
}
57131
}
58132

59133
[NonSerialized] private DateTimeOffset? commitTimeValue;
60-
public DateTimeOffset? CommitTime
134+
public DateTimeOffset CommitTime
61135
{
62136
get
63137
{
64-
if (!timeValue.HasValue && !string.IsNullOrEmpty(CommitTimeString))
138+
if (!commitTimeValue.HasValue)
65139
{
66-
commitTimeValue = DateTimeOffset.Parse(CommitTimeString);
140+
commitTimeValue = DateTimeOffset.ParseExact(CommitTimeString, Constants.Iso8601Format, CultureInfo.InvariantCulture, DateTimeStyles.None);
67141
}
68142

69-
return commitTimeValue;
143+
return commitTimeValue.Value;
144+
}
145+
private set
146+
{
147+
commitTimeString = value.ToString(Constants.Iso8601Format);
148+
commitTimeValue = value;
70149
}
71150
}
72151

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

77-
timeValue = DateTimeOffset.MinValue;
78-
TimeString = timeValue.Value.ToString(DateTimeFormatInfo.CurrentInfo);
154+
public string CommitID => commitID;
79155

80-
commitTimeValue = null;
81-
CommitTimeString = null;
82-
}
156+
public string MergeA => mergeA;
157+
158+
public string MergeB => mergeB;
159+
160+
public string AuthorName => authorName;
161+
162+
public string AuthorEmail => authorEmail;
163+
164+
public string CommitEmail => commitEmail;
165+
166+
public string CommitName => commitName;
167+
168+
public string Summary => summary;
169+
170+
public string Description => description;
171+
172+
public string TimeString => timeString;
173+
174+
public string CommitTimeString => commitTimeString;
175+
176+
public List<GitStatusEntry> Changes => changes;
83177

84178
public override string ToString()
85179
{

src/GitHub.Api/OutputProcessors/LogEntryOutputProcessor.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -317,21 +317,16 @@ private void ReturnGitLogEntry()
317317

318318
if (time.HasValue)
319319
{
320-
RaiseOnEntry(new GitLogEntry()
321-
{
322-
AuthorName = authorName,
323-
CommitName = committerName,
324-
MergeA = mergeA,
325-
MergeB = mergeB,
326-
Changes = changes,
327-
AuthorEmail = authorEmail,
328-
CommitEmail = committerEmail,
329-
Summary = summary,
330-
Description = description,
331-
CommitID = commitId,
332-
TimeString = time.Value.ToString(Constants.Iso8601Format),
333-
CommitTimeString = committerTime.Value.ToString(Constants.Iso8601Format)
334-
});
320+
var gitLogEntry = new GitLogEntry(commitId,
321+
authorName, authorEmail,
322+
committerName, committerEmail,
323+
summary,
324+
description,
325+
time.Value, committerTime.Value,
326+
changes,
327+
mergeA, mergeB);
328+
329+
RaiseOnEntry(gitLogEntry);
335330
}
336331

337332
Reset();

src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -42,42 +42,29 @@ public async Task LogEntriesTest()
4242

4343
logEntries.AssertEqual(new[]
4444
{
45-
new GitLogEntry
46-
{
47-
AuthorEmail = "[email protected]",
48-
CommitEmail = "[email protected]",
49-
AuthorName = "Author Person",
50-
CommitName = "Author Person",
51-
Changes = new List<GitStatusEntry>
45+
new GitLogEntry("018997938335742f8be694240a7c2b352ec0835f",
46+
"Author Person", "[email protected]", "Author Person",
47+
48+
"Moving project files where they should be kept",
49+
"Moving project files where they should be kept", firstCommitTime,
50+
firstCommitTime, new List<GitStatusEntry>
5251
{
5352
new GitStatusEntry("Assets/TestDocument.txt".ToNPath(),
5453
TestRepoMasterCleanUnsynchronized + "/Assets/TestDocument.txt".ToNPath(), "Assets/TestDocument.txt".ToNPath(),
5554
GitFileStatus.Renamed, "TestDocument.txt")
56-
},
57-
CommitID = "018997938335742f8be694240a7c2b352ec0835f",
58-
Description = "Moving project files where they should be kept",
59-
Summary = "Moving project files where they should be kept",
60-
TimeString = firstCommitTime.ToString(Constants.Iso8601Format),
61-
CommitTimeString = firstCommitTime.ToString(Constants.Iso8601Format),
62-
},
63-
new GitLogEntry
64-
{
65-
AuthorEmail = "[email protected]",
66-
CommitEmail = "[email protected]",
67-
AuthorName = "Author Person",
68-
CommitName = "Author Person",
69-
Changes = new List<GitStatusEntry>
55+
}),
56+
57+
new GitLogEntry("03939ffb3eb8486dba0259b43db00842bbe6eca1",
58+
"Author Person", "[email protected]", "Author Person",
59+
60+
"Initial Commit",
61+
"Initial Commit", secondCommitTime,
62+
secondCommitTime, new List<GitStatusEntry>
7063
{
7164
new GitStatusEntry("TestDocument.txt".ToNPath(),
7265
TestRepoMasterCleanUnsynchronized + "/TestDocument.txt".ToNPath(), "TestDocument.txt".ToNPath(),
7366
GitFileStatus.Added),
74-
},
75-
CommitID = "03939ffb3eb8486dba0259b43db00842bbe6eca1",
76-
Description = "Initial Commit",
77-
Summary = "Initial Commit",
78-
TimeString = secondCommitTime.ToString(Constants.Iso8601Format),
79-
CommitTimeString = secondCommitTime.ToString(Constants.Iso8601Format),
80-
},
67+
}),
8168
});
8269
}
8370

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

9683
logEntries.AssertEqual(new[]
9784
{
98-
new GitLogEntry
99-
{
100-
AuthorEmail = "[email protected]",
101-
CommitEmail = "[email protected]",
102-
AuthorName = "Author Person",
103-
CommitName = "Author Person",
104-
Changes = new List<GitStatusEntry>
85+
new GitLogEntry("06d6451d351626894a30e9134f551db12c74254b",
86+
"Author Person", "[email protected]", "Author Person",
87+
88+
"Я люблю github",
89+
"Я люблю github", commitTime,
90+
commitTime, new List<GitStatusEntry>
10591
{
10692
new GitStatusEntry(@"Assets\A new file.txt".ToNPath(),
10793
TestRepoMasterCleanUnsynchronizedRussianLanguage + "/Assets/A new file.txt".ToNPath(), "Assets/A new file.txt".ToNPath(),
10894
GitFileStatus.Added),
109-
},
110-
CommitID = "06d6451d351626894a30e9134f551db12c74254b",
111-
Description = "Я люблю github",
112-
Summary = "Я люблю github",
113-
TimeString = commitTime.ToString(Constants.Iso8601Format),
114-
CommitTimeString = commitTime.ToString(Constants.Iso8601Format),
115-
}
95+
}),
11696
});
11797
}
11898

0 commit comments

Comments
 (0)