Skip to content

Commit

Permalink
Fixup tests for GHProjectCardTest
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Leitschuh <[email protected]>
  • Loading branch information
JLLeitschuh committed Oct 11, 2021
1 parent ccf6031 commit 1cdbc17
Show file tree
Hide file tree
Showing 31 changed files with 819 additions and 379 deletions.
10 changes: 9 additions & 1 deletion src/main/java/org/kohsuke/github/GHIssue.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ GHIssue wrap(GHRepository owner) {
return this;
}

String getRepositoryUrlPath() {
private String getRepositoryUrlPath() {
String url = getUrl().toString();
int index = url.indexOf("/issues");
if (index == -1) {
Expand All @@ -95,6 +95,14 @@ String getRepositoryUrlPath() {
*/
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected behavior")
public GHRepository getRepository() {
try {
if (owner == null) {
String repositoryUrlPath = getRepositoryUrlPath();
wrap(root().createRequest().withUrlPath(repositoryUrlPath).fetch(GHRepository.class));
}
} catch (IOException e) {
throw new GHException("Failed to fetch repository", e);
}
return owner;
}

Expand Down
12 changes: 3 additions & 9 deletions src/main/java/org/kohsuke/github/GHProjectCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public GHProjectColumn getColumn() throws IOException {
}

/**
* Gets content. May be a {@link GHPullRequest} or a {@link GHIssue}.
* Gets content if present. Might be a {@link GHPullRequest} or a {@link GHIssue}.
*
* @return the content
* @throws IOException
Expand All @@ -125,17 +125,11 @@ public GHIssue getContent() throws IOException {
if (StringUtils.isEmpty(content_url))
return null;
try {
GHIssue issue;
if (content_url.contains("/pulls")) {
issue = root().createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHPullRequest.class);
return root().createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHPullRequest.class);
} else {
issue = root().createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHIssue.class);
return root().createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHIssue.class);
}
GHRepository repository = root().createRequest()
.withUrlPath(issue.getRepositoryUrlPath())
.fetch(GHRepository.class);
issue.wrap(repository);
return issue;
} catch (FileNotFoundException e) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/kohsuke/github/GHProjectCardTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void testCreateCardFromIssue() throws IOException {
GHIssue issue = repo.createIssue("new-issue").body("With body").create();
GHProjectCard card = column.createCard(issue);
assertThat(card.getContentUrl(), equalTo(issue.getUrl()));
assertThat(card.getContent(), notNullValue());
assertThat(card.getContent().getRepository(), notNullValue());
assertThat(card.getContent().getUrl(), equalTo(issue.getUrl()));
assertThat(card.getContent().getRepository().getUrl(), equalTo(repo.getUrl()));
} finally {
repo.delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,46 @@
"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,
"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": "[email protected]",
"twitter_username": null,
"is_verified": false,
"has_organization_projects": true,
"has_repository_projects": true,
"public_repos": 9,
"public_repos": 20,
"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",
"updated_at": "2020-06-04T05:56:10Z",
"type": "Organization",
"total_private_repos": 0,
"owned_private_repos": 0,
"total_private_repos": 2,
"owned_private_repos": 2,
"private_gists": 0,
"disk_usage": 132,
"disk_usage": 11979,
"collaborators": 0,
"billing_email": "[email protected]",
"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_create_public_pages": true,
"members_can_create_private_pages": true,
"plan": {
"name": "free",
"space": 976562499,
"private_repos": 0,
"filled_seats": 4,
"seats": 0
"private_repos": 10000,
"filled_seats": 29,
"seats": 3
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"owner_url": "https://api.github.com/orgs/hub4j-test-org",
"url": "https://api.github.com/projects/3312449",
"html_url": "https://github.com/orgs/hub4j-test-org/projects/31",
"columns_url": "https://api.github.com/projects/3312449/columns",
"id": 3312449,
"node_id": "MDc6UHJvamVjdDMzMTI0NDk=",
"url": "https://api.github.com/projects/13495086",
"html_url": "https://github.com/orgs/hub4j-test-org/projects/32",
"columns_url": "https://api.github.com/projects/13495086/columns",
"id": 13495086,
"node_id": "PRO_kwDOAHMfo84Azesu",
"name": "test-project",
"body": "This is a test project",
"number": 31,
"number": 32,
"state": "open",
"creator": {
"login": "bitwiseman",
Expand All @@ -29,8 +29,8 @@
"type": "User",
"site_admin": false
},
"created_at": "2019-10-04T17:25:11Z",
"updated_at": "2019-10-04T17:25:11Z",
"created_at": "2021-10-11T15:43:37Z",
"updated_at": "2021-10-11T15:43:37Z",
"organization_permission": "write",
"private": true
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"id": 212868194,
"node_id": "MDEwOlJlcG9zaXRvcnkyMTI4NjgxOTQ=",
"id": 415990154,
"node_id": "R_kgDOGMuBig",
"name": "repo-for-project-card",
"full_name": "hub4j-test-org/repo-for-project-card",
"private": false,
"owner": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"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",
Expand Down Expand Up @@ -64,9 +64,9 @@
"labels_url": "https://api.github.com/repos/hub4j-test-org/repo-for-project-card/labels{/name}",
"releases_url": "https://api.github.com/repos/hub4j-test-org/repo-for-project-card/releases{/id}",
"deployments_url": "https://api.github.com/repos/hub4j-test-org/repo-for-project-card/deployments",
"created_at": "2019-10-04T17:25:12Z",
"updated_at": "2019-10-04T17:25:12Z",
"pushed_at": "2019-10-04T17:25:13Z",
"created_at": "2021-10-11T15:43:39Z",
"updated_at": "2021-10-11T15:43:39Z",
"pushed_at": "2021-10-11T15:43:39Z",
"git_url": "git://github.com/hub4j-test-org/repo-for-project-card.git",
"ssh_url": "[email protected]:hub4j-test-org/repo-for-project-card.git",
"clone_url": "https://github.com/hub4j-test-org/repo-for-project-card.git",
Expand All @@ -87,23 +87,31 @@
"disabled": false,
"open_issues_count": 0,
"license": null,
"allow_forking": true,
"is_template": 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,
"organization": {
"login": "hub4j-test-org",
"id": 7544739,
"node_id": "MDEyOk9yZ2FuaXphdGlvbjc1NDQ3Mzk=",
"avatar_url": "https://avatars3.githubusercontent.com/u/7544739?v=4",
"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",
Expand All @@ -120,5 +128,5 @@
"site_admin": false
},
"network_count": 0,
"subscribers_count": 2
"subscribers_count": 0
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"url": "https://api.github.com/projects/columns/16361848",
"project_url": "https://api.github.com/projects/13495086",
"cards_url": "https://api.github.com/projects/columns/16361848/cards",
"id": 16361848,
"node_id": "PC_lAPOAHMfo84AzesuzgD5qXg",
"name": "column-one",
"created_at": "2021-10-11T15:43:38Z",
"updated_at": "2021-10-11T15:43:38Z"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"url": "https://api.github.com/projects/columns/cards/27353274",
"project_url": "https://api.github.com/projects/3312449",
"id": 27353274,
"node_id": "MDExOlByb2plY3RDYXJkMjczNTMyNzQ=",
"url": "https://api.github.com/projects/columns/cards/70575561",
"project_url": "https://api.github.com/projects/13495086",
"id": 70575561,
"node_id": "PRC_lADOAHMfo84AzesuzgQ05ck",
"note": "This is a card",
"archived": false,
"creator": {
Expand All @@ -25,7 +25,7 @@
"type": "User",
"site_admin": false
},
"created_at": "2019-10-04T17:25:11Z",
"updated_at": "2019-10-04T17:25:11Z",
"column_url": "https://api.github.com/projects/columns/6706803"
}
"created_at": "2021-10-11T15:43:38Z",
"updated_at": "2021-10-11T15:43:38Z",
"column_url": "https://api.github.com/projects/columns/16361848"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"url": "https://api.github.com/projects/columns/cards/27353276",
"project_url": "https://api.github.com/projects/3312449",
"id": 27353276,
"node_id": "MDExOlByb2plY3RDYXJkMjczNTMyNzY=",
"url": "https://api.github.com/projects/columns/cards/70575566",
"project_url": "https://api.github.com/projects/13495086",
"id": 70575566,
"node_id": "PRC_lADOAHMfo84AzesuzgQ05c4",
"note": null,
"archived": false,
"creator": {
Expand All @@ -25,8 +25,8 @@
"type": "User",
"site_admin": false
},
"created_at": "2019-10-04T17:25:14Z",
"updated_at": "2019-10-04T17:25:14Z",
"column_url": "https://api.github.com/projects/columns/6706803",
"created_at": "2021-10-11T15:43:41Z",
"updated_at": "2021-10-11T15:43:41Z",
"column_url": "https://api.github.com/projects/columns/16361848",
"content_url": "https://api.github.com/repos/hub4j-test-org/repo-for-project-card/issues/1"
}
}
Loading

0 comments on commit 1cdbc17

Please sign in to comment.