Skip to content

Commit

Permalink
Resolve comments on pull-request
Browse files Browse the repository at this point in the history
  • Loading branch information
jbenaventem authored Mar 18, 2024
1 parent 2105263 commit 88cfdad
Show file tree
Hide file tree
Showing 21 changed files with 829 additions and 393 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ public GHCreateRepositoryBuilder fromTemplateRepository(String templateOwner, St
@Preview(BAPTISTE)
public GHCreateRepositoryBuilder fromTemplateRepository(GHRepository templateRepository) {
Objects.requireNonNull(templateRepository, "templateRepository cannot be null");
if (!templateRepository.isTemplate()) {
throw new IllegalArgumentException("The provided repository is not a template repository.");
}
return fromTemplateRepository(templateRepository.getOwnerName(), templateRepository.getName());
}

Expand Down
21 changes: 4 additions & 17 deletions src/main/java/org/kohsuke/github/GHRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
@SuppressWarnings({ "UnusedDeclaration" })
@SuppressFBWarnings(value = { "UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD", "UWF_UNWRITTEN_FIELD", "NP_UNWRITTEN_FIELD" },
justification = "JSON API")
public class GHRepository extends GHObject implements Cloneable {
public class GHRepository extends GHObject {

private String nodeId, description, homepage, name, full_name;

Expand Down Expand Up @@ -953,12 +953,11 @@ public String getMasterBranch() {
/**
* Get Repository template was the repository created from.
*
* @throws CloneNotSupportedException
* if the template repository is not cloneable
* @return the repository template
*/
public GHRepository getTemplateRepository() throws CloneNotSupportedException {
return (GHRepository) template_repository.clone();
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
public GHRepository getTemplateRepository() {
return (GHRepository) template_repository;
}

/**
Expand Down Expand Up @@ -1430,18 +1429,6 @@ public void setPrivate(boolean value) throws IOException {
set().private_(value);
}

/**
* Sets repository template
*
* @param value
* the GitHub repository used as a template
* @throws IOException
* the io exception
*/
public void setTemplateRepository(GHRepository value) throws IOException {
set().templateRepository(value);
}

/**
* Sets visibility.
*
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/org/kohsuke/github/GHRepositoryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,6 @@ public S private_(boolean enabled) throws IOException {
return with("private", enabled);
}

/**
* Set template repository as GHRepository.
*
* @param repositoryTemplate
* GHRepository
* @throws IOException
* In case of any networking error or error from the server.
* @return a builder to continue with building
*
*/
public S templateRepository(GHRepository repositoryTemplate) throws IOException {
return with("template_repository", repositoryTemplate);
}

/**
* Sets the repository visibility.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.List;

import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.equalTo;

// TODO: Auto-generated Javadoc
/**
Expand Down Expand Up @@ -85,6 +84,8 @@ public void testGetRepository() throws Exception {
public void testGetRepositoryWithTemplateRepositoryInfo() throws Exception {
GHRepository testRepo = gitHub.getRepositoryById(repo.getId());
assertThat(testRepo.getTemplateRepository(), notNullValue());
assertThat(testRepo.getTemplateRepository().getOwnerName(), equalTo("octocat"));
assertThat(testRepo.getTemplateRepository().isTemplate(), equalTo(true));
}

/**
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/org/kohsuke/github/GHOrganizationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThrows;

// TODO: Auto-generated Javadoc
/**
Expand Down Expand Up @@ -177,6 +178,43 @@ public void testCreateRepositoryWithTemplateAndGHRepository() throws IOException

}

/**
* Test create repository with template repository null.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Test
public void testCreateRepositoryFromTemplateRepositoryNull() throws IOException {
cleanupRepository(GITHUB_API_TEST_ORG + '/' + GITHUB_API_TEST);

GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
assertThrows(NullPointerException.class, () -> {
org.createRepository(GITHUB_API_TEST).fromTemplateRepository(null).owner(GITHUB_API_TEST_ORG).create();
});
}

/**
* Test create repository when repository template is not a template.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
@Test
public void testCreateRepositoryWhenRepositoryTemplateIsNotATemplate() throws IOException {
cleanupRepository(GITHUB_API_TEST_ORG + '/' + GITHUB_API_TEST);

GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG);
GHRepository templateRepository = org.getRepository(GITHUB_API_TEMPLATE_TEST);

assertThrows(IllegalArgumentException.class, () -> {
org.createRepository(GITHUB_API_TEST)
.fromTemplateRepository(templateRepository)
.owner(GITHUB_API_TEST_ORG)
.create();
});
}

/**
* Test invite user.
*
Expand Down
Loading

0 comments on commit 88cfdad

Please sign in to comment.