Skip to content

Commit 885bc95

Browse files
committed
Add support for 'include_all_branches' flag when creating repository from a template
1 parent 7c61987 commit 885bc95

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ public GHCreateRepositoryBuilder gitignoreTemplate(String language) throws IOExc
9898
return with("gitignore_template", language);
9999
}
100100

101+
/**
102+
* Include all branches when creating from a template repository
103+
*
104+
* @param includeAllBranches
105+
* whether or not to include all branches from the template repository
106+
* @return a builder to continue with building
107+
* @throws IOException
108+
*/
109+
public GHCreateRepositoryBuilder includeAllBranches(boolean includeAllBranches) throws IOException {
110+
return with("include_all_branches", includeAllBranches);
111+
}
112+
101113
/**
102114
* Desired license template to apply.
103115
*

src/test/java/org/kohsuke/github/GHOrganizationTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,37 @@ public void testCreateRepositoryWithTemplateAndGHRepository() throws IOException
264264

265265
}
266266

267+
/**
268+
* Test create a repository from a template with all branches included
269+
*
270+
* @throws IOException
271+
* Signals that an I/O exception has occurred.
272+
* @throws InterruptedException
273+
* Signals that Thread.sleep() was interrupted
274+
*/
275+
276+
@Test
277+
public void testCreateRepositoryWithTemplateAndIncludeAllBranches() throws IOException, InterruptedException {
278+
cleanupRepository(GITHUB_API_TEST_ORG + '/' + GITHUB_API_TEST);
279+
280+
GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
281+
GHRepository templateRepository = org.getRepository(GITHUB_API_TEMPLATE_TEST);
282+
283+
GHRepository repository = gitHub.createRepository(GITHUB_API_TEST)
284+
.fromTemplateRepository(templateRepository)
285+
.includeAllBranches(true)
286+
.owner(GITHUB_API_TEST_ORG)
287+
.create();
288+
289+
assertThat(repository, notNullValue());
290+
291+
// give it a moment for branches to be created
292+
Thread.sleep(1500);
293+
294+
assertThat(repository.getBranches().keySet(), equalTo(templateRepository.getBranches().keySet()));
295+
296+
}
297+
267298
/**
268299
* Test create team.
269300
*

0 commit comments

Comments
 (0)