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

Making the standalone api nicer to use #989

Merged
merged 9 commits into from
Jan 23, 2019
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
2 changes: 1 addition & 1 deletion src/GitHub.Api/Helpers/SimpleJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@ private static string ToJsonPropertyName(string propertyName)
return propertyName.Substring(0, i).ToLowerInvariant() + propertyName.Substring(i);
}

class JsonSerializationStrategy : PocoJsonSerializerStrategy
public class JsonSerializationStrategy : PocoJsonSerializerStrategy
{
private bool toLowerCase = false;
private bool onlyPublic = true;
Expand Down
7 changes: 4 additions & 3 deletions src/GitHub.Api/OutputProcessors/LogEntryOutputProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -143,7 +144,6 @@ public override void LineReceived(string line)
}

summary = line;
descriptionLines.Add(line);
phase++;
// there's no description so skip it
if (oneliner)
Expand Down Expand Up @@ -313,7 +313,8 @@ private void ReturnGitLogEntry()
{
PopNewlines();

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

if (time.HasValue)
{
Expand Down Expand Up @@ -347,4 +348,4 @@ private enum ProcessingPhase
Files = 10,
}
}
}
}
2 changes: 1 addition & 1 deletion src/GitHub.Api/Platform/DefaultEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void InitializeRepository(NPath? repositoryPath = null)
Guard.NotNull(this, FileSystem, nameof(FileSystem));

NPath expectedRepositoryPath;
if (!RepositoryPath.IsInitialized)
if (!RepositoryPath.IsInitialized || (repositoryPath != null && RepositoryPath != repositoryPath.Value))
{
Guard.NotNull(this, UnityProjectPath, nameof(UnityProjectPath));

Expand Down
20 changes: 10 additions & 10 deletions src/GitHub.Api/Tasks/ActionTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace GitHub.Unity
{
class TaskQueue : TPLTask
public class TaskQueue : TPLTask
{
private TaskCompletionSource<bool> aggregateTask = new TaskCompletionSource<bool>();
private readonly List<ITask> queuedTasks = new List<ITask>();
Expand Down Expand Up @@ -85,7 +85,7 @@ private void TaskFinished(bool success, Exception ex)
}
}

class TaskQueue<TTaskResult, TResult> : TPLTask<List<TResult>>
public class TaskQueue<TTaskResult, TResult> : TPLTask<List<TResult>>
{
private TaskCompletionSource<List<TResult>> aggregateTask = new TaskCompletionSource<List<TResult>>();
private readonly List<ITask<TTaskResult>> queuedTasks = new List<ITask<TTaskResult>>();
Expand Down Expand Up @@ -190,7 +190,7 @@ private void TaskFinished(TTaskResult result, bool success, Exception ex)
}
}

class TPLTask : TaskBase
public class TPLTask : TaskBase
{
private Task task;

Expand Down Expand Up @@ -235,7 +235,7 @@ protected override void Run(bool success)
}
}

class TPLTask<T> : TaskBase<T>
public class TPLTask<T> : TaskBase<T>
{
private Task<T> task;

Expand Down Expand Up @@ -280,7 +280,7 @@ protected override T RunWithReturn(bool success)
}
}

class ActionTask : TaskBase
public class ActionTask : TaskBase
{
protected Action<bool> Callback { get; }
protected Action<bool, Exception> CallbackWithException { get; }
Expand Down Expand Up @@ -329,7 +329,7 @@ protected override void Run(bool success)
}
}

class ActionTask<T> : TaskBase
public class ActionTask<T> : TaskBase
{
private readonly Func<T> getPreviousResult;

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

class FuncTask<T> : TaskBase<T>
public class FuncTask<T> : TaskBase<T>
{
protected Func<bool, T> Callback { get; }
protected Func<bool, Exception, T> CallbackWithException { get; }
Expand Down Expand Up @@ -468,7 +468,7 @@ protected override T RunWithReturn(bool success)
}
}

class FuncTask<T, TResult> : TaskBase<T, TResult>
public class FuncTask<T, TResult> : TaskBase<T, TResult>
{
protected Func<bool, T, TResult> Callback { get; }
protected Func<bool, Exception, T, TResult> CallbackWithException { get; }
Expand Down Expand Up @@ -513,7 +513,7 @@ protected override TResult RunWithData(bool success, T previousResult)
}
}

class FuncListTask<T> : DataTaskBase<T, List<T>>
public class FuncListTask<T> : DataTaskBase<T, List<T>>
{
protected Func<bool, List<T>> Callback { get; }
protected Func<bool, FuncListTask<T>, List<T>> CallbackWithSelf { get; }
Expand Down Expand Up @@ -573,7 +573,7 @@ protected override List<T> RunWithReturn(bool success)
}
}

class FuncListTask<T, TData, TResult> : DataTaskBase<T, TData, List<TResult>>
public class FuncListTask<T, TData, TResult> : DataTaskBase<T, TData, List<TResult>>
{
protected Func<bool, T, List<TResult>> Callback { get; }
protected Func<bool, Exception, T, List<TResult>> CallbackWithException { get; }
Expand Down
8 changes: 4 additions & 4 deletions src/GitHub.Api/Tasks/TaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public override string ToString()
public virtual string Message { get; set; }
}

abstract class TaskBase<TResult> : TaskBase, ITask<TResult>
public abstract class TaskBase<TResult> : TaskBase, ITask<TResult>
{
private event Action<bool, TResult> finallyHandler;

Expand Down Expand Up @@ -723,7 +723,7 @@ protected override void CallFinallyHandler()
public TResult Result { get { return result; } }
}

abstract class TaskBase<T, TResult> : TaskBase<TResult>
public abstract class TaskBase<T, TResult> : TaskBase<TResult>
{
private readonly Func<T> getPreviousResult;

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

abstract class DataTaskBase<TData, TResult> : TaskBase<TResult>, ITask<TData, TResult>
public abstract class DataTaskBase<TData, TResult> : TaskBase<TResult>, ITask<TData, TResult>
{
public DataTaskBase(CancellationToken token)
: base(token)
Expand All @@ -783,7 +783,7 @@ protected void RaiseOnData(TData data)
}
}

abstract class DataTaskBase<T, TData, TResult> : TaskBase<T, TResult>, ITask<TData, TResult>
public abstract class DataTaskBase<T, TData, TResult> : TaskBase<T, TResult>, ITask<TData, TResult>
{
public DataTaskBase(CancellationToken token)
: base(token)
Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.Api/Tasks/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace GitHub.Unity
{
static class TaskExtensions
public static class TaskExtensions
{
public static async Task StartAwait(this ITask source, Action<Exception> handler = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public async Task LogEntriesTest()
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,
"Moving project files where they should be kept",
"",
firstCommitTime,
firstCommitTime, new List<GitStatusEntry>
{
new GitStatusEntry("Assets/TestDocument.txt".ToNPath(),
Expand All @@ -59,7 +60,8 @@ public async Task LogEntriesTest()
"Author Person", "author@example.com", "Author Person",
"author@example.com",
"Initial Commit",
"Initial Commit", secondCommitTime,
"",
secondCommitTime,
secondCommitTime, new List<GitStatusEntry>
{
new GitStatusEntry("TestDocument.txt".ToNPath(),
Expand Down Expand Up @@ -87,7 +89,8 @@ public async Task RussianLogEntriesTest()
"Author Person", "author@example.com", "Author Person",
"author@example.com",
"Я люблю github",
"Я люблю github", commitTime,
"",
commitTime,
commitTime, new List<GitStatusEntry>
{
new GitStatusEntry(@"Assets\A new file.txt".ToNPath(),
Expand Down
94 changes: 91 additions & 3 deletions src/tests/UnitTests/IO/LogEntryOutputProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public void ShouldParseSingleCommit()
{
new GitLogEntry("1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf",
"Author Person", "author@example.com",
"Author Person", "author@example.com",
"Rename RepositoryModelBase to RepositoryModel",
"Author Person", "author@example.com",
"Rename RepositoryModelBase to RepositoryModel",
"",
commitTime, commitTime,
new List<GitStatusEntry>
{
Expand All @@ -61,6 +61,94 @@ public void ShouldParseSingleCommit()
AssertProcessOutput(output, expected);
}

[Test]
public void ShouldParseSummaryAndDescription()
{
var output = new[]
{
"1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf",
"865b8d9d6e5e3bd6d7a4dc9c9f3588192314942c",
"Author Person",
"author@example.com",
"2017-01-06T15:36:57+01:00",
"Author Person",
"author@example.com",
"2017-01-06T15:36:57+01:00",
"Rename RepositoryModelBase to RepositoryModel",
"",
"This is a line on the description",
"---GHUBODYEND---",
"M src/GitHub.App/Models/RemoteRepositoryModel.cs",
null,
};

var commitTime = new DateTimeOffset(2017, 1, 6, 15, 36, 57, TimeSpan.FromHours(1));

var expected = new[]
{
new GitLogEntry("1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf",
"Author Person", "author@example.com",
"Author Person", "author@example.com",
"Rename RepositoryModelBase to RepositoryModel",
"This is a line on the description",
commitTime,
commitTime,
new List<GitStatusEntry>
{
new GitStatusEntry("src/GitHub.App/Models/RemoteRepositoryModel.cs",
TestRootPath + @"\src/GitHub.App/Models/RemoteRepositoryModel.cs", null,
GitFileStatus.Modified),
})
};

AssertProcessOutput(output, expected);
}

[Test]
public void ShouldParseSummaryAndDescriptionWithExtraNewLines()
{
var output = new[]
{
"1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf",
"865b8d9d6e5e3bd6d7a4dc9c9f3588192314942c",
"Author Person",
"author@example.com",
"2017-01-06T15:36:57+01:00",
"Author Person",
"author@example.com",
"2017-01-06T15:36:57+01:00",
"Rename RepositoryModelBase to RepositoryModel",
"",
"",
"",
"This is a line on the description",
"---GHUBODYEND---",
"M src/GitHub.App/Models/RemoteRepositoryModel.cs",
null,
};

var commitTime = new DateTimeOffset(2017, 1, 6, 15, 36, 57, TimeSpan.FromHours(1));

var expected = new[]
{
new GitLogEntry("1cd4b9154a88bc8c7b09cb8cacc79bf1d5bde8cf",
"Author Person", "author@example.com",
"Author Person", "author@example.com",
"Rename RepositoryModelBase to RepositoryModel",
Environment.NewLine + Environment.NewLine + "This is a line on the description",
commitTime,
commitTime,
new List<GitStatusEntry>
{
new GitStatusEntry("src/GitHub.App/Models/RemoteRepositoryModel.cs",
TestRootPath + @"\src/GitHub.App/Models/RemoteRepositoryModel.cs", null,
GitFileStatus.Modified),
})
};

AssertProcessOutput(output, expected);
}

private void AssertProcessOutput(IEnumerable<string> lines, GitLogEntry[] expected)
{
var gitObjectFactory = SubstituteFactory.CreateGitObjectFactory(TestRootPath);
Expand All @@ -77,4 +165,4 @@ private void AssertProcessOutput(IEnumerable<string> lines, GitLogEntry[] expect
results.AssertEqual(expected);
}
}
}
}