Skip to content

Commit

Permalink
improve handling of GetAllContentsByRef where root path is requested (#…
Browse files Browse the repository at this point in the history
…2105)

* add failing test for handling / as the path

* workaround issue by passing in what the API expects
  • Loading branch information
shiftkey authored Feb 24, 2020
1 parent 6fdd800 commit 5223d1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Octokit.Tests.Integration/Clients/RepositoryContentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ public async Task GetsDirectoryContent()
Assert.Equal(ContentType.Dir, contents.First().Type);
}

[IntegrationTest]
public async Task GetsContentNonMasterWithRootPath()
{
var github = Helper.GetAuthenticatedClient();

var contents = await github
.Repository
.Content
.GetAllContentsByRef("octocat", "Spoon-Knife", "/", reference: "test-branch");
Assert.Equal(4, contents.Count);
}

[IntegrationTest]
public async Task GetsDirectoryContentWithRepositoryId()
{
Expand Down
4 changes: 3 additions & 1 deletion Octokit/Clients/RepositoryContentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public Task<IReadOnlyList<RepositoryContent>> GetAllContentsByRef(string owner,
Ensure.ArgumentNotNullOrEmptyString(path, nameof(path));
Ensure.ArgumentNotNullOrEmptyString(reference, nameof(reference));

var url = ApiUrls.RepositoryContent(owner, name, path, reference);
var url = (path == "/")
? ApiUrls.RepositoryContent(owner, name, "", reference)
: ApiUrls.RepositoryContent(owner, name, path, reference);

return ApiConnection.GetAll<RepositoryContent>(url);
}
Expand Down

0 comments on commit 5223d1a

Please sign in to comment.