Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into check-runs
Browse files Browse the repository at this point in the history
# Conflicts:
#	Octokit.Reactive/Clients/IObservableChecksClient.cs
#	Octokit.Reactive/Clients/ObservableChecksClient.cs
#	Octokit.Tests/Reactive/ObservableCheckSuitesClientTests.cs
#	Octokit/Clients/ChecksClient.cs
#	Octokit/Clients/IChecksClient.cs
#	Octokit/Helpers/ApiUrls.cs
#	Octokit/Models/Common/CheckStatus.cs
  • Loading branch information
ryangribble committed Jul 14, 2018
2 parents 9396bae + 4df21a6 commit 412358b
Show file tree
Hide file tree
Showing 13 changed files with 467 additions and 17 deletions.
21 changes: 21 additions & 0 deletions Octokit.Reactive/Clients/IObservableProjectCardsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ public interface IObservableProjectCardsClient
/// <param name="options">Options for changing the API response</param>
IObservable<ProjectCard> GetAll(int columnId, ApiOptions options);

/// <summary>
/// Gets all cards.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/projects/#list-projects-cards">API documentation</a> for more information.
/// </remarks>
/// <param name="columnId">The id of the column</param>
/// <param name="request">Used to filter the list of project cards returned</param>
IObservable<ProjectCard> GetAll(int columnId, ProjectCardRequest request);

/// <summary>
/// Gets all cards.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/projects/#list-projects-cards">API documentation</a> for more information.
/// </remarks>
/// <param name="columnId">The id of the column</param>
/// <param name="request">Used to filter the list of project cards returned</param>
/// <param name="options">Options for changing the API response</param>
IObservable<ProjectCard> GetAll(int columnId, ProjectCardRequest request, ApiOptions options);

/// <summary>
/// Gets a single card.
/// </summary>
Expand Down
35 changes: 33 additions & 2 deletions Octokit.Reactive/Clients/ObservableProjectCardsClient.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Octokit.Reactive.Internal;
using System;
using System.Reactive.Threading.Tasks;
using System.Collections.Generic;

namespace Octokit.Reactive
{
Expand Down Expand Up @@ -48,9 +47,41 @@ public IObservable<ProjectCard> GetAll(int columnId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));

return GetAll(columnId, new ProjectCardRequest(), options);
}

/// <summary>
/// Gets all cards.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/projects/#list-projects-cards">API documentation</a> for more information.
/// </remarks>
/// <param name="columnId">The id of the column</param>
/// <param name="request">Used to filter the list of project cards returned</param>
public IObservable<ProjectCard> GetAll(int columnId, ProjectCardRequest request)
{
Ensure.ArgumentNotNull(request, nameof(request));

return GetAll(columnId, request, ApiOptions.None);
}

/// <summary>
/// Gets all cards.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/projects/#list-projects-cards">API documentation</a> for more information.
/// </remarks>
/// <param name="columnId">The id of the column</param>
/// <param name="request">Used to filter the list of project cards returned</param>
/// <param name="options">Options for changing the API response</param>
public IObservable<ProjectCard> GetAll(int columnId, ProjectCardRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));

var url = ApiUrls.ProjectCards(columnId);

return _connection.GetAndFlattenAllPages<ProjectCard>(url, new Dictionary<string, string>(), AcceptHeaders.ProjectsApiPreview, options);
return _connection.GetAndFlattenAllPages<ProjectCard>(url, request.ToParametersDictionary(), AcceptHeaders.ProjectsApiPreview, options);
}

/// <summary>
Expand Down
105 changes: 100 additions & 5 deletions Octokit.Tests.Integration/Clients/ProjectCardsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
using Octokit.Tests.Integration;
using Octokit.Tests.Integration.Helpers;
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Xunit;

Expand Down Expand Up @@ -33,8 +31,57 @@ public async Task GetsAllCards()
var result = await _github.Repository.Project.Card.GetAll(column.Id);

Assert.Equal(2, result.Count);
Assert.True(result.FirstOrDefault(x => x.Id == card1.Id).Id == card1.Id);
Assert.True(result.FirstOrDefault(x => x.Id == card2.Id).Id == card2.Id);
Assert.Contains(result, x => x.Id == card1.Id);
Assert.Contains(result, x => x.Id == card2.Id);
}

[IntegrationTest]
public async Task GetsAllArchivedCards()
{
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card1 = await CreateCardHelper(_github, column.Id);
var card2 = await CreateArchivedCardHelper(_github, column.Id);

var request = new ProjectCardRequest(ProjectCardArchivedStateFilter.Archived);

var result = await _github.Repository.Project.Card.GetAll(column.Id, request);

Assert.Equal(1, result.Count);
Assert.Contains(result, x => x.Id == card2.Id);
}

[IntegrationTest]
public async Task GetsAllNotArchivedCards()
{
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card1 = await CreateCardHelper(_github, column.Id);
var card2 = await CreateArchivedCardHelper(_github, column.Id);

var request = new ProjectCardRequest(ProjectCardArchivedStateFilter.NotArchived);

var result = await _github.Repository.Project.Card.GetAll(column.Id, request);

Assert.Equal(1, result.Count);
Assert.Contains(result, x => x.Id == card1.Id);
}

[IntegrationTest]
public async Task GetsAllArchivedAndNotArchivedCards()
{
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card1 = await CreateCardHelper(_github, column.Id);
var card2 = await CreateArchivedCardHelper(_github, column.Id);

var request = new ProjectCardRequest(ProjectCardArchivedStateFilter.All);

var result = await _github.Repository.Project.Card.GetAll(column.Id, request);

Assert.Equal(2, result.Count);
Assert.Contains(result, x => x.Id == card1.Id);
Assert.Contains(result, x => x.Id == card2.Id);
}

[IntegrationTest]
Expand Down Expand Up @@ -207,14 +254,53 @@ public async Task UpdatesCard()
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card = await CreateCardHelper(_github, column.Id);
var cardUpdate = new ProjectCardUpdate("newNameOfNote");
var cardUpdate = new ProjectCardUpdate
{
Note = "newNameOfNote"
};

var result = await _github.Repository.Project.Card.Update(card.Id, cardUpdate);

Assert.Equal("newNameOfNote", result.Note);
Assert.Equal(card.Id, result.Id);
}

[IntegrationTest]
public async Task ArchivesCard()
{
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card = await CreateCardHelper(_github, column.Id);
var cardUpdate = new ProjectCardUpdate
{
Archived = true
};

var result = await _github.Repository.Project.Card.Update(card.Id, cardUpdate);

Assert.Equal(card.Id, result.Id);
Assert.False(card.Archived);
Assert.True(result.Archived);
}

[IntegrationTest]
public async Task UnarchivesCard()
{
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card = await CreateArchivedCardHelper(_github, column.Id);
var cardUpdate = new ProjectCardUpdate
{
Archived = false
};

var result = await _github.Repository.Project.Card.Update(card.Id, cardUpdate);

Assert.Equal(card.Id, result.Id);
Assert.True(card.Archived);
Assert.False(result.Archived);
}

public void Dispose()
{
if (_context != null)
Expand Down Expand Up @@ -343,6 +429,15 @@ private static async Task<ProjectCard> CreateCardHelper(IGitHubClient githubClie
return result;
}

private static async Task<ProjectCard> CreateArchivedCardHelper(IGitHubClient githubClient, int columnId)
{
var newCard = new NewProjectCard(Helper.MakeNameWithTimestamp("new-card"));
var card = await githubClient.Repository.Project.Card.Create(columnId, newCard);
var result = await githubClient.Repository.Project.Card.Update(card.Id, new ProjectCardUpdate { Archived = true });

return result;
}

private static async Task<ProjectCard> CreateIssueCardHelper(IGitHubClient githubClient, int issueId, int columnId)
{
var newCard = new NewProjectCard(issueId, ProjectCardContentType.Issue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Octokit.Tests.Integration.Helpers;
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Xunit;
using System.Reactive.Linq;
Expand Down Expand Up @@ -39,6 +38,55 @@ public async Task GetsAllCards()
Assert.True(result.FirstOrDefault(x => x.Id == card2.Id).Id == card2.Id);
}

[IntegrationTest]
public async Task GetsAllArchivedCards()
{
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card1 = await CreateCardHelper(_github, column.Id);
var card2 = await CreateArchivedCardHelper(_github, column.Id);

var request = new ProjectCardRequest(ProjectCardArchivedStateFilter.Archived);

var result = await _github.Repository.Project.Card.GetAll(column.Id, request).ToList();

Assert.Equal(1, result.Count);
Assert.Contains(result, x => x.Id == card2.Id);
}

[IntegrationTest]
public async Task GetsAllNotArchivedCards()
{
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card1 = await CreateCardHelper(_github, column.Id);
var card2 = await CreateArchivedCardHelper(_github, column.Id);

var request = new ProjectCardRequest(ProjectCardArchivedStateFilter.NotArchived);

var result = await _github.Repository.Project.Card.GetAll(column.Id, request).ToList();

Assert.Equal(1, result.Count);
Assert.Contains(result, x => x.Id == card1.Id);
}

[IntegrationTest]
public async Task GetsAllArchivedAndNotArchivedCards()
{
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card1 = await CreateCardHelper(_github, column.Id);
var card2 = await CreateArchivedCardHelper(_github, column.Id);

var request = new ProjectCardRequest(ProjectCardArchivedStateFilter.All);

var result = await _github.Repository.Project.Card.GetAll(column.Id, request).ToList();

Assert.Equal(2, result.Count);
Assert.Contains(result, x => x.Id == card1.Id);
Assert.Contains(result, x => x.Id == card2.Id);
}

[IntegrationTest]
public async Task ReturnsCorrectCountOfCardWithoutStart()
{
Expand Down Expand Up @@ -209,14 +257,53 @@ public async Task UpdatesCard()
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card = await CreateCardHelper(_github, column.Id);
var cardUpdate = new ProjectCardUpdate("newNameOfNote");
var cardUpdate = new ProjectCardUpdate
{
Note = "newNameOfNote"
};

var result = await _github.Repository.Project.Card.Update(card.Id, cardUpdate);

Assert.Equal("newNameOfNote", result.Note);
Assert.Equal(card.Id, result.Id);
}

[IntegrationTest]
public async Task ArchivesCard()
{
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card = await CreateCardHelper(_github, column.Id);
var cardUpdate = new ProjectCardUpdate
{
Archived = true
};

var result = await _github.Repository.Project.Card.Update(card.Id, cardUpdate);

Assert.Equal(card.Id, result.Id);
Assert.False(card.Archived);
Assert.True(result.Archived);
}

[IntegrationTest]
public async Task UnarchivesCard()
{
var project = await CreateRepositoryProjectHelper(_github, _context.RepositoryId);
var column = await CreateColumnHelper(_github, project.Id);
var card = await CreateArchivedCardHelper(_github, column.Id);
var cardUpdate = new ProjectCardUpdate
{
Archived = false
};

var result = await _github.Repository.Project.Card.Update(card.Id, cardUpdate);

Assert.Equal(card.Id, result.Id);
Assert.True(card.Archived);
Assert.False(result.Archived);
}

public void Dispose()
{
if (_context != null)
Expand Down Expand Up @@ -345,6 +432,15 @@ private static async Task<ProjectCard> CreateCardHelper(IObservableGitHubClient
return result;
}

private static async Task<ProjectCard> CreateArchivedCardHelper(IObservableGitHubClient githubClient, int columnId)
{
var newCard = new NewProjectCard(Helper.MakeNameWithTimestamp("new-card"));
var card = await githubClient.Repository.Project.Card.Create(columnId, newCard);
var result = await githubClient.Repository.Project.Card.Update(card.Id, new ProjectCardUpdate { Archived = true });

return result;
}

private static async Task<ProjectCard> CreateIssueCardHelper(IObservableGitHubClient githubClient, int issueId, int columnId)
{
var newCard = new NewProjectCard(issueId, ProjectCardContentType.Issue);
Expand Down
24 changes: 23 additions & 1 deletion Octokit.Tests/Clients/ProjectCardsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NSubstitute;
using Xunit;
Expand Down Expand Up @@ -33,12 +34,33 @@ public async Task RequestCorrectURL()
Args.ApiOptions);
}

[Fact]
public async Task SendsAppropriateParameters()
{
var connection = Substitute.For<IApiConnection>();
var client = new ProjectCardsClient(connection);

await client.GetAll(1, new ProjectCardRequest(ProjectCardArchivedStateFilter.NotArchived));

connection.Received().GetAll<ProjectCard>(
Arg.Is<Uri>(u => u.ToString() == "projects/columns/1/cards"),
Arg.Is<Dictionary<string,string>>(x =>
x.Count == 1
&& x["archived_state"] == "not_archived"),
"application/vnd.github.inertia-preview+json",
Args.ApiOptions);
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ProjectCardsClient(Substitute.For<IApiConnection>());
var request = new ProjectCardRequest();

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, (ProjectCardRequest)null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, (ApiOptions)null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, null, ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(1, request, null));
}
}

Expand Down
Loading

0 comments on commit 412358b

Please sign in to comment.