GHRespository.getTemplateRepository() should call populate() if null
Describe the bug A clear and concise description of what the bug is.
When calling the GitHub API to get a list of repositories the template_repository field is not included in the response. Thus if using this library to get a list of repositories (i.e. GHOrganization.listRepositories()) that field will always be null when mapped onto the GHRepository object constructed as introduced in PR#1817. Under a different proposal I saw PR#1579 it had a check
if this.template_repository == null
populate()
This has its own performance concerns as there is no flag that populate() isn't called more than once which would happen if this was not a child of a template repository and the getTemplateRepository() method was called multiple times. All works as expected when getting a single repository via GitHub.getRepository() as the GitHub API includes the template_repository field in that case.
To Reproduce Steps to reproduce the behavior:
- Go to '...'
- Click on '....'
- Scroll down to '....'
- See error
GHRepositories[] repos = gitHub.getOrganization("SAMPLE").listRepositories(10);
for (GHRepository repo : repos){
if (repo.getTemplateRepository() != null) {
// BUG: This will never hit as underlying template_repository field isn't ever populated when using list vs single get methods
doSomethingWithTemplate();
}
}
Expected behavior A clear and concise description of what you expected to happen.
I expect the GHRepository.getTemplateRepository() to return the value assuming the repo is a child of a template regardless of if it was originally constructed by a method to get the single repo (working) versus getting a list of repositories (not working) and believe making the delayed load populate() call as seen in other places is an established behavior that would be expected.
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Additional context Add any other context about the problem here.
@kkroner8451
You don't have to use this.template_repository to check for population - check another field that is populated by the populate call.
PR welcome.