github-api
github-api copied to clipboard
Default branch is always null for repos accessed with GHContentSearchBuilder
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();
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.