From 69279caaf4023eaeb2aeeab0619938504de8638d Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Fri, 11 Jul 2014 09:54:55 +0930 Subject: [PATCH 1/3] :lipstick: test code --- .../Clients/ReleasesClientTests.cs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs b/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs index 0a114ae6..e6d9199b 100644 --- a/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs @@ -14,18 +14,17 @@ public class ReleasesClientTests readonly Repository _repository; readonly string _repositoryOwner; readonly string _repositoryName; - readonly GitHubClient _github; public TheGetReleasesMethod() { - _github = new GitHubClient(new ProductHeaderValue("OctokitTests")) + var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; - _releaseClient = _github.Release; + _releaseClient = github.Release; var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = _github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; + _repository = github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; _repositoryOwner = _repository.Owner.Login; _repositoryName = _repository.Name; } @@ -44,7 +43,7 @@ public class ReleasesClientTests { // create a release without a publish date var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true }; - var release = _releaseClient.Create(_repositoryOwner, _repositoryName, releaseWithNoUpdate).Result; + await _releaseClient.Create(_repositoryOwner, _repositoryName, releaseWithNoUpdate); var releases = await _releaseClient.GetAll(_repositoryOwner, _repositoryName); @@ -64,18 +63,17 @@ public class ReleasesClientTests readonly Repository _repository; readonly string _repositoryOwner; readonly string _repositoryName; - readonly GitHubClient _github; public TheEditMethod() { - _github = new GitHubClient(new ProductHeaderValue("OctokitTests")) + var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; - _releaseClient = _github.Release; + _releaseClient = github.Release; var repoName = Helper.MakeNameWithTimestamp("public-repo"); - _repository = _github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; + _repository = github.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result; _repositoryOwner = _repository.Owner.Login; _repositoryName = _repository.Name; } From 94b05e4579e45053a6dbf6a1d31301bd61e55d0e Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Fri, 11 Jul 2014 10:04:11 +0930 Subject: [PATCH 2/3] introduced test helper for creating repository data --- .../Helpers/RepositorySetupHelper.cs | 61 +++++++++++++++++++ .../Octokit.Tests.Integration.csproj | 1 + 2 files changed, 62 insertions(+) create mode 100644 Octokit.Tests.Integration/Helpers/RepositorySetupHelper.cs diff --git a/Octokit.Tests.Integration/Helpers/RepositorySetupHelper.cs b/Octokit.Tests.Integration/Helpers/RepositorySetupHelper.cs new file mode 100644 index 00000000..97db3c00 --- /dev/null +++ b/Octokit.Tests.Integration/Helpers/RepositorySetupHelper.cs @@ -0,0 +1,61 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit.Tests.Integration.Helpers +{ + public static class RepositorySetupHelper + { + public static async Task CreateTree(this IGitHubClient client, Repository repository, IEnumerable> treeContents) + { + var collection = new List(); + + foreach (var c in treeContents) + { + var baselineBlob = new NewBlob + { + Content = c.Value, + Encoding = EncodingType.Utf8 + }; + var baselineBlobResult = await client.GitDatabase.Blob.Create(repository.Owner.Login, repository.Name, baselineBlob); + + collection.Add(new NewTreeItem + { + Type = TreeType.Blob, + Mode = FileMode.File, + Path = c.Key, + Sha = baselineBlobResult.Sha + }); + } + + var newTree = new NewTree { Tree = collection }; + + return await client.GitDatabase.Tree.Create(repository.Owner.Login, repository.Name, newTree); + } + + public static async Task CreateCommit(this IGitHubClient client, Repository repository, string message, string sha, string parent) + { + var newCommit = new NewCommit(message, sha, parent); + return await client.GitDatabase.Commit.Create(repository.Owner.Login, repository.Name, newCommit); + } + + public static async Task CreateTheWorld(this IGitHubClient client, Repository repository) + { + var master = await client.GitDatabase.Reference.Get(repository.Owner.Login, repository.Name, "heads/master"); + + // create new commit for master branch + var newMasterTree = await client.CreateTree(repository, new Dictionary { { "README.md", "Hello World!" } }); + var newMaster = await client.CreateCommit(repository, "baseline for pull request", newMasterTree.Sha, master.Object.Sha); + + // update master + await client.GitDatabase.Reference.Update(repository.Owner.Login, repository.Name, "heads/master", new ReferenceUpdate(newMaster.Sha)); + + // create new commit for feature branch + var featureBranchTree = await client.CreateTree(repository, new Dictionary { { "README.md", "I am overwriting this blob with something new" } }); + var featureBranchCommit = await client.CreateCommit(repository, "this is the commit to merge into the pull request", featureBranchTree.Sha, newMaster.Sha); + + // create branch + return await client.GitDatabase.Reference.Create(repository.Owner.Login, repository.Name, new NewReference("refs/heads/my-branch", featureBranchCommit.Sha)); + } + + } +} diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 824137cb..6710f1fa 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -79,6 +79,7 @@ + From c25b6f021087cabda80063d7e11172c7fd3c0785 Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Fri, 11 Jul 2014 10:08:51 +0930 Subject: [PATCH 3/3] added test to ensure you can change the targetcommitish field --- .../Clients/ReleasesClientTests.cs | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs b/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs index e6d9199b..4e087057 100644 --- a/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; using Octokit; using Octokit.Tests.Integration; +using Octokit.Tests.Integration.Helpers; using Xunit; public class ReleasesClientTests @@ -63,10 +64,11 @@ public class ReleasesClientTests readonly Repository _repository; readonly string _repositoryOwner; readonly string _repositoryName; + readonly GitHubClient github; public TheEditMethod() { - var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) + github = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials }; @@ -95,6 +97,28 @@ public class ReleasesClientTests Assert.Equal("**This is an updated release", updatedRelease.Body); } + + [IntegrationTest] + public async Task CanChangeCommitIshOfRelease() + { + var releaseWithNoUpdate = new ReleaseUpdate("0.1") { Draft = true }; + var release = await _releaseClient.Create(_repositoryOwner, _repositoryName, releaseWithNoUpdate); + + Assert.Equal("master", release.TargetCommitish); + + var newHead = await github.CreateTheWorld(_repository); + + var editRelease = release.ToUpdate(); + editRelease.Draft = false; + editRelease.TargetCommitish = newHead.Object.Sha; + + var updatedRelease = await _releaseClient.Edit(_repositoryOwner, _repositoryName, release.Id, editRelease); + + Assert.Equal(release.Id, updatedRelease.Id); + Assert.False(updatedRelease.Draft); + Assert.Equal(newHead.Object.Sha, updatedRelease.TargetCommitish); + } + public void Dispose() { Helper.DeleteRepo(_repository);