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

Includes template_repository information fixes #1549 #1579

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/main/java/org/kohsuke/github/GHRepository.java
Expand Up @@ -123,7 +123,7 @@
@SkipFromToString
private GHRepoPermission permissions;

private GHRepository source, parent;
private GHRepository source, parent, template_repository;

private Boolean isTemplate;
private boolean compareUsePaginatedCommits;
Expand Down Expand Up @@ -2975,6 +2975,27 @@
return parent;
}

/**
* Repositories generated from a template have a 'template_repository' attribute that specifies the repository this
* repository is generated from. Only available in Detailed representations, not in Summary representations.
*
* @return {@link GHRepository} that points to the repository where this repository is generated from. Otherwise
* null.
* @throws IOException
* the io exception
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
public GHRepository getTemplateRepository() throws IOException {
if (template_repository == null) {
populate();

Check warning on line 2990 in src/main/java/org/kohsuke/github/GHRepository.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kohsuke/github/GHRepository.java#L2990

Added line #L2990 was not covered by tests
}

if (template_repository == null) {
return null;

Check warning on line 2994 in src/main/java/org/kohsuke/github/GHRepository.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/kohsuke/github/GHRepository.java#L2994

Added line #L2994 was not covered by tests
}
return template_repository;
}

/**
* Subscribes to this repository to get notifications.
*
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/org/kohsuke/github/GHRepositoryTest.java
Expand Up @@ -1565,6 +1565,19 @@ public void createSecret() throws Exception {
repo.createSecret("secret", "encrypted", "public");
}

/**
* Creates the template repository
*
* @throws Exception
* the exception
*/
@Test
public void templateRepository() throws Exception {
GHRepository repo = getRepository();

assertThat(repo.getTemplateRepository().getName(), is("github-api-template"));
}

/**
* Test to check star method by verifying stargarzer count.
*
Expand Down
@@ -0,0 +1,42 @@
{
"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://avatars3.githubusercontent.com/u/7544739?v=4",
"description": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 9,
"public_gists": 0,
"followers": 0,
"following": 0,
"html_url": "https://github.com/hub4j-test-org",
"created_at": "2014-05-10T19:39:11Z",
"updated_at": "2015-04-20T00:42:30Z",
"type": "Organization",
"total_private_repos": 0,
"owned_private_repos": 0,
"private_gists": 0,
"disk_usage": 132,
"collaborators": 0,
"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",
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 0,
"filled_seats": 3,
"seats": 0
}
}