Fixed broken conventions. Wrote a integrationstests that performs an actual merge between two branches.

This commit is contained in:
Lars Tabro Sørensen
2015-01-31 23:15:26 +01:00
parent 150e38a264
commit 7a6b988f8a
16 changed files with 176 additions and 41 deletions

View File

@@ -0,0 +1,19 @@
using System;
namespace Octokit.Reactive
{
public interface IObservableMergingClient
{
/// <summary>
/// Create a merge for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/repos/merging/#perform-a-merge
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="merge">The merge to create</param>
/// <returns></returns>
IObservable<Merge> Create(string owner, string name, NewMerge merge);
}
}

View File

@@ -133,6 +133,14 @@ namespace Octokit.Reactive
/// </remarks> /// </remarks>
IObservableRepositoryContentsClient Content { get; } IObservableRepositoryContentsClient Content { get; }
/// <summary>
/// Client for GitHub's Repository Merging API
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/merging/">Merging API documentation</a> for more details
///</remarks>
IObservableMergingClient Merging { get; }
/// <summary> /// <summary>
/// Gets all the branches for the specified repository. /// Gets all the branches for the specified repository.
/// </summary> /// </summary>

View File

@@ -0,0 +1,31 @@
using System;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
public class ObservableMergingClient : IObservableMergingClient
{
readonly IMergingClient _client;
public ObservableMergingClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Repository.Merging;
}
/// <summary>
/// Create a merge for a given repository
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/repos/merging/#perform-a-merge
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="merge">The merge to create</param>
/// <returns></returns>
public IObservable<Merge> Create(string owner, string name, NewMerge merge)
{
return _client.Create(owner, name, merge).ToObservable();
}
}
}

View File

@@ -28,6 +28,7 @@ namespace Octokit.Reactive
Commits = new ObservableRepositoryCommitsClient(client); Commits = new ObservableRepositoryCommitsClient(client);
DeployKeys = new ObservableRepositoryDeployKeysClient(client); DeployKeys = new ObservableRepositoryDeployKeysClient(client);
Content = new ObservableRepositoryContentsClient(client); Content = new ObservableRepositoryContentsClient(client);
Merging = new ObservableMergingClient(client);
} }
/// <summary> /// <summary>
@@ -196,6 +197,15 @@ namespace Octokit.Reactive
/// </remarks> /// </remarks>
public IObservableRepositoryContentsClient Content { get; private set; } public IObservableRepositoryContentsClient Content { get; private set; }
/// <summary>
/// Client for GitHub's Repository Merging API
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/merging/">Merging API documentation</a> for more details
///</remarks>
public IObservableMergingClient Merging { get; private set; }
/// <summary> /// <summary>
/// Gets all the branches for the specified repository. /// Gets all the branches for the specified repository.
/// </summary> /// </summary>

View File

@@ -150,6 +150,8 @@
<Compile Include="Clients\ObservableUserKeysClient.cs" /> <Compile Include="Clients\ObservableUserKeysClient.cs" />
<Compile Include="Clients\IObservableRepositoryContentsClient.cs" /> <Compile Include="Clients\IObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\ObservableRepositoryContentsClient.cs" /> <Compile Include="Clients\ObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\IObservableMergingClient.cs" />
<Compile Include="Clients\ObservableMergingClient.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@@ -159,6 +159,8 @@
<Compile Include="Clients\ObservableUserKeysClient.cs" /> <Compile Include="Clients\ObservableUserKeysClient.cs" />
<Compile Include="Clients\IObservableRepositoryContentsClient.cs" /> <Compile Include="Clients\IObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\ObservableRepositoryContentsClient.cs" /> <Compile Include="Clients\ObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\IObservableMergingClient.cs" />
<Compile Include="Clients\ObservableMergingClient.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@@ -154,6 +154,8 @@
<Compile Include="Clients\ObservableUserKeysClient.cs" /> <Compile Include="Clients\ObservableUserKeysClient.cs" />
<Compile Include="Clients\IObservableRepositoryContentsClient.cs" /> <Compile Include="Clients\IObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\ObservableRepositoryContentsClient.cs" /> <Compile Include="Clients\ObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\IObservableMergingClient.cs" />
<Compile Include="Clients\ObservableMergingClient.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@@ -74,10 +74,12 @@
<Compile Include="..\SolutionInfo.cs"> <Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link> <Link>Properties\SolutionInfo.cs</Link>
</Compile> </Compile>
<Compile Include="Clients\IObservableMergingClient.cs" />
<Compile Include="Clients\IObservableOauthClient.cs" /> <Compile Include="Clients\IObservableOauthClient.cs" />
<Compile Include="Clients\IObservableRepositoryCommitsClients.cs" /> <Compile Include="Clients\IObservableRepositoryCommitsClients.cs" />
<Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" /> <Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\IObservableUserKeysClient.cs" /> <Compile Include="Clients\IObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableMergingClient.cs" />
<Compile Include="Clients\ObservableRepositoryDeployKeysClient.cs" /> <Compile Include="Clients\ObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\ObservableOauthClient.cs" /> <Compile Include="Clients\ObservableOauthClient.cs" />
<Compile Include="Clients\IObservableRepositoryContentsClient.cs" /> <Compile Include="Clients\IObservableRepositoryContentsClient.cs" />

View File

@@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Octokit; using Octokit;
using Octokit.Tests.Integration; using Octokit.Tests.Integration;
@@ -10,7 +11,8 @@ public class MergingClientTests : IDisposable
readonly Repository _repository; readonly Repository _repository;
readonly string _owner; readonly string _owner;
readonly IMergingClient _fixture; readonly IMergingClient _fixture;
readonly ICommitsClient _commitsClient;
const string branchName = "my-branch";
public MergingClientTests() public MergingClientTests()
{ {
@@ -20,8 +22,7 @@ public class MergingClientTests : IDisposable
}; };
var repoName = Helper.MakeNameWithTimestamp("public-repo"); var repoName = Helper.MakeNameWithTimestamp("public-repo");
_fixture = _client.GitDatabase.Merging; _fixture = _client.Repository.Merging;
_commitsClient = _client.GitDatabase.Commit;
_repository = _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; _repository = _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result;
_owner = _repository.Owner.Login; _owner = _repository.Owner.Login;
} }
@@ -29,33 +30,70 @@ public class MergingClientTests : IDisposable
[IntegrationTest] [IntegrationTest]
public async Task CanCreateMerge() public async Task CanCreateMerge()
{ {
var blob = new NewBlob await CreateTheWorld();
{
Content = "Hello World!",
Encoding = EncodingType.Utf8
};
var blobResult = await _client.GitDatabase.Blob.Create(_owner, _repository.Name, blob);
var newTree = new NewTree(); var newMerge = new NewMerge("master", branchName, "merge commit to master from integrationtests");
newTree.Tree.Add(new NewTreeItem
{
Type = TreeType.Blob,
Mode = FileMode.File,
Path = "README.md",
Sha = blobResult.Sha
});
var treeResult = await _client.GitDatabase.Tree.Create(_owner, _repository.Name, newTree);
var newCommit = new NewCommit("test-commit", treeResult.Sha);
var commit = await _commitsClient.Create(_owner, _repository.Name, newCommit);
Assert.NotNull(commit);
var newMerge = new NewMerge("master", commit.Sha, "merge commit to master from integrationtests");
var merge = await _fixture.Create(_owner, _repository.Name, newMerge); var merge = await _fixture.Create(_owner, _repository.Name, newMerge);
Assert.NotNull(merge); Assert.NotNull(merge);
Assert.NotNull(merge.Commit);
Assert.Equal("merge commit to master from integrationtests", merge.Commit.Message);
}
async Task CreateTheWorld()
{
var master = await _client.GitDatabase.Reference.Get(Helper.UserName, _repository.Name, "heads/master");
// create new commit for master branch
var newMasterTree = await CreateTree(new Dictionary<string, string> { { "README.md", "Hello World! I want to be overwritten by featurebranch!" } });
var newMaster = await CreateCommit("baseline for merge", newMasterTree.Sha, master.Object.Sha);
// update master
await _client.GitDatabase.Reference.Update(Helper.UserName, _repository.Name, "heads/master", new ReferenceUpdate(newMaster.Sha));
// create new commit for feature branch
var featureBranchTree = await CreateTree(new Dictionary<string, string> { { "README.md", "I am overwriting this blob with something new" } });
var featureBranchCommit = await CreateCommit("this is the commit to merge", featureBranchTree.Sha, newMaster.Sha);
// create branch
await _client.GitDatabase.Reference.Create(Helper.UserName, _repository.Name, new NewReference("refs/heads/my-branch", featureBranchCommit.Sha));
}
async Task<TreeResponse> CreateTree(IEnumerable<KeyValuePair<string, string>> treeContents)
{
var collection = new List<NewTreeItem>();
foreach (var c in treeContents)
{
var baselineBlob = new NewBlob
{
Content = c.Value,
Encoding = EncodingType.Utf8
};
var baselineBlobResult = await _client.GitDatabase.Blob.Create(Helper.UserName, _repository.Name, baselineBlob);
collection.Add(new NewTreeItem
{
Type = TreeType.Blob,
Mode = FileMode.File,
Path = c.Key,
Sha = baselineBlobResult.Sha
});
}
var newTree = new NewTree();
foreach (var item in collection)
{
newTree.Tree.Add(item);
}
return await _client.GitDatabase.Tree.Create(Helper.UserName, _repository.Name, newTree);
}
async Task<Commit> CreateCommit(string message, string sha, string parent)
{
var newCommit = new NewCommit(message, sha, parent);
return await _client.GitDatabase.Commit.Create(Helper.UserName, _repository.Name, newCommit);
} }
public void Dispose() public void Dispose()

View File

@@ -262,5 +262,7 @@ II.2.12 &lt;HandlesEvent /&gt;&#xD;
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String> <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticReadonly/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpFileLayoutPatternsUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary> </wpf:ResourceDictionary>

View File

@@ -19,7 +19,6 @@
Tree = new TreesClient(apiConnection); Tree = new TreesClient(apiConnection);
Tag = new TagsClient(apiConnection); Tag = new TagsClient(apiConnection);
Commit = new CommitsClient(apiConnection); Commit = new CommitsClient(apiConnection);
Merging = new MergingClient(apiConnection);
Reference = new ReferencesClient(apiConnection); Reference = new ReferencesClient(apiConnection);
} }
@@ -27,7 +26,6 @@
public ITreesClient Tree { get; private set; } public ITreesClient Tree { get; private set; }
public ITagsClient Tag { get; private set; } public ITagsClient Tag { get; private set; }
public ICommitsClient Commit { get; private set; } public ICommitsClient Commit { get; private set; }
public IMergingClient Merging { get; private set; }
public IReferencesClient Reference { get; private set; } public IReferencesClient Reference { get; private set; }
} }
} }

View File

@@ -12,7 +12,6 @@
ITagsClient Tag { get; } ITagsClient Tag { get; }
ITreesClient Tree { get; } ITreesClient Tree { get; }
ICommitsClient Commit { get; } ICommitsClient Commit { get; }
IMergingClient Merging { get; }
IReferencesClient Reference { get; } IReferencesClient Reference { get; }
} }
} }

View File

@@ -6,11 +6,25 @@ namespace Octokit
[DebuggerDisplay("{DebuggerDisplay,nq}")] [DebuggerDisplay("{DebuggerDisplay,nq}")]
public class Merge : GitReference public class Merge : GitReference
{ {
public string Message { get; set; } public Merge() { }
public Signature Author { get; set; }
public Signature Committer { get; set; } public Merge(Author author, Author committer, Commit commit, IEnumerable<GitReference> parents, string commentsUrl, int commentCount, string htmlUrl)
public GitReference Tree { get; set; } {
public IEnumerable<GitReference> Parents { get; set; } Author = author;
public int CommentCount { get; set; } Committer = committer;
Commit = commit;
Parents = parents;
CommentsUrl = commentsUrl;
CommentCount = commentCount;
HtmlUrl = htmlUrl;
}
public Author Author { get; protected set; }
public Author Committer { get; protected set; }
public Commit Commit { get; protected set; }
public IEnumerable<GitReference> Parents { get; protected set; }
public string CommentsUrl { get; protected set; }
public int CommentCount { get; protected set; }
public string HtmlUrl { get; protected set; }
} }
} }

View File

@@ -67,9 +67,11 @@
<Compile Include="Clients\IGitDatabaseClient.cs" /> <Compile Include="Clients\IGitDatabaseClient.cs" />
<Compile Include="Clients\IIssueCommentsClient.cs" /> <Compile Include="Clients\IIssueCommentsClient.cs" />
<Compile Include="Clients\IIssuesEventsClient.cs" /> <Compile Include="Clients\IIssuesEventsClient.cs" />
<Compile Include="Clients\IMergingClient.cs" />
<Compile Include="Clients\IssueCommentsClient.cs" /> <Compile Include="Clients\IssueCommentsClient.cs" />
<Compile Include="Clients\IssuesClient.cs" /> <Compile Include="Clients\IssuesClient.cs" />
<Compile Include="Clients\IssuesEventsClient.cs" /> <Compile Include="Clients\IssuesEventsClient.cs" />
<Compile Include="Clients\MergingClient.cs" />
<Compile Include="Clients\ITagsClient.cs" /> <Compile Include="Clients\ITagsClient.cs" />
<Compile Include="Clients\ITreesClient.cs" /> <Compile Include="Clients\ITreesClient.cs" />
<Compile Include="Clients\MilestonesClient.cs" /> <Compile Include="Clients\MilestonesClient.cs" />
@@ -89,6 +91,7 @@
<Compile Include="Models\Request\NewBlob.cs" /> <Compile Include="Models\Request\NewBlob.cs" />
<Compile Include="Models\Request\NewCommit.cs" /> <Compile Include="Models\Request\NewCommit.cs" />
<Compile Include="Models\Request\NewCommitStatus.cs" /> <Compile Include="Models\Request\NewCommitStatus.cs" />
<Compile Include="Models\Request\NewMerge.cs" />
<Compile Include="Models\Request\NewMilestone.cs" /> <Compile Include="Models\Request\NewMilestone.cs" />
<Compile Include="Models\Request\NewPullRequest.cs" /> <Compile Include="Models\Request\NewPullRequest.cs" />
<Compile Include="Models\Request\NewTag.cs" /> <Compile Include="Models\Request\NewTag.cs" />
@@ -111,6 +114,7 @@
<Compile Include="Models\Response\IssueComment.cs" /> <Compile Include="Models\Response\IssueComment.cs" />
<Compile Include="Models\Response\IssueEvent.cs" /> <Compile Include="Models\Response\IssueEvent.cs" />
<Compile Include="Models\Response\Label.cs" /> <Compile Include="Models\Response\Label.cs" />
<Compile Include="Models\Response\Merge.cs" />
<Compile Include="Models\Response\Milestone.cs" /> <Compile Include="Models\Response\Milestone.cs" />
<Compile Include="Models\Request\NewIssue.cs" /> <Compile Include="Models\Request\NewIssue.cs" />
<Compile Include="Models\Response\Notification.cs" /> <Compile Include="Models\Response\Notification.cs" />

View File

@@ -62,9 +62,11 @@
<Compile Include="Clients\IGitDatabaseClient.cs" /> <Compile Include="Clients\IGitDatabaseClient.cs" />
<Compile Include="Clients\IIssueCommentsClient.cs" /> <Compile Include="Clients\IIssueCommentsClient.cs" />
<Compile Include="Clients\IIssuesEventsClient.cs" /> <Compile Include="Clients\IIssuesEventsClient.cs" />
<Compile Include="Clients\IMergingClient.cs" />
<Compile Include="Clients\IssueCommentsClient.cs" /> <Compile Include="Clients\IssueCommentsClient.cs" />
<Compile Include="Clients\IssuesClient.cs" /> <Compile Include="Clients\IssuesClient.cs" />
<Compile Include="Clients\IssuesEventsClient.cs" /> <Compile Include="Clients\IssuesEventsClient.cs" />
<Compile Include="Clients\MergingClient.cs" />
<Compile Include="Clients\ITagsClient.cs" /> <Compile Include="Clients\ITagsClient.cs" />
<Compile Include="Clients\ITreesClient.cs" /> <Compile Include="Clients\ITreesClient.cs" />
<Compile Include="Clients\MilestonesClient.cs" /> <Compile Include="Clients\MilestonesClient.cs" />
@@ -84,6 +86,7 @@
<Compile Include="Models\Request\NewBlob.cs" /> <Compile Include="Models\Request\NewBlob.cs" />
<Compile Include="Models\Request\NewCommit.cs" /> <Compile Include="Models\Request\NewCommit.cs" />
<Compile Include="Models\Request\NewCommitStatus.cs" /> <Compile Include="Models\Request\NewCommitStatus.cs" />
<Compile Include="Models\Request\NewMerge.cs" />
<Compile Include="Models\Request\NewMilestone.cs" /> <Compile Include="Models\Request\NewMilestone.cs" />
<Compile Include="Models\Request\NewPullRequest.cs" /> <Compile Include="Models\Request\NewPullRequest.cs" />
<Compile Include="Models\Request\NewTag.cs" /> <Compile Include="Models\Request\NewTag.cs" />
@@ -108,6 +111,7 @@
<Compile Include="Models\Response\IssueComment.cs" /> <Compile Include="Models\Response\IssueComment.cs" />
<Compile Include="Models\Response\IssueEvent.cs" /> <Compile Include="Models\Response\IssueEvent.cs" />
<Compile Include="Models\Response\Label.cs" /> <Compile Include="Models\Response\Label.cs" />
<Compile Include="Models\Response\Merge.cs" />
<Compile Include="Models\Response\Milestone.cs" /> <Compile Include="Models\Response\Milestone.cs" />
<Compile Include="Models\Request\NewIssue.cs" /> <Compile Include="Models\Request\NewIssue.cs" />
<Compile Include="Models\Response\Notification.cs" /> <Compile Include="Models\Response\Notification.cs" />

View File

@@ -3,11 +3,11 @@ using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
[assembly: AssemblyProductAttribute("Octokit")] [assembly: AssemblyProductAttribute("Octokit")]
[assembly: AssemblyVersionAttribute("0.6.2")] [assembly: AssemblyVersionAttribute("0.6.3")]
[assembly: AssemblyFileVersionAttribute("0.6.2")] [assembly: AssemblyFileVersionAttribute("0.6.3")]
[assembly: ComVisibleAttribute(false)] [assembly: ComVisibleAttribute(false)]
namespace System { namespace System {
internal static class AssemblyVersionInformation { internal static class AssemblyVersionInformation {
internal const string Version = "0.6.2"; internal const string Version = "0.6.3";
} }
} }