Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull-Request-Squash-Commit #1245

Merged
merged 9 commits into from
May 20, 2016
Merged
Show file tree
Hide file tree
Changes from 8 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
19 changes: 19 additions & 0 deletions Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,25 @@ public async Task CanBeMergedWithShaSpecified()
}

[IntegrationTest]
public async Task CanBeMergedWithSquashCommit()
{
await CreateTheWorld();

var newPullRequest = new NewPullRequest("squash commit pull request", branchName, "master");
var pullRequest = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest);

var merge = new MergePullRequest { CommitMessage = "fake commit message", CommitTitle = "fake title", Squash = true };
var result = await _fixture.Merge(Helper.UserName, _context.RepositoryName, pullRequest.Number, merge);
var commit = await _github.Repository.Commit.Get(_context.RepositoryOwner, _context.RepositoryName, result.Sha);
var message = commit.Commit.Message;
Assert.True(result.Merged);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we assert something here about the commit title or message versus what we actually committed, to indicate this was squashed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure i will add assert statement here. 😃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion - look at the commit:

var commit = await _github.Repository.Commit.Get(_context.RepositoryOwner, _context.RepositoryName, result.Sha);
// TODO: something interesting goes here
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Assert.Equal("fake title\n\nfake commit message", commit.Commit.Message);


}

[IntegrationTest]

public async Task CannotBeMergedDueMismatchConflict()
{
await CreateTheWorld();
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests/Clients/PullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public void PutsToCorrectUrl()
client.Merge("fake", "repo", 42, mergePullRequest);

connection.Received().Put<PullRequestMerge>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/42/merge"),
mergePullRequest);
mergePullRequest,null, "application/vnd.github.polaris-preview+json");
}

[Fact]
Expand Down
4 changes: 4 additions & 0 deletions Octokit.Tests/OctoKit.Tests-NetCore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@
<Project>{c8bc13b6-3fa3-4716-827d-e7706f976fe1}</Project>
<Name>Octokit-NetCore45</Name>
</ProjectReference>
<ProjectReference Include="..\Octokit\Octokit.csproj">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how this crept in, but this project reference shouldn't be needed 🔥 🔥 🔥

<Project>{08DD4305-7787-4823-A53F-4D0F725A07F3}</Project>
<Name>Octokit</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
Expand Down
3 changes: 2 additions & 1 deletion Octokit/Clients/PullRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public async Task<PullRequestMerge> Merge(string owner, string name, int number,
try
{
var endpoint = ApiUrls.MergePullRequest(owner, name, number);
return await ApiConnection.Put<PullRequestMerge>(endpoint, mergePullRequest).ConfigureAwait(false);
return await ApiConnection.Put<PullRequestMerge>(endpoint, mergePullRequest,null,
AcceptHeaders.SquashCommitPreview).ConfigureAwait(false);
}
catch (ApiException ex)
{
Expand Down
2 changes: 2 additions & 0 deletions Octokit/Helpers/AcceptHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ public static class AcceptHeaders
public const string IssueLockingUnlockingApiPreview = "application/vnd.github.the-key-preview+json";

public const string CommitReferenceSha1Preview = "application/vnd.github.chitauri-preview+sha";

public const string SquashCommitPreview = "application/vnd.github.polaris-preview+json";
}
}
12 changes: 11 additions & 1 deletion Octokit/Models/Request/MergePullRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ public class MergePullRequest
/// </summary>
public string Sha { get; set; }

/// <summary>
/// The Title for the automatic commit message (optional)
/// </summary>
public string CommitTitle { get; set; }

/// <summary>
/// Commit a single commit to the head branch (optional)
/// </summary>
public bool Squash { get; set; }

internal string DebuggerDisplay
{
get
{
return string.Format(CultureInfo.InvariantCulture, "Message: '{0}', Sha: '{1}'", CommitMessage, Sha);
return string.Format(CultureInfo.InvariantCulture, "Title: '{0}' Message: '{1}', Sha: '{2}' , Squash: '{3}'", CommitTitle, CommitMessage, Sha, Squash);
}
}
}
Expand Down