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

Implement Draft Pull Requests #2009

Merged
merged 5 commits into from
Sep 22, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions Octokit.Reactive/Clients/ObservablePullRequestsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public IObservable<PullRequest> GetAllForRepository(string owner, string name, A
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<PullRequest>(ApiUrls.PullRequests(owner, name), options);
return _connection.GetAndFlattenAllPages<PullRequest>(ApiUrls.PullRequests(owner, name), null, AcceptHeaders.DraftPullRequestApiPreview, options);
}

/// <summary>
Expand All @@ -126,7 +126,7 @@ public IObservable<PullRequest> GetAllForRepository(long repositoryId, ApiOption
{
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<PullRequest>(ApiUrls.PullRequests(repositoryId), options);
return _connection.GetAndFlattenAllPages<PullRequest>(ApiUrls.PullRequests(repositoryId), null, AcceptHeaders.DraftPullRequestApiPreview, options);
}

/// <summary>
Expand Down Expand Up @@ -180,7 +180,7 @@ public IObservable<PullRequest> GetAllForRepository(string owner, string name, P
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<PullRequest>(ApiUrls.PullRequests(owner, name),
request.ToParametersDictionary(), options);
request.ToParametersDictionary(), AcceptHeaders.DraftPullRequestApiPreview, options);
}

/// <summary>
Expand All @@ -198,7 +198,7 @@ public IObservable<PullRequest> GetAllForRepository(long repositoryId, PullReque
Ensure.ArgumentNotNull(options, nameof(options));

return _connection.GetAndFlattenAllPages<PullRequest>(ApiUrls.PullRequests(repositoryId),
request.ToParametersDictionary(), options);
request.ToParametersDictionary(), AcceptHeaders.DraftPullRequestApiPreview, options);
}

/// <summary>
Expand Down
54 changes: 54 additions & 0 deletions Octokit.Tests.Integration/Clients/PullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ public async Task CanCreate()
Assert.Equal("a pull request", result.Title);
}

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

var newPullRequest = new NewPullRequest("a draft pull request", branchName, "master") { Draft = true };
var result = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest);
Assert.Equal("a draft pull request", result.Title);
Assert.True(result.Draft);
}

[IntegrationTest]
public async Task CanCreateWithRepositoryId()
{
Expand All @@ -48,6 +59,17 @@ public async Task CanCreateWithRepositoryId()
Assert.Equal("a pull request", result.Title);
}

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

var newPullRequest = new NewPullRequest("a draft pull request", branchName, "master") { Draft = true };
var result = await _fixture.Create(_context.Repository.Id, newPullRequest);
Assert.Equal("a draft pull request", result.Title);
Assert.True(result.Draft);
}

[IntegrationTest]
public async Task CanGetForRepository()
{
Expand All @@ -63,6 +85,22 @@ public async Task CanGetForRepository()
Assert.True(pullRequests[0].Id > 0);
}

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

var newPullRequest = new NewPullRequest("a draft pull request", branchName, "master") { Draft = true };
var result = await _fixture.Create(Helper.UserName, _context.RepositoryName, newPullRequest);

var pullRequests = await _fixture.GetAllForRepository(Helper.UserName, _context.RepositoryName);

Assert.Equal(1, pullRequests.Count);
Assert.Equal(result.Title, pullRequests[0].Title);
Assert.Equal(result.Draft, pullRequests[0].Draft);
Assert.True(pullRequests[0].Id > 0);
}

[IntegrationTest]
public async Task CanGetForRepositoryWithRepositoryId()
{
Expand All @@ -77,6 +115,22 @@ public async Task CanGetForRepositoryWithRepositoryId()
Assert.Equal(result.Title, pullRequests[0].Title);
}

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

var newPullRequest = new NewPullRequest("a draft pull request", branchName, "master") { Draft = true };
var result = await _fixture.Create(_context.Repository.Id, newPullRequest);

var pullRequests = await _fixture.GetAllForRepository(_context.Repository.Id);

Assert.Equal(1, pullRequests.Count);
Assert.Equal(result.Title, pullRequests[0].Title);
Assert.Equal(result.Draft, pullRequests[0].Draft);
Assert.True(pullRequests[0].Id > 0);
}

[IntegrationTest]
public async Task CanGetWithAssigneesForRepository()
{
Expand Down
28 changes: 14 additions & 14 deletions Octokit.Tests/Clients/PullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task RequestsCorrectUrl()

await client.Get("fake", "repo", 42);

connection.Received().Get<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/42"));
connection.Received().Get<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/42"), Arg.Any<Dictionary<string, string>>(), "application/vnd.github.shadow-cat-preview+json");
}

[Fact]
Expand All @@ -29,7 +29,7 @@ public async Task RequestsCorrectUrlWithRepositoryId()

await client.Get(1, 42);

connection.Received().Get<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42"));
connection.Received().Get<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42"), Arg.Any<Dictionary<string, string>>(), "application/vnd.github.shadow-cat-preview+json");
}

[Fact]
Expand All @@ -56,7 +56,7 @@ public async Task RequestsCorrectUrl()
await client.GetAllForRepository("fake", "repo");

connection.Received().GetAll<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls"),
Arg.Any<Dictionary<string, string>>(), Args.ApiOptions);
Arg.Any<Dictionary<string, string>>(), "application/vnd.github.shadow-cat-preview+json", Args.ApiOptions);
}

[Fact]
Expand All @@ -68,7 +68,7 @@ public async Task RequestsCorrectUrlWithRepositoryId()
await client.GetAllForRepository(1);

connection.Received().GetAll<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls"),
Arg.Any<Dictionary<string, string>>(), Args.ApiOptions);
Arg.Any<Dictionary<string, string>>(), "application/vnd.github.shadow-cat-preview+json", Args.ApiOptions);
}

[Fact]
Expand All @@ -87,7 +87,7 @@ public async Task RequestsCorrectUrlWithApiOptions()
await client.GetAllForRepository("fake", "repo", options);

connection.Received().GetAll<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls"),
Arg.Any<Dictionary<string, string>>(), options);
Arg.Any<Dictionary<string, string>>(), "application/vnd.github.shadow-cat-preview+json", options);
}

[Fact]
Expand All @@ -106,7 +106,7 @@ public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId()
await client.GetAllForRepository(1, options);

connection.Received().GetAll<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls"),
Arg.Any<Dictionary<string, string>>(), options);
Arg.Any<Dictionary<string, string>>(), "application/vnd.github.shadow-cat-preview+json", options);
}

[Fact]
Expand All @@ -123,7 +123,7 @@ public async Task SendsAppropriateParameters()
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), Args.ApiOptions);
&& d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json", Args.ApiOptions);
}

[Fact]
Expand All @@ -140,7 +140,7 @@ public async Task SendsAppropriateParametersWithRepositoryId()
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), Args.ApiOptions);
&& d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json", Args.ApiOptions);
}

[Fact]
Expand All @@ -164,7 +164,7 @@ public async Task SendsAppropriateParametersWithApiOptions()
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), options);
&& d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json", options);
}

[Fact]
Expand All @@ -188,7 +188,7 @@ public async Task SendsAppropriateParametersWithApiOptionsWithRepositoryId()
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), options);
&& d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json", options);
}

[Fact]
Expand Down Expand Up @@ -243,7 +243,7 @@ public async Task PostsToCorrectUrl()
await client.Create("fake", "repo", newPullRequest);

connection.Received().Post<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls"),
newPullRequest);
newPullRequest, "application/vnd.github.shadow-cat-preview+json");
}

[Fact]
Expand All @@ -256,7 +256,7 @@ public async Task PostsToCorrectUrlWithRepositoryId()
await client.Create(1, newPullRequest);

connection.Received().Post<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls"),
newPullRequest);
newPullRequest, "application/vnd.github.shadow-cat-preview+json");
}

[Fact]
Expand Down Expand Up @@ -288,7 +288,7 @@ public async Task PostsToCorrectUrl()
await client.Update("fake", "repo", 42, pullRequestUpdate);

connection.Received().Patch<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pulls/42"),
pullRequestUpdate);
pullRequestUpdate, "application/vnd.github.shadow-cat-preview+json");
}

[Fact]
Expand All @@ -301,7 +301,7 @@ public async Task PostsToCorrectUrlWithRepositoryId()
await client.Update(1, 42, pullRequestUpdate);

connection.Received().Patch<PullRequest>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/pulls/42"),
pullRequestUpdate);
pullRequestUpdate, "application/vnd.github.shadow-cat-preview+json");
}

[Fact]
Expand Down
24 changes: 12 additions & 12 deletions Octokit.Tests/Reactive/ObservablePullRequestsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ public async Task ReturnsEveryPageOfPullRequests()
}
);
var gitHubClient = Substitute.For<IGitHubClient>();
gitHubClient.Connection.Get<List<PullRequest>>(firstPageUrl, Args.EmptyDictionary, null)
gitHubClient.Connection.Get<List<PullRequest>>(firstPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => firstPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(secondPageUrl, Args.EmptyDictionary, null)
gitHubClient.Connection.Get<List<PullRequest>>(secondPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => secondPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(thirdPageUrl, Args.EmptyDictionary, null)
gitHubClient.Connection.Get<List<PullRequest>>(thirdPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => lastPageResponse));
var client = new ObservablePullRequestsClient(gitHubClient);

Expand Down Expand Up @@ -262,11 +262,11 @@ public async Task ReturnsEveryPageOfPullRequestsWithRepositoryId()
}
);
var gitHubClient = Substitute.For<IGitHubClient>();
gitHubClient.Connection.Get<List<PullRequest>>(firstPageUrl, Args.EmptyDictionary, null)
gitHubClient.Connection.Get<List<PullRequest>>(firstPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => firstPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(secondPageUrl, Args.EmptyDictionary, null)
gitHubClient.Connection.Get<List<PullRequest>>(secondPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => secondPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(thirdPageUrl, Args.EmptyDictionary, null)
gitHubClient.Connection.Get<List<PullRequest>>(thirdPageUrl, Args.EmptyDictionary, "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => lastPageResponse));
var client = new ObservablePullRequestsClient(gitHubClient);

Expand Down Expand Up @@ -321,21 +321,21 @@ public async Task SendsAppropriateParametersMulti()
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), Arg.Any<string>())
&& d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => firstPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(secondPageUrl, Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["head"] == "user:ref-name"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), null)
&& d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => secondPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(thirdPageUrl, Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["head"] == "user:ref-name"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), null)
&& d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => lastPageResponse));
var client = new ObservablePullRequestsClient(gitHubClient);

Expand Down Expand Up @@ -390,21 +390,21 @@ public async Task SendsAppropriateParametersMultiWithRepositoryId()
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), Arg.Any<string>())
&& d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => firstPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(secondPageUrl, Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["head"] == "user:ref-name"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), null)
&& d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => secondPageResponse));
gitHubClient.Connection.Get<List<PullRequest>>(thirdPageUrl, Arg.Is<Dictionary<string, string>>(d => d.Count == 5
&& d["head"] == "user:ref-name"
&& d["state"] == "open"
&& d["base"] == "fake_base_branch"
&& d["sort"] == "created"
&& d["direction"] == "desc"), null)
&& d["direction"] == "desc"), "application/vnd.github.shadow-cat-preview+json")
.Returns(Task.Factory.StartNew<IApiResponse<List<PullRequest>>>(() => lastPageResponse));
var client = new ObservablePullRequestsClient(gitHubClient);

Expand Down
Loading