Skip to content

Add support for 'include_all_branches' flag when creating repository from a template #2107

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ public GHCreateRepositoryBuilder gitignoreTemplate(String language) throws IOExc
return with("gitignore_template", language);
}

/**
* Include all branches when creating from a template repository
*
* @param includeAllBranches
* whether or not to include all branches from the template repository
* @return a builder to continue with building
* @throws IOException
*/
public GHCreateRepositoryBuilder includeAllBranches(boolean includeAllBranches) throws IOException {
return with("include_all_branches", includeAllBranches);
}

/**
* Desired license template to apply.
*
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/org/kohsuke/github/GHOrganizationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,37 @@ public void testCreateRepositoryWithTemplateAndGHRepository() throws IOException

}

/**
* Test create a repository from a template with all branches included
*
* @throws IOException
* Signals that an I/O exception has occurred.
* @throws InterruptedException
* Signals that Thread.sleep() was interrupted
*/

@Test
public void testCreateRepositoryWithTemplateAndIncludeAllBranches() throws IOException, InterruptedException {
cleanupRepository(GITHUB_API_TEST_ORG + '/' + GITHUB_API_TEST);

GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHRepository templateRepository = org.getRepository(GITHUB_API_TEMPLATE_TEST);

GHRepository repository = gitHub.createRepository(GITHUB_API_TEST)
.fromTemplateRepository(templateRepository)
.includeAllBranches(true)
.owner(GITHUB_API_TEST_ORG)
.create();

assertThat(repository, notNullValue());

// give it a moment for branches to be created
Thread.sleep(1500);

assertThat(repository.getBranches().keySet(), equalTo(templateRepository.getBranches().keySet()));

}

/**
* Test create team.
*
Expand Down
Loading