Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Retrieving Template Repository Information for a Repository #1812

Closed
jbenaventem opened this issue Mar 10, 2024 · 3 comments
Closed

Comments

@jbenaventem
Copy link
Contributor

I'm currently working on a project where I need to retrieve the information of the template repository from which a repository was created. However, it seems that the current version of the GitHub API kosuke library does not support this feature. Here's an example of how I'm trying to use this feature:

GHRepository repository = organization.createRepository(repositoryName)
    .owner("owner")
    .description("Component-Manager Test create repository from template repository")
    .private_(true)
    .fromTemplateRepository("template_owner", "repository_template")
    .create();
    
   //If I retrieve the GHRepository there's not a way to retrieve the templateRepository
GHRepository repoFind = organization.getRepository(repositoryName);
assert repoFind.getTemplateRepository().getFullName().equals("template_owner/template_repository");

In this code, I'm creating a new repository from a template repository. After the repository is created, I'm trying to retrieve the template repository information using repoFind.getTemplateRepository(). However, this method does not exist in the current version of the library.

Proposed Solution

I propose adding a new method to the GHRepository class that allows retrieving the template repository information. This method could return a GHRepository object representing the template repository. Here's a rough idea of how this could be implemented:

GHRepository.java

    private GHRepository template_repository; //Repository template from it was created

   /**
    * Get Repository template was the repository created from.
    *
    * @return the repository template
    */
    public GHRepository getTemplateRepository() {
        return template_repository;
    }

    /**
     * Sets repository template
     *
     */
    public void setTemplateRepository(GHRepository value) throws IOException {
        set().template_repository(value);
    }

And In the abstract class GHRepositoryBuilder (I'm not absolutly sure about this method is needed)

    public S template_repository(GHRepository repositoryTemplate) throws IOException {
        return with("template_repository", repositoryTemplate);
    }
@jbenaventem
Copy link
Contributor Author

Assuming you have no objections, I would like to initiate the collaboration process.

@bitwiseman
Copy link
Member

@jbenaventem

REST API Docs:

For Create, the only parameters for template-based creation are template_owner and template_repo. There's no template_repository.

For the builder related to Create, since there isn't a template_repository field, I agree you could add an overload for fromTemplateRepository that takes a GHRepository instance and then pulls the owner and repo from the instance. That would be a nice convenience.

For Update, the API does not support changing template_repository. So, there's no setTemplateRepository().

For Read, I agree we should have a method that returns the template repository details.

@bitwiseman
Copy link
Member

This looks similar to #1549 and associated PR #1579 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants