Skip to content

Commit 02d88e8

Browse files
committed
Support getting repository from project card
Closes #1097
1 parent b92c060 commit 02d88e8

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/main/java/org/kohsuke/github/GHIssue.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ GHIssue wrap(GHRepository owner) {
7979
return this;
8080
}
8181

82+
String getRepositoryUrlPath() {
83+
String url = getUrl().toString();
84+
int index = url.indexOf("/issues");
85+
if (index == -1) {
86+
index = url.indexOf("/pulls");
87+
}
88+
return url.substring(0, index);
89+
}
90+
8291
/**
8392
* Repository to which the issue belongs.
8493
*

src/main/java/org/kohsuke/github/GHProjectCard.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public GHProjectColumn getColumn() throws IOException {
115115
}
116116

117117
/**
118-
* Gets content.
118+
* Gets content. May be a {@link GHPullRequest} or a {@link GHIssue}.
119119
*
120120
* @return the content
121121
* @throws IOException
@@ -125,11 +125,16 @@ public GHIssue getContent() throws IOException {
125125
if (StringUtils.isEmpty(content_url))
126126
return null;
127127
try {
128+
GHIssue issue;
128129
if (content_url.contains("/pulls")) {
129-
return root().createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHPullRequest.class);
130+
issue = root().createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHPullRequest.class);
130131
} else {
131-
return root().createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHIssue.class);
132+
issue = root().createRequest().withUrlPath(getContentUrl().getPath()).fetch(GHIssue.class);
132133
}
134+
GHRepository repository =
135+
root().createRequest().withUrlPath(issue.getRepositoryUrlPath()).fetch(GHRepository.class);
136+
issue.wrap(repository);
137+
return issue;
133138
} catch (FileNotFoundException e) {
134139
return null;
135140
}

src/test/java/org/kohsuke/github/GHProjectCardTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public void testCreateCardFromIssue() throws IOException {
5555
GHIssue issue = repo.createIssue("new-issue").body("With body").create();
5656
GHProjectCard card = column.createCard(issue);
5757
assertThat(card.getContentUrl(), equalTo(issue.getUrl()));
58+
assertThat(card.getContent(), notNullValue());
59+
assertThat(card.getContent().getRepository(), notNullValue());
5860
} finally {
5961
repo.delete();
6062
}

0 commit comments

Comments
 (0)