github-api icon indicating copy to clipboard operation
github-api copied to clipboard

Default branch is always null for repos accessed with GHContentSearchBuilder

Open fwdekker opened this issue 6 years ago • 1 comments

When information on a repository is downloaded using the GHContentSearchBuilder, the defaultBranch property is always null, regardless of whether the repository in question has a default branch. On the other hand, if the same repository is accessed using a simple getRepository call, the defaultBranch is set correctly.

Sample setup

This repository has a non-standard default branch, and does not have a master branch. I think it's a good example for this issue.

Correct behaviour

The following code returns "original", as expected:

GitHub gh = GitHub.connectUsingOAuth(/* insert your token here */);
return gh.getRepository("Stargator/koskela_sourcecode").getDefaultBranch();

Incorrect behaviour

The following code always returns null:

GitHub gh = GitHub.connectUsingOAuth(/* insert your token here */);
GHContentSearchBuilder sb = gh.searchContent().user("Stargator")
    .repo("Stargator/koskela_sourcecode")
    .q("koskela");
GHContent repo = sb.list().asList().get(0);
return repo.getOwner().getDefaultBranch();

fwdekker avatar Feb 07 '19 10:02 fwdekker

I was going over my old bug reports to see if there are stale reports.

I can confirm this bug is still present in v1.319.

fwdekker avatar Mar 08 '24 12:03 fwdekker