Skip to content
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

Fix visibility when creating a repository #1692

Merged
merged 5 commits into from
Aug 15, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/main/java/org/kohsuke/github/GHRepositoryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public S private_(boolean enabled) throws IOException {
*/
public S visibility(final Visibility visibility) throws IOException {
requester.withPreview(NEBULA);
return with("visibility", visibility);
return with("visibility", visibility.toString());
}

/**
Expand Down
52 changes: 52 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.kohsuke.github;

import com.fasterxml.jackson.databind.JsonMappingException;
import com.google.common.collect.Sets;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
Expand Down Expand Up @@ -310,6 +311,57 @@ public void testSetPublic() throws Exception {
}
}

/**
* Tests the creation of repositories with alternating visibilities for orgs.
*
* @throws Exception
* the exception
*/
@Test
public void testCreateVisibilityForOrganization() throws Exception {
GHOrganization organization = gitHub.getOrganization(GITHUB_API_TEST_ORG);

// can not test for internal, as test org is not assigned to an enterprise
for (Visibility visibility : Sets.newHashSet(Visibility.PUBLIC, Visibility.PRIVATE)) {
String repoName = String.format("test-repo-visibility-%s", visibility.toString());
GHRepository repository = organization.createRepository(repoName).visibility(visibility).create();
try {
assertThat(repository.getVisibility(), is(visibility));
assertThat(organization.getRepository(repoName).getVisibility(), is(visibility));
} finally {
repository.delete();
}
}
}

/**
* Tests the creation of repositories with alternating visibilities for users.
*
* @throws Exception
* the exception
*/
@Test
public void testCreateVisibilityForUser() throws Exception {

GHUser myself = gitHub.getMyself();

// can not test for internal, as test org is not assigned to an enterprise
for (Visibility visibility : Sets.newHashSet(Visibility.PUBLIC, Visibility.PRIVATE)) {
String repoName = String.format("test-repo-visibility-%s", visibility.toString());
boolean isPrivate = visibility.equals(Visibility.PRIVATE);
GHRepository repository = gitHub.createRepository(repoName)
.private_(isPrivate)
.visibility(visibility)
.create();
try {
assertThat(repository.getVisibility(), is(visibility));
assertThat(myself.getRepository(repoName).getVisibility(), is(visibility));
} finally {
repository.delete();
}
}
}

/**
* Test update repository.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"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": "hub4jtestorgemail@could.be.null.com",
"twitter_username": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 26,
"public_gists": 0,
"followers": 1,
"following": 0,
"html_url": "https://github.com/hub4j-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2020-06-04T05:56:10Z",
"archived_at": null,
"type": "Organization",
"total_private_repos": 6,
"owned_private_repos": 6,
"private_gists": 0,
"disk_usage": 12007,
"collaborators": 1,
"billing_email": "kk@kohsuke.org",
"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,
"members_can_create_public_pages": true,
"members_can_create_private_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 10000,
"filled_seats": 46,
"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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"id": 676879845,
"node_id": "R_kgDOKFhd5Q",
"name": "test-repo-visibility-public",
"full_name": "hub4j-test-org/test-repo-visibility-public",
"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",
"site_admin": false
},
"html_url": "https://github.com/hub4j-test-org/test-repo-visibility-public",
"description": null,
"fork": false,
"url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public",
"forks_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/forks",
"keys_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/teams",
"hooks_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/hooks",
"issue_events_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/issues/events{/number}",
"events_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/events",
"assignees_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/assignees{/user}",
"branches_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/branches{/branch}",
"tags_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/tags",
"blobs_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/statuses/{sha}",
"languages_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/languages",
"stargazers_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/stargazers",
"contributors_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/contributors",
"subscribers_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/subscribers",
"subscription_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/subscription",
"commits_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/contents/{+path}",
"compare_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/merges",
"archive_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/downloads",
"issues_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/issues{/number}",
"pulls_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/pulls{/number}",
"milestones_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/milestones{/number}",
"notifications_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/test-repo-visibility-public/deployments",
"created_at": "2023-08-10T08:16:45Z",
"updated_at": "2023-08-10T08:16:46Z",
"pushed_at": "2023-08-10T08:16:46Z",
"git_url": "git://github.com/hub4j-test-org/test-repo-visibility-public.git",
"ssh_url": "git@github.com:hub4j-test-org/test-repo-visibility-public.git",
"clone_url": "https://github.com/hub4j-test-org/test-repo-visibility-public.git",
"svn_url": "https://github.com/hub4j-test-org/test-repo-visibility-public",
"homepage": null,
"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": false,
"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
},
"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",
"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",
"site_admin": false
},
"network_count": 0,
"subscribers_count": 0
}
Loading