Skip to content

Commit

Permalink
fix(fork): Validate that name follows GitHub repository naming conven…
Browse files Browse the repository at this point in the history
…tions and add @nullable annotations for optional parameters
  • Loading branch information
gounthar committed Dec 10, 2024
1 parent ec41545 commit 97eabee
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 97eabee

Please sign in to comment.