Skip to content

Commit 4c84356

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

File tree

2 files changed

+58
-17
lines changed

2 files changed

+58
-17
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: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package org.kohsuke.github;
22

33
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
4-
import org.junit.After;
5-
import org.junit.Before;
64
import org.junit.Test;
75
import org.kohsuke.github.GHOrganization.Permission;
86
import org.kohsuke.github.GHOrganization.RepositoryRole;
@@ -44,21 +42,21 @@ public GHOrganizationTest() {
4442
* @throws IOException
4543
* Signals that an I/O exception has occurred.
4644
*/
47-
@Before
48-
@After
49-
public void cleanUpTeam() throws IOException {
50-
// Cleanup is only needed when proxying
51-
if (!mockGitHub.isUseProxy()) {
52-
return;
53-
}
54-
55-
GHTeam team = getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).getTeamByName(TEAM_NAME_CREATE);
56-
if (team != null) {
57-
team.delete();
58-
}
59-
60-
getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).enableOrganizationProjects(true);
61-
}
45+
// @Before
46+
// @After
47+
// public void cleanUpTeam() throws IOException {
48+
// // Cleanup is only needed when proxying
49+
// if (!mockGitHub.isUseProxy()) {
50+
// return;
51+
// }
52+
//
53+
// GHTeam team = getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).getTeamByName(TEAM_NAME_CREATE);
54+
// if (team != null) {
55+
// team.delete();
56+
// }
57+
//
58+
// getNonRecordingGitHub().getOrganization(GITHUB_API_TEST_ORG).enableOrganizationProjects(true);
59+
// }
6260

6361
/**
6462
* Test are organization projects enabled.
@@ -264,6 +262,37 @@ public void testCreateRepositoryWithTemplateAndGHRepository() throws IOException
264262

265263
}
266264

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

0 commit comments

Comments
 (0)