mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 11:40:42 +00:00
Merge pull request #536 from octokit/releases-can-should-change-commitish
releases can/should change commitish
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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<TreeResponse> CreateTree(this IGitHubClient client, Repository repository, 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(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<Commit> 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<Reference> 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<string, string> { { "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<string, string> { { "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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -79,6 +79,7 @@
|
||||
<Compile Include="Clients\UserEmailsClientTests.cs" />
|
||||
<Compile Include="Clients\FollowersClientTests.cs" />
|
||||
<Compile Include="Clients\UserKeysClientTests.cs" />
|
||||
<Compile Include="Helpers\RepositorySetupHelper.cs" />
|
||||
<Compile Include="HttpClientAdapterTests.cs" />
|
||||
<Compile Include="Clients\TeamsClientTests.cs" />
|
||||
<Compile Include="IntegrationTestAttribute.cs" />
|
||||
|
||||
Reference in New Issue
Block a user