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

Commit 5defe7b

Browse files
Merge pull request #989 from github-for-unity/fixes/api
Making the standalone api nicer to use
2 parents be609cf + 58a35fb commit 5defe7b

File tree

8 files changed

+119
-27
lines changed

8 files changed

+119
-27
lines changed

src/GitHub.Api/Helpers/SimpleJson.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2214,7 +2214,7 @@ private static string ToJsonPropertyName(string propertyName)
22142214
return propertyName.Substring(0, i).ToLowerInvariant() + propertyName.Substring(i);
22152215
}
22162216

2217-
class JsonSerializationStrategy : PocoJsonSerializerStrategy
2217+
public class JsonSerializationStrategy : PocoJsonSerializerStrategy
22182218
{
22192219
private bool toLowerCase = false;
22202220
private bool onlyPublic = true;

src/GitHub.Api/OutputProcessors/LogEntryOutputProcessor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Globalization;
4+
using System.Linq;
45
using System.Text;
56
using System.Text.RegularExpressions;
67

@@ -143,7 +144,6 @@ public override void LineReceived(string line)
143144
}
144145

145146
summary = line;
146-
descriptionLines.Add(line);
147147
phase++;
148148
// there's no description so skip it
149149
if (oneliner)
@@ -313,7 +313,8 @@ private void ReturnGitLogEntry()
313313
{
314314
PopNewlines();
315315

316-
var description = string.Join(Environment.NewLine, descriptionLines.ToArray());
316+
var filteredDescriptionLines = (descriptionLines.Any() && string.IsNullOrEmpty(descriptionLines.First()) ? descriptionLines.Skip(1) : descriptionLines).ToArray();
317+
var description = string.Join(Environment.NewLine, filteredDescriptionLines);
317318

318319
if (time.HasValue)
319320
{
@@ -347,4 +348,4 @@ private enum ProcessingPhase
347348
Files = 10,
348349
}
349350
}
350-
}
351+
}

src/GitHub.Api/Platform/DefaultEnvironment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void InitializeRepository(NPath? repositoryPath = null)
8383
Guard.NotNull(this, FileSystem, nameof(FileSystem));
8484

8585
NPath expectedRepositoryPath;
86-
if (!RepositoryPath.IsInitialized)
86+
if (!RepositoryPath.IsInitialized || (repositoryPath != null && RepositoryPath != repositoryPath.Value))
8787
{
8888
Guard.NotNull(this, UnityProjectPath, nameof(UnityProjectPath));
8989

src/GitHub.Api/Tasks/ActionTask.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace GitHub.Unity
99
{
10-
class TaskQueue : TPLTask
10+
public class TaskQueue : TPLTask
1111
{
1212
private TaskCompletionSource<bool> aggregateTask = new TaskCompletionSource<bool>();
1313
private readonly List<ITask> queuedTasks = new List<ITask>();
@@ -85,7 +85,7 @@ private void TaskFinished(bool success, Exception ex)
8585
}
8686
}
8787

88-
class TaskQueue<TTaskResult, TResult> : TPLTask<List<TResult>>
88+
public class TaskQueue<TTaskResult, TResult> : TPLTask<List<TResult>>
8989
{
9090
private TaskCompletionSource<List<TResult>> aggregateTask = new TaskCompletionSource<List<TResult>>();
9191
private readonly List<ITask<TTaskResult>> queuedTasks = new List<ITask<TTaskResult>>();
@@ -190,7 +190,7 @@ private void TaskFinished(TTaskResult result, bool success, Exception ex)
190190
}
191191
}
192192

193-
class TPLTask : TaskBase
193+
public class TPLTask : TaskBase
194194
{
195195
private Task task;
196196

@@ -235,7 +235,7 @@ protected override void Run(bool success)
235235
}
236236
}
237237

238-
class TPLTask<T> : TaskBase<T>
238+
public class TPLTask<T> : TaskBase<T>
239239
{
240240
private Task<T> task;
241241

@@ -280,7 +280,7 @@ protected override T RunWithReturn(bool success)
280280
}
281281
}
282282

283-
class ActionTask : TaskBase
283+
public class ActionTask : TaskBase
284284
{
285285
protected Action<bool> Callback { get; }
286286
protected Action<bool, Exception> CallbackWithException { get; }
@@ -329,7 +329,7 @@ protected override void Run(bool success)
329329
}
330330
}
331331

332-
class ActionTask<T> : TaskBase
332+
public class ActionTask<T> : TaskBase
333333
{
334334
private readonly Func<T> getPreviousResult;
335335

@@ -415,7 +415,7 @@ protected virtual void Run(bool success, T previousResult)
415415
public T PreviousResult { get; set; } = default(T);
416416
}
417417

418-
class FuncTask<T> : TaskBase<T>
418+
public class FuncTask<T> : TaskBase<T>
419419
{
420420
protected Func<bool, T> Callback { get; }
421421
protected Func<bool, Exception, T> CallbackWithException { get; }
@@ -468,7 +468,7 @@ protected override T RunWithReturn(bool success)
468468
}
469469
}
470470

471-
class FuncTask<T, TResult> : TaskBase<T, TResult>
471+
public class FuncTask<T, TResult> : TaskBase<T, TResult>
472472
{
473473
protected Func<bool, T, TResult> Callback { get; }
474474
protected Func<bool, Exception, T, TResult> CallbackWithException { get; }
@@ -513,7 +513,7 @@ protected override TResult RunWithData(bool success, T previousResult)
513513
}
514514
}
515515

516-
class FuncListTask<T> : DataTaskBase<T, List<T>>
516+
public class FuncListTask<T> : DataTaskBase<T, List<T>>
517517
{
518518
protected Func<bool, List<T>> Callback { get; }
519519
protected Func<bool, FuncListTask<T>, List<T>> CallbackWithSelf { get; }
@@ -573,7 +573,7 @@ protected override List<T> RunWithReturn(bool success)
573573
}
574574
}
575575

576-
class FuncListTask<T, TData, TResult> : DataTaskBase<T, TData, List<TResult>>
576+
public class FuncListTask<T, TData, TResult> : DataTaskBase<T, TData, List<TResult>>
577577
{
578578
protected Func<bool, T, List<TResult>> Callback { get; }
579579
protected Func<bool, Exception, T, List<TResult>> CallbackWithException { get; }

src/GitHub.Api/Tasks/TaskBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ public override string ToString()
547547
public virtual string Message { get; set; }
548548
}
549549

550-
abstract class TaskBase<TResult> : TaskBase, ITask<TResult>
550+
public abstract class TaskBase<TResult> : TaskBase, ITask<TResult>
551551
{
552552
private event Action<bool, TResult> finallyHandler;
553553

@@ -723,7 +723,7 @@ protected override void CallFinallyHandler()
723723
public TResult Result { get { return result; } }
724724
}
725725

726-
abstract class TaskBase<T, TResult> : TaskBase<TResult>
726+
public abstract class TaskBase<T, TResult> : TaskBase<TResult>
727727
{
728728
private readonly Func<T> getPreviousResult;
729729

@@ -770,7 +770,7 @@ protected virtual TResult RunWithData(bool success, T previousResult)
770770
public T PreviousResult { get; set; } = default(T);
771771
}
772772

773-
abstract class DataTaskBase<TData, TResult> : TaskBase<TResult>, ITask<TData, TResult>
773+
public abstract class DataTaskBase<TData, TResult> : TaskBase<TResult>, ITask<TData, TResult>
774774
{
775775
public DataTaskBase(CancellationToken token)
776776
: base(token)
@@ -783,7 +783,7 @@ protected void RaiseOnData(TData data)
783783
}
784784
}
785785

786-
abstract class DataTaskBase<T, TData, TResult> : TaskBase<T, TResult>, ITask<TData, TResult>
786+
public abstract class DataTaskBase<T, TData, TResult> : TaskBase<T, TResult>, ITask<TData, TResult>
787787
{
788788
public DataTaskBase(CancellationToken token)
789789
: base(token)

src/GitHub.Api/Tasks/TaskExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace GitHub.Unity
66
{
7-
static class TaskExtensions
7+
public static class TaskExtensions
88
{
99
public static async Task StartAwait(this ITask source, Action<Exception> handler = null)
1010
{

src/tests/IntegrationTests/Process/ProcessManagerIntegrationTests.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ public async Task LogEntriesTest()
4646
new GitLogEntry("018997938335742f8be694240a7c2b352ec0835f",
4747
"Author Person", "author@example.com", "Author Person",
4848
"author@example.com",
49-
"Moving project files where they should be kept",
50-
"Moving project files where they should be kept", firstCommitTime,
49+
"Moving project files where they should be kept",
50+
"",
51+
firstCommitTime,
5152
firstCommitTime, new List<GitStatusEntry>
5253
{
5354
new GitStatusEntry("Assets/TestDocument.txt".ToNPath(),
@@ -59,7 +60,8 @@ public async Task LogEntriesTest()
5960
"Author Person", "author@example.com", "Author Person",
6061
"author@example.com",
6162
"Initial Commit",
62-
"Initial Commit", secondCommitTime,
63+
"",
64+
secondCommitTime,
6365
secondCommitTime, new List<GitStatusEntry>
6466
{
6567
new GitStatusEntry("TestDocument.txt".ToNPath(),
@@ -87,7 +89,8 @@ public async Task RussianLogEntriesTest()
8789
"Author Person", "author@example.com", "Author Person",
8890
"author@example.com",
8991
"Я люблю github",
90-
"Я люблю github", commitTime,
92+
"",
93+
commitTime,
9194
commitTime, new List<GitStatusEntry>
9295
{
9396
new GitStatusEntry(@"Assets\A new file.txt".ToNPath(),

src/tests/UnitTests/IO/LogEntryOutputProcessorTests.cs

Lines changed: 91 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public void ShouldParseSingleCommit()
4646
{
4747
new GitLogEntry("1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf",
4848
"Author Person", "author@example.com",
49-
"Author Person", "author@example.com",
50-
"Rename RepositoryModelBase to RepositoryModel",
49+
"Author Person", "author@example.com",
5150
"Rename RepositoryModelBase to RepositoryModel",
51+
"",
5252
commitTime, commitTime,
5353
new List<GitStatusEntry>
5454
{
@@ -61,6 +61,94 @@ public void ShouldParseSingleCommit()
6161
AssertProcessOutput(output, expected);
6262
}
6363

64+
[Test]
65+
public void ShouldParseSummaryAndDescription()
66+
{
67+
var output = new[]
68+
{
69+
"1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf",
70+
"865b8d9d6e5e3bd6d7a4dc9c9f3588192314942c",
71+
"Author Person",
72+
"author@example.com",
73+
"2017-01-06T15:36:57+01:00",
74+
"Author Person",
75+
"author@example.com",
76+
"2017-01-06T15:36:57+01:00",
77+
"Rename RepositoryModelBase to RepositoryModel",
78+
"",
79+
"This is a line on the description",
80+
"---GHUBODYEND---",
81+
"M src/GitHub.App/Models/RemoteRepositoryModel.cs",
82+
null,
83+
};
84+
85+
var commitTime = new DateTimeOffset(2017, 1, 6, 15, 36, 57, TimeSpan.FromHours(1));
86+
87+
var expected = new[]
88+
{
89+
new GitLogEntry("1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf",
90+
"Author Person", "author@example.com",
91+
"Author Person", "author@example.com",
92+
"Rename RepositoryModelBase to RepositoryModel",
93+
"This is a line on the description",
94+
commitTime,
95+
commitTime,
96+
new List<GitStatusEntry>
97+
{
98+
new GitStatusEntry("src/GitHub.App/Models/RemoteRepositoryModel.cs",
99+
TestRootPath + @"\src/GitHub.App/Models/RemoteRepositoryModel.cs", null,
100+
GitFileStatus.Modified),
101+
})
102+
};
103+
104+
AssertProcessOutput(output, expected);
105+
}
106+
107+
[Test]
108+
public void ShouldParseSummaryAndDescriptionWithExtraNewLines()
109+
{
110+
var output = new[]
111+
{
112+
"1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf",
113+
"865b8d9d6e5e3bd6d7a4dc9c9f3588192314942c",
114+
"Author Person",
115+
"author@example.com",
116+
"2017-01-06T15:36:57+01:00",
117+
"Author Person",
118+
"author@example.com",
119+
"2017-01-06T15:36:57+01:00",
120+
"Rename RepositoryModelBase to RepositoryModel",
121+
"",
122+
"",
123+
"",
124+
"This is a line on the description",
125+
"---GHUBODYEND---",
126+
"M src/GitHub.App/Models/RemoteRepositoryModel.cs",
127+
null,
128+
};
129+
130+
var commitTime = new DateTimeOffset(2017, 1, 6, 15, 36, 57, TimeSpan.FromHours(1));
131+
132+
var expected = new[]
133+
{
134+
new GitLogEntry("1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf",
135+
"Author Person", "author@example.com",
136+
"Author Person", "author@example.com",
137+
"Rename RepositoryModelBase to RepositoryModel",
138+
Environment.NewLine + Environment.NewLine + "This is a line on the description",
139+
commitTime,
140+
commitTime,
141+
new List<GitStatusEntry>
142+
{
143+
new GitStatusEntry("src/GitHub.App/Models/RemoteRepositoryModel.cs",
144+
TestRootPath + @"\src/GitHub.App/Models/RemoteRepositoryModel.cs", null,
145+
GitFileStatus.Modified),
146+
})
147+
};
148+
149+
AssertProcessOutput(output, expected);
150+
}
151+
64152
private void AssertProcessOutput(IEnumerable<string> lines, GitLogEntry[] expected)
65153
{
66154
var gitObjectFactory = SubstituteFactory.CreateGitObjectFactory(TestRootPath);
@@ -77,4 +165,4 @@ private void AssertProcessOutput(IEnumerable<string> lines, GitLogEntry[] expect
77165
results.AssertEqual(expected);
78166
}
79167
}
80-
}
168+
}

0 commit comments

Comments
 (0)