Skip to content

Commit 03b08b6

Browse files
authored
Add support for 'include_all_branches' flag when creating repository from a template (#2107)
* Add support for 'include_all_branches' flag when creating repository from a template * Add testing files captured from testing against hub4j-test-org * Update javadoc for IOException definition
1 parent 2e0fdcc commit 03b08b6

File tree

14 files changed

+826
-0
lines changed

14 files changed

+826
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,19 @@ 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+
* In case of any networking error or error from the server.
109+
*/
110+
public GHCreateRepositoryBuilder includeAllBranches(boolean includeAllBranches) throws IOException {
111+
return with("include_all_branches", includeAllBranches);
112+
}
113+
101114
/**
102115
* Desired license template to apply.
103116
*

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
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"login": "leowebb",
3+
"id": 6266758,
4+
"node_id": "MDQ6VXNlcjYyNjY3NTg=",
5+
"avatar_url": "https://avatars.githubusercontent.com/u/6266758?v=4",
6+
"gravatar_id": "",
7+
"url": "https://api.github.com/users/leowebb",
8+
"html_url": "https://github.com/leowebb",
9+
"followers_url": "https://api.github.com/users/leowebb/followers",
10+
"following_url": "https://api.github.com/users/leowebb/following{/other_user}",
11+
"gists_url": "https://api.github.com/users/leowebb/gists{/gist_id}",
12+
"starred_url": "https://api.github.com/users/leowebb/starred{/owner}{/repo}",
13+
"subscriptions_url": "https://api.github.com/users/leowebb/subscriptions",
14+
"organizations_url": "https://api.github.com/users/leowebb/orgs",
15+
"repos_url": "https://api.github.com/users/leowebb/repos",
16+
"events_url": "https://api.github.com/users/leowebb/events{/privacy}",
17+
"received_events_url": "https://api.github.com/users/leowebb/received_events",
18+
"type": "User",
19+
"user_view_type": "private",
20+
"site_admin": false,
21+
"name": null,
22+
"company": null,
23+
"blog": "",
24+
"location": null,
25+
"email": null,
26+
"hireable": null,
27+
"bio": null,
28+
"twitter_username": null,
29+
"notification_email": null,
30+
"public_repos": 4,
31+
"public_gists": 0,
32+
"followers": 5,
33+
"following": 8,
34+
"created_at": "2013-12-26T20:32:21Z",
35+
"updated_at": "2025-08-04T14:53:23Z",
36+
"private_gists": 1,
37+
"total_private_repos": 5,
38+
"owned_private_repos": 5,
39+
"disk_usage": 24,
40+
"collaborators": 0,
41+
"two_factor_authentication": true,
42+
"plan": {
43+
"name": "free",
44+
"space": 976562499,
45+
"collaborators": 0,
46+
"private_repos": 10000
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"login": "hub4j-test-org",
3+
"id": 7544739,
4+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
5+
"url": "https://api.github.com/orgs/hub4j-test-org",
6+
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
7+
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
8+
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
9+
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
10+
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
11+
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
12+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
13+
"description": "Hub4j Test Org Description (this could be null or blank too)",
14+
"name": "Hub4j Test Org Name (this could be null or blank too)",
15+
"company": null,
16+
"blog": "https://hub4j.url.io/could/be/null",
17+
"location": "Hub4j Test Org Location (this could be null or blank too)",
18+
"email": "[email protected]",
19+
"twitter_username": null,
20+
"is_verified": false,
21+
"has_organization_projects": true,
22+
"has_repository_projects": true,
23+
"public_repos": 27,
24+
"public_gists": 0,
25+
"followers": 2,
26+
"following": 0,
27+
"html_url": "https://github.com/hub4j-test-org",
28+
"created_at": "2014-05-10T19:39:11Z",
29+
"updated_at": "2025-08-05T00:53:03Z",
30+
"archived_at": null,
31+
"type": "Organization",
32+
"total_private_repos": 8,
33+
"owned_private_repos": 8,
34+
"private_gists": 0,
35+
"disk_usage": 12020,
36+
"collaborators": 1,
37+
"billing_email": "[email protected]",
38+
"default_repository_permission": "none",
39+
"members_can_create_repositories": false,
40+
"two_factor_requirement_enabled": false,
41+
"members_allowed_repository_creation_type": "none",
42+
"members_can_create_public_repositories": false,
43+
"members_can_create_private_repositories": false,
44+
"members_can_create_internal_repositories": false,
45+
"members_can_create_pages": true,
46+
"members_can_fork_private_repositories": false,
47+
"web_commit_signoff_required": false,
48+
"deploy_keys_enabled_for_repositories": false,
49+
"members_can_delete_repositories": true,
50+
"members_can_change_repo_visibility": true,
51+
"members_can_invite_outside_collaborators": true,
52+
"members_can_delete_issues": false,
53+
"display_commenter_full_name_setting_enabled": false,
54+
"readers_can_create_discussions": true,
55+
"members_can_create_teams": true,
56+
"members_can_view_dependency_insights": true,
57+
"default_repository_branch": "main",
58+
"members_can_create_public_pages": true,
59+
"members_can_create_private_pages": true,
60+
"plan": {
61+
"name": "free",
62+
"space": 976562499,
63+
"private_repos": 10000,
64+
"filled_seats": 52,
65+
"seats": 3
66+
},
67+
"advanced_security_enabled_for_new_repositories": false,
68+
"dependabot_alerts_enabled_for_new_repositories": false,
69+
"dependabot_security_updates_enabled_for_new_repositories": false,
70+
"dependency_graph_enabled_for_new_repositories": false,
71+
"secret_scanning_enabled_for_new_repositories": false,
72+
"secret_scanning_push_protection_enabled_for_new_repositories": false,
73+
"secret_scanning_push_protection_custom_link_enabled": false,
74+
"secret_scanning_push_protection_custom_link": null,
75+
"secret_scanning_validity_checks_enabled": false
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
{
2+
"id": 776220577,
3+
"node_id": "R_kgDOLkQvoQ",
4+
"name": "github-api-template-test",
5+
"full_name": "hub4j-test-org/github-api-template-test",
6+
"private": false,
7+
"owner": {
8+
"login": "hub4j-test-org",
9+
"id": 7544739,
10+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
11+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
12+
"gravatar_id": "",
13+
"url": "https://api.github.com/users/hub4j-test-org",
14+
"html_url": "https://github.com/hub4j-test-org",
15+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
16+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
17+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
18+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
19+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
20+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
21+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
22+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
23+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
24+
"type": "Organization",
25+
"user_view_type": "public",
26+
"site_admin": false
27+
},
28+
"html_url": "https://github.com/hub4j-test-org/github-api-template-test",
29+
"description": "a test template repository used to test kohsuke's github-api",
30+
"fork": false,
31+
"url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test",
32+
"forks_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/forks",
33+
"keys_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/keys{/key_id}",
34+
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/collaborators{/collaborator}",
35+
"teams_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/teams",
36+
"hooks_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/hooks",
37+
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/issues/events{/number}",
38+
"events_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/events",
39+
"assignees_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/assignees{/user}",
40+
"branches_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/branches{/branch}",
41+
"tags_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/tags",
42+
"blobs_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/git/blobs{/sha}",
43+
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/git/tags{/sha}",
44+
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/git/refs{/sha}",
45+
"trees_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/git/trees{/sha}",
46+
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/statuses/{sha}",
47+
"languages_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/languages",
48+
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/stargazers",
49+
"contributors_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/contributors",
50+
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/subscribers",
51+
"subscription_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/subscription",
52+
"commits_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/commits{/sha}",
53+
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/git/commits{/sha}",
54+
"comments_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/comments{/number}",
55+
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/issues/comments{/number}",
56+
"contents_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/contents/{+path}",
57+
"compare_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/compare/{base}...{head}",
58+
"merges_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/merges",
59+
"archive_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/{archive_format}{/ref}",
60+
"downloads_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/downloads",
61+
"issues_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/issues{/number}",
62+
"pulls_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/pulls{/number}",
63+
"milestones_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/milestones{/number}",
64+
"notifications_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/notifications{?since,all,participating}",
65+
"labels_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/labels{/name}",
66+
"releases_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/releases{/id}",
67+
"deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/deployments",
68+
"created_at": "2024-03-22T23:35:17Z",
69+
"updated_at": "2024-03-22T23:35:17Z",
70+
"pushed_at": "2025-08-05T00:38:59Z",
71+
"git_url": "git://github.com/hub4j-test-org/github-api-template-test.git",
72+
"ssh_url": "[email protected]:hub4j-test-org/github-api-template-test.git",
73+
"clone_url": "https://github.com/hub4j-test-org/github-api-template-test.git",
74+
"svn_url": "https://github.com/hub4j-test-org/github-api-template-test",
75+
"homepage": "http://github-api.kohsuke.org/",
76+
"size": 0,
77+
"stargazers_count": 0,
78+
"watchers_count": 0,
79+
"language": null,
80+
"has_issues": true,
81+
"has_projects": true,
82+
"has_downloads": true,
83+
"has_wiki": true,
84+
"has_pages": false,
85+
"has_discussions": false,
86+
"forks_count": 0,
87+
"mirror_url": null,
88+
"archived": false,
89+
"disabled": false,
90+
"open_issues_count": 0,
91+
"license": null,
92+
"allow_forking": true,
93+
"is_template": true,
94+
"web_commit_signoff_required": false,
95+
"topics": [],
96+
"visibility": "public",
97+
"forks": 0,
98+
"open_issues": 0,
99+
"watchers": 0,
100+
"default_branch": "main",
101+
"permissions": {
102+
"admin": true,
103+
"maintain": true,
104+
"push": true,
105+
"triage": true,
106+
"pull": true
107+
},
108+
"temp_clone_token": "",
109+
"allow_squash_merge": true,
110+
"allow_merge_commit": true,
111+
"allow_rebase_merge": true,
112+
"allow_auto_merge": false,
113+
"delete_branch_on_merge": false,
114+
"allow_update_branch": false,
115+
"use_squash_pr_title_as_default": false,
116+
"squash_merge_commit_message": "COMMIT_MESSAGES",
117+
"squash_merge_commit_title": "COMMIT_OR_PR_TITLE",
118+
"merge_commit_message": "PR_TITLE",
119+
"merge_commit_title": "MERGE_MESSAGE",
120+
"custom_properties": {},
121+
"organization": {
122+
"login": "hub4j-test-org",
123+
"id": 7544739,
124+
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
125+
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
126+
"gravatar_id": "",
127+
"url": "https://api.github.com/users/hub4j-test-org",
128+
"html_url": "https://github.com/hub4j-test-org",
129+
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
130+
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
131+
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
132+
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
133+
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
134+
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
135+
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
136+
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
137+
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
138+
"type": "Organization",
139+
"user_view_type": "public",
140+
"site_admin": false
141+
},
142+
"security_and_analysis": {
143+
"secret_scanning": {
144+
"status": "disabled"
145+
},
146+
"secret_scanning_push_protection": {
147+
"status": "disabled"
148+
},
149+
"dependabot_security_updates": {
150+
"status": "disabled"
151+
},
152+
"secret_scanning_non_provider_patterns": {
153+
"status": "disabled"
154+
},
155+
"secret_scanning_validity_checks": {
156+
"status": "disabled"
157+
}
158+
},
159+
"network_count": 0,
160+
"subscribers_count": 21
161+
}

0 commit comments

Comments
 (0)