Skip to content

Commit

Permalink
change to use pull request URL with media type to retrieve diff
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegKleyman committed Sep 2, 2015
1 parent 0251532 commit ec6a92b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/OctoStyle.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public static void Main(string[] args)

var builder = new PullRequestBuilder(new DiffParser());
var pullRequestRetriever = new PullRequestRetriever(builder, client.PullRequest, client.Connection, repository);

var con = new Connection(new ProductHeaderValue("OctoStyle"),
new InMemoryCredentialStore(new Credentials(arguments.Login, arguments.Password)));

var pullRequest = pullRequestRetriever.RetrieveAsync(arguments.PullRequestNumber).GetAwaiter().GetResult();

foreach (var file in pullRequest.Files)
Expand Down
2 changes: 1 addition & 1 deletion src/OctoStyle.Core/PullRequestRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public async Task<GitHubPullRequest> RetrieveAsync(int number)

var files = await this.client.Files(this.repository.Owner, this.repository.Name, number);
var pull = await this.client.Get(this.repository.Owner, this.repository.Name, number);
var diff = await this.connection.Get<string>(pull.DiffUrl, null, null);
var diff = await this.connection.Get<string>(pull.Url, null, "application/vnd.github.VERSION.diff");

return this.builder.Build(
number,
Expand Down
15 changes: 10 additions & 5 deletions tests/unit/OctoStyle.Core.Tests.Unit/PullRequestRetrieverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,21 @@ private static IPullRequestRetriever GetPullRequestRetriever()
client.Setup(requestsClient => requestsClient.Files(repository.Owner, repository.Name, PullRequestNumber))
.ReturnsAsync(files);

var diffUrl =
var pullRequestUrl =
new Uri(
String.Format(
CultureInfo.InvariantCulture,
"http://github.com/{0}/{1}/pull/{2}",
"https://api.github.com/repos/{0}/{1}/pulls/{2}",
repository.Owner,
repository.Name,
PullRequestNumber));

client.Setup(requestsClient => requestsClient.Get(repository.Owner, repository.Name, PullRequestNumber))
.ReturnsAsync(
new PullRequest(
pullRequestUrl,
null,
null,
diffUrl,
null,
null,
null,
Expand Down Expand Up @@ -167,7 +167,11 @@ private static IPullRequestRetriever GetPullRequestRetriever()
var mockResponse = new Mock<IResponse>();

connection.Setup(
con => con.Get<string>(It.Is<Uri>(uri => uri.AbsoluteUri == diffUrl.AbsoluteUri), null, null))
con =>
con.Get<string>(
It.Is<Uri>(uri => uri.AbsoluteUri == pullRequestUrl.AbsoluteUri),
null,
"application/vnd.github.VERSION.diff"))
.ReturnsAsync(new ApiResponse<string>(mockResponse.Object, FileContents.FullDiff));

var pullRequestFiles = new List<GitHubPullRequestFile>
Expand Down Expand Up @@ -210,7 +214,8 @@ private static IPullRequestRetriever GetPullRequestRetriever()
FileContents.FullDiff,
It.Is<GitHubPullRequestBranches>(
branches =>
branches.Branch == PullRequestBranch & branches.MergeBranch == PullRequestMergeBranch))).Returns(pullRequest);
branches.Branch == PullRequestBranch & branches.MergeBranch == PullRequestMergeBranch)))
.Returns(pullRequest);

return new PullRequestRetriever(builder.Object, client.Object, connection.Object, repository);
}
Expand Down

0 comments on commit ec6a92b

Please sign in to comment.