Skip to content

Commit a37c814

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

File tree

2 files changed

+56
-13
lines changed

2 files changed

+56
-13
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: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,21 @@ public GHOrganizationTest() {
4444
* @throws IOException
4545
* Signals that an I/O exception has occurred.
4646
*/
47-
@Before
48-
@After
49-
public void cleanUpTeam() throws IOException {
50-
// Cleanup is only needed when proxying
51-
if (!mockGitHub.isUseProxy()) {
52-
return;
53-
}
47+
@Before
48+
@After
49+
public void cleanUpTeam() throws IOException {
50+
// Cleanup is only needed when proxying
51+
if (!mockGitHub.isUseProxy()) {
52+
return;
53+
}
5454

55-
GHTeam team = getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).getTeamByName(TEAM_NAME_CREATE);
56-
if (team != null) {
57-
team.delete();
58-
}
55+
GHTeam team = getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).getTeamByName(TEAM_NAME_CREATE);
56+
if (team != null) {
57+
team.delete();
58+
}
5959

60-
getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).enableOrganizationProjects(true);
61-
}
60+
getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).enableOrganizationProjects(true);
61+
}
6262

6363
/**
6464
* Test are organization projects enabled.
@@ -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)