diff --git a/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs b/Octokit.Tests.Integration/Clients/ReleasesClientTests.cs index 0a114ae6..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 @@ -14,18 +15,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 +44,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 +64,18 @@ public class ReleasesClientTests readonly Repository _repository; readonly string _repositoryOwner; readonly string _repositoryName; - readonly GitHubClient _github; + readonly GitHubClient github; public TheEditMethod() { - _github = new GitHubClient(new ProductHeaderValue("OctokitTests")) + 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; } @@ -97,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); 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 @@ +