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 6 commits 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
13 changes: 13 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,19 @@ 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
* In case of any networking error or error from the server.
*/
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"login": "leowebb",
"id": 6266758,
"node_id": "MDQ6VXNlcjYyNjY3NTg=",
"avatar_url": "https://avatars.githubusercontent.com/u/6266758?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/leowebb",
"html_url": "https://github.com/leowebb",
"followers_url": "https://api.github.com/users/leowebb/followers",
"following_url": "https://api.github.com/users/leowebb/following{/other_user}",
"gists_url": "https://api.github.com/users/leowebb/gists{/gist_id}",
"starred_url": "https://api.github.com/users/leowebb/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/leowebb/subscriptions",
"organizations_url": "https://api.github.com/users/leowebb/orgs",
"repos_url": "https://api.github.com/users/leowebb/repos",
"events_url": "https://api.github.com/users/leowebb/events{/privacy}",
"received_events_url": "https://api.github.com/users/leowebb/received_events",
"type": "User",
"user_view_type": "private",
"site_admin": false,
"name": null,
"company": null,
"blog": "",
"location": null,
"email": null,
"hireable": null,
"bio": null,
"twitter_username": null,
"notification_email": null,
"public_repos": 4,
"public_gists": 0,
"followers": 5,
"following": 8,
"created_at": "2013-12-26T20:32:21Z",
"updated_at": "2025-08-04T14:53:23Z",
"private_gists": 1,
"total_private_repos": 5,
"owned_private_repos": 5,
"disk_usage": 24,
"collaborators": 0,
"two_factor_authentication": true,
"plan": {
"name": "free",
"space": 976562499,
"collaborators": 0,
"private_repos": 10000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"url": "https://api.github.com/orgs/hub4j-test-org",
"repos_url": "https://api.github.com/orgs/hub4j-test-org/repos",
"events_url": "https://api.github.com/orgs/hub4j-test-org/events",
"hooks_url": "https://api.github.com/orgs/hub4j-test-org/hooks",
"issues_url": "https://api.github.com/orgs/hub4j-test-org/issues",
"members_url": "https://api.github.com/orgs/hub4j-test-org/members{/member}",
"public_members_url": "https://api.github.com/orgs/hub4j-test-org/public_members{/member}",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"description": "Hub4j Test Org Description (this could be null or blank too)",
"name": "Hub4j Test Org Name (this could be null or blank too)",
"company": null,
"blog": "https://hub4j.url.io/could/be/null",
"location": "Hub4j Test Org Location (this could be null or blank too)",
"email": "[email protected]",
"twitter_username": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 27,
"public_gists": 0,
"followers": 2,
"following": 0,
"html_url": "https://github.com/hub4j-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2025-08-05T00:53:03Z",
"archived_at": null,
"type": "Organization",
"total_private_repos": 8,
"owned_private_repos": 8,
"private_gists": 0,
"disk_usage": 12020,
"collaborators": 1,
"billing_email": "[email protected]",
"default_repository_permission": "none",
"members_can_create_repositories": false,
"two_factor_requirement_enabled": false,
"members_allowed_repository_creation_type": "none",
"members_can_create_public_repositories": false,
"members_can_create_private_repositories": false,
"members_can_create_internal_repositories": false,
"members_can_create_pages": true,
"members_can_fork_private_repositories": false,
"web_commit_signoff_required": false,
"deploy_keys_enabled_for_repositories": false,
"members_can_delete_repositories": true,
"members_can_change_repo_visibility": true,
"members_can_invite_outside_collaborators": true,
"members_can_delete_issues": false,
"display_commenter_full_name_setting_enabled": false,
"readers_can_create_discussions": true,
"members_can_create_teams": true,
"members_can_view_dependency_insights": true,
"default_repository_branch": "main",
"members_can_create_public_pages": true,
"members_can_create_private_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 52,
"seats": 3
},
"advanced_security_enabled_for_new_repositories": false,
"dependabot_alerts_enabled_for_new_repositories": false,
"dependabot_security_updates_enabled_for_new_repositories": false,
"dependency_graph_enabled_for_new_repositories": false,
"secret_scanning_enabled_for_new_repositories": false,
"secret_scanning_push_protection_enabled_for_new_repositories": false,
"secret_scanning_push_protection_custom_link_enabled": false,
"secret_scanning_push_protection_custom_link": null,
"secret_scanning_validity_checks_enabled": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"id": 776220577,
"node_id": "R_kgDOLkQvoQ",
"name": "github-api-template-test",
"full_name": "hub4j-test-org/github-api-template-test",
"private": false,
"owner": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "Organization",
"user_view_type": "public",
"site_admin": false
},
"html_url": "https://github.com/hub4j-test-org/github-api-template-test",
"description": "a test template repository used to test kohsuke's github-api",
"fork": false,
"url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test",
"forks_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/forks",
"keys_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/teams",
"hooks_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/hooks",
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/issues/events{/number}",
"events_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/events",
"assignees_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/assignees{/user}",
"branches_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/branches{/branch}",
"tags_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/tags",
"blobs_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/statuses/{sha}",
"languages_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/languages",
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/stargazers",
"contributors_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/contributors",
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/subscribers",
"subscription_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/subscription",
"commits_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/contents/{+path}",
"compare_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/merges",
"archive_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/downloads",
"issues_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/issues{/number}",
"pulls_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/pulls{/number}",
"milestones_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/milestones{/number}",
"notifications_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/github-api-template-test/deployments",
"created_at": "2024-03-22T23:35:17Z",
"updated_at": "2024-03-22T23:35:17Z",
"pushed_at": "2025-08-05T00:38:59Z",
"git_url": "git://github.com/hub4j-test-org/github-api-template-test.git",
"ssh_url": "[email protected]:hub4j-test-org/github-api-template-test.git",
"clone_url": "https://github.com/hub4j-test-org/github-api-template-test.git",
"svn_url": "https://github.com/hub4j-test-org/github-api-template-test",
"homepage": "http://github-api.kohsuke.org/",
"size": 0,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"has_discussions": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": true,
"is_template": true,
"web_commit_signoff_required": false,
"topics": [],
"visibility": "public",
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "main",
"permissions": {
"admin": true,
"maintain": true,
"push": true,
"triage": true,
"pull": true
},
"temp_clone_token": "",
"allow_squash_merge": true,
"allow_merge_commit": true,
"allow_rebase_merge": true,
"allow_auto_merge": false,
"delete_branch_on_merge": false,
"allow_update_branch": false,
"use_squash_pr_title_as_default": false,
"squash_merge_commit_message": "COMMIT_MESSAGES",
"squash_merge_commit_title": "COMMIT_OR_PR_TITLE",
"merge_commit_message": "PR_TITLE",
"merge_commit_title": "MERGE_MESSAGE",
"custom_properties": {},
"organization": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars.githubusercontent.com/u/7544739?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/hub4j-test-org",
"html_url": "https://github.com/hub4j-test-org",
"followers_url": "https://api.github.com/users/hub4j-test-org/followers",
"following_url": "https://api.github.com/users/hub4j-test-org/following{/other_user}",
"gists_url": "https://api.github.com/users/hub4j-test-org/gists{/gist_id}",
"starred_url": "https://api.github.com/users/hub4j-test-org/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/hub4j-test-org/subscriptions",
"organizations_url": "https://api.github.com/users/hub4j-test-org/orgs",
"repos_url": "https://api.github.com/users/hub4j-test-org/repos",
"events_url": "https://api.github.com/users/hub4j-test-org/events{/privacy}",
"received_events_url": "https://api.github.com/users/hub4j-test-org/received_events",
"type": "Organization",
"user_view_type": "public",
"site_admin": false
},
"security_and_analysis": {
"secret_scanning": {
"status": "disabled"
},
"secret_scanning_push_protection": {
"status": "disabled"
},
"dependabot_security_updates": {
"status": "disabled"
},
"secret_scanning_non_provider_patterns": {
"status": "disabled"
},
"secret_scanning_validity_checks": {
"status": "disabled"
}
},
"network_count": 0,
"subscribers_count": 21
}
Loading
Loading