diff --git a/src/main/java/org/kohsuke/github/GHRepository.java b/src/main/java/org/kohsuke/github/GHRepository.java index f320d8f5a4..274d68b5e8 100644 --- a/src/main/java/org/kohsuke/github/GHRepository.java +++ b/src/main/java/org/kohsuke/github/GHRepository.java @@ -1501,24 +1501,23 @@ public GHRepository forkTo(GHOrganization org) throws IOException { /** * Creates a fork of this repository with optional parameters. * - * @param organization - * the organization to fork to, or null to fork to the authenticated user's account - * @param name - * the name of the new repository, or null to use the same name as the original repository - * @param defaultBranchOnly - * whether to fork only the default branch + * @param organization the organization to fork to, or null to fork to the authenticated user's account + * @param name the name of the new repository, or null to use the same name as the original repository + * @param defaultBranchOnly whether to fork only the default branch * @return the newly forked repository - * @throws IOException - * if an I/O error occurs + * @throws IOException if an I/O error occurs */ - public GHRepository createFork(String organization, String name, boolean defaultBranchOnly) throws IOException { + public GHRepository createFork(@Nullable String organization, @Nullable String name, boolean defaultBranchOnly) throws IOException { + if (organization != null && organization.isEmpty()) { throw new IllegalArgumentException("Organization cannot be empty"); } if (name != null && name.isEmpty()) { throw new IllegalArgumentException("Name cannot be empty"); } - + if (name != null && !name.matches("^[a-zA-Z0-9._-]+$")) { + throw new IllegalArgumentException("Repository name contains invalid characters"); + } Requester requester = root().createRequest().method("POST").withUrlPath(getApiTailUrl("forks")); if (organization != null) {