Skip to content
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
16 changes: 16 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -650,5 +650,21 @@ public interface IObservableRepositoriesClient
/// <returns>All topics now associated with the repository.</returns>
IObservable<RepositoryTopics> ReplaceAllTopics(string owner, string name, RepositoryTopics topics);

/// <summary>
/// Gets the list of errors in the codeowners file
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>Returns the list of errors in the codeowners files</returns>
[ManualRoute("GET", "/repos/{owner}/{repo}/codeowners/errors")]
IObservable<RepositoryCodeOwnersErrors> GetAllCodeOwnersErrors(string owner, string name);

/// <summary>
/// Gets the list of errors in the codeowners file
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <returns>Returns the list of errors in the codeowners files</returns>
[ManualRoute("GET", "/repositories/{id}/codeowners/errors")]
IObservable<RepositoryCodeOwnersErrors> GetAllCodeOwnersErrors(long repositoryId);
}
}
26 changes: 26 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,32 @@ public IObservable<RepositoryContentLicense> GetLicenseContents(long repositoryI
return _client.GetLicenseContents(repositoryId).ToObservable();
}

/// <summary>
/// Gets the list of errors in the codeowners file
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>Returns the list of errors in the codeowners files</returns>
[ManualRoute("GET", "/repos/{owner}/{repo}/codeowners/errors")]
public IObservable<RepositoryCodeOwnersErrors> GetAllCodeOwnersErrors(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));

return _client.GetAllCodeOwnersErrors(owner, name).ToObservable();
}

/// <summary>
/// Gets the list of errors in the codeowners file
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <returns>Returns the list of errors in the codeowners files</returns>
[ManualRoute("GET", "/repositories/{id}/codeowners/errors")]
public IObservable<RepositoryCodeOwnersErrors> GetAllCodeOwnersErrors(long repositoryId)
{
return _client.GetAllCodeOwnersErrors(repositoryId).ToObservable();
}

/// <summary>
/// Updates the specified repository with the values given in <paramref name="update"/>
/// </summary>
Expand Down
36 changes: 36 additions & 0 deletions Octokit.Tests.Integration/Clients/RepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Octokit;
using Octokit.Tests.Integration;
Expand Down Expand Up @@ -2102,6 +2103,7 @@ public async Task GetsPagesOfBranchesWithRepositoryId()
public class TheGetLicenseContentsMethod
{
[IntegrationTest]
[PotentiallyFlakyTest]
public async Task ReturnsLicenseContent()
{
var github = Helper.GetAuthenticatedClient();
Expand All @@ -2114,6 +2116,7 @@ public async Task ReturnsLicenseContent()
}

[IntegrationTest]
[PotentiallyFlakyTest]
public async Task ReturnsLicenseContentWithRepositoryId()
{
var github = Helper.GetAuthenticatedClient();
Expand All @@ -2126,6 +2129,39 @@ public async Task ReturnsLicenseContentWithRepositoryId()
}
}

public class TheGetCodeOwnersErrorsMethod : GitHubClientTestBase
{
[IntegrationTest]
public async Task ReturnsCodeOwnersErrors()
{
using (var repoContext = await _github.CreateUserRepositoryContext())
{
await _github.Repository.Content.CreateFile(repoContext.RepositoryOwner, repoContext.RepositoryName, ".github/codeowners", new CreateFileRequest("Create codeowners", @"* snyrting6@hotmail.com"));

// Sometimes it takes a second to create the file
Thread.Sleep(TimeSpan.FromSeconds(2));

var license = await _github.Repository.GetAllCodeOwnersErrors(repoContext.RepositoryOwner, repoContext.RepositoryName);
Assert.NotEmpty(license.Errors);
}
}

[IntegrationTest]
public async Task ReturnsCodeOwnersErrorsWithRepositoryId()
{
using (var repoContext = await _github.CreateUserRepositoryContext())
{
await _github.Repository.Content.CreateFile(repoContext.RepositoryId, ".github/codeowners", new CreateFileRequest("Create codeowners", @"* snyrting6@hotmail.com"));

// Sometimes it takes a second to create the file
Thread.Sleep(TimeSpan.FromSeconds(2));

var license = await _github.Repository.GetAllCodeOwnersErrors(repoContext.RepositoryId);
Assert.NotEmpty(license.Errors);
}
}
}

public class TheTransferMethod
{
[IntegrationTest]
Expand Down
36 changes: 36 additions & 0 deletions Octokit.Tests/Clients/RepositoriesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,42 @@ public async Task EnsuresNonNullArguments()
}
}

public class TheGetCodeOwnersErrorsMethod
{
[Fact]
public async Task RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);

await client.GetAllCodeOwnersErrors("owner", "name");

connection.Received()
.Get<RepositoryCodeOwnersErrors>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/codeowners/errors"));
}

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

await client.GetAllCodeOwnersErrors(1);

connection.Received()
.Get<RepositoryCodeOwnersErrors>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/codeowners/errors"));
}

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

await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllCodeOwnersErrors(null, "repo"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllCodeOwnersErrors("owner", null));
}
}

public class TheGetAllTagsMethod
{
[Fact]
Expand Down
16 changes: 16 additions & 0 deletions Octokit/Clients/IRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -714,5 +714,21 @@ public interface IRepositoriesClient
/// <returns>All topics now associated with the repository.</returns>
Task<RepositoryTopics> ReplaceAllTopics(string owner, string name, RepositoryTopics topics);

/// <summary>
/// Gets the list of errors in the codeowners file
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>Returns the list of errors in the codeowners files</returns>
[ManualRoute("GET", "/repos/{owner}/{repo}/codeowners/errors")]
Task<RepositoryCodeOwnersErrors> GetAllCodeOwnersErrors(string owner, string name);

/// <summary>
/// Gets the list of errors in the codeowners file
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <returns>Returns the list of errors in the codeowners files</returns>
[ManualRoute("GET", "/repositories/{id}/codeowners/errors")]
Task<RepositoryCodeOwnersErrors> GetAllCodeOwnersErrors(long repositoryId);
}
}
28 changes: 27 additions & 1 deletion Octokit/Clients/RepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Octokit
/// A client for GitHub's Repositories API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/">Repositories API documentation</a> for more details.
/// See the <a href="https://docs.github.com/rest/repos/repos">Repositories API documentation</a> for more details.
/// </remarks>
public class RepositoriesClient : ApiClient, IRepositoriesClient
{
Expand Down Expand Up @@ -1114,6 +1114,32 @@ public Task<RepositoryContentLicense> GetLicenseContents(long repositoryId)
return ApiConnection.Get<RepositoryContentLicense>(ApiUrls.RepositoryLicense(repositoryId));
}

/// <summary>
/// Gets the list of errors in the codeowners file
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>Returns the list of errors in the codeowners files</returns>
[ManualRoute("GET", "/repos/{owner}/{repo}/codeowners/errors")]
public Task<RepositoryCodeOwnersErrors> GetAllCodeOwnersErrors(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));

return ApiConnection.Get<RepositoryCodeOwnersErrors>(ApiUrls.RepositoryCodeOwnersErrors(owner, name));
}

/// <summary>
/// Gets the list of errors in the codeowners file
/// </summary>
/// <param name="repositoryId">The Id of the repository</param>
/// <returns>Returns the list of errors in the codeowners files</returns>
[ManualRoute("GET", "/repositories/{id}/codeowners/errors")]
public Task<RepositoryCodeOwnersErrors> GetAllCodeOwnersErrors(long repositoryId)
{
return ApiConnection.Get<RepositoryCodeOwnersErrors>(ApiUrls.RepositoryCodeOwnersErrors(repositoryId));
}

/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
Expand Down
21 changes: 21 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,27 @@ public static Uri SearchLabels()
return "search/labels".FormatUri();
}

/// <summary>
/// Returns the <see cref="Uri"/> for repository codeowners errors.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>the <see cref="Uri"/> for repository topics.</returns>
public static Uri RepositoryCodeOwnersErrors(string owner, string name)
{
return "repos/{0}/{1}/codeowners/errors".FormatUri(owner, name);
}

/// <summary>
/// Returns the <see cref="Uri"/> for repository codeowners errors.
/// </summary>
/// <param name="repositoryId">The ID of the repository</param>
/// <returns>the <see cref="Uri"/> for repository topics.</returns>
public static Uri RepositoryCodeOwnersErrors(long repositoryId)
{
return "repositories/{0}/codeowners/errors".FormatUri(repositoryId);
}

/// <summary>
/// Returns the <see cref="Uri"/> for repository contributors.
/// </summary>
Expand Down
58 changes: 58 additions & 0 deletions Octokit/Models/Response/RepositoryCodeOwnersErrors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Octokit.Internal;
using System.Collections.Generic;
using System.Diagnostics;

namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RepositoryCodeOwnersErrors
{
public RepositoryCodeOwnersErrors()
{
}

public RepositoryCodeOwnersErrors(List<RepositoryCodeOwnersError> errors)
{
Errors = errors;
}

public IReadOnlyList<RepositoryCodeOwnersError> Errors { get; private set; }

[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RepositoryCodeOwnersError
{
public RepositoryCodeOwnersError()
{
}

public RepositoryCodeOwnersError(int line, int column, string kind, string source, string suggestion, string message, string path)
{
Line = line;
Column = column;
Kind = kind;
Source = source;
Suggestion = suggestion;
Message = message;
Path = path;
}

public int Line { get; private set; }

public int Column { get; private set; }

public string Kind { get; private set; }

public string Source { get; private set; }

public string Suggestion { get; private set; }

public string Message { get; private set; }

public string Path { get; private set; }

internal string DebuggerDisplay => new SimpleJsonSerializer().Serialize(this);
}

internal string DebuggerDisplay => new SimpleJsonSerializer().Serialize(this);
}
}
3 changes: 2 additions & 1 deletion Octokit/Models/Response/RepositoryTag.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

Expand Down