Skip to content

Commit bb3bfe4

Browse files
committed
added support for the issue comments
1 parent 561f839 commit bb3bfe4

3 files changed

Lines changed: 102 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ public void reopen() throws IOException {
116116
new Poster(root).withCredential().to(getApiRoute("reopen"));
117117
}
118118

119+
/**
120+
* Obtains all the comments associated with this issue.
121+
*/
122+
public List<GHIssueComment> getComments() throws IOException {
123+
return root.retrieve(getApiRoute("comments"), JsonIssueComments.class).wrap(this);
124+
}
125+
119126
private String getApiRoute(String verb) {
120127
return "/issues/"+verb+"/"+owner.getOwnerName()+"/"+owner.getName()+"/"+number;
121128
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Copyright (c) 2010, Kohsuke Kawaguchi
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
package org.kohsuke.github;
25+
26+
import java.io.IOException;
27+
import java.util.Date;
28+
29+
/**
30+
* Comment to the issue
31+
*
32+
* @author Kohsuke Kawaguchi
33+
*/
34+
public class GHIssueComment {
35+
GHIssue owner;
36+
37+
private String body, gravatar_id, user, created_at, updated_at;
38+
private int id;
39+
40+
/**
41+
* Gets the issue to which this comment is associated.
42+
*/
43+
public GHIssue getParent() {
44+
return owner;
45+
}
46+
47+
/**
48+
* The comment itself.
49+
*/
50+
public String getBody() {
51+
return body;
52+
}
53+
54+
public Date getCreatedAt() {
55+
return GitHub.parseDate(created_at);
56+
}
57+
58+
public Date getUpdatedAt() {
59+
return GitHub.parseDate(updated_at);
60+
}
61+
62+
public int getId() {
63+
return id;
64+
}
65+
66+
/**
67+
* Gets the ID of the user who posted this comment.
68+
*/
69+
public String getUserName() {
70+
return user;
71+
}
72+
73+
/**
74+
* Gets the user who posted this comment.
75+
*/
76+
public GHUser getUser() throws IOException {
77+
return owner.root.getUser(user);
78+
}
79+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.kohsuke.github;
2+
3+
import java.util.List;
4+
5+
/**
6+
* @author Kohsuke Kawaguchi
7+
*/
8+
class JsonIssueComments {
9+
List<GHIssueComment> comments;
10+
11+
List<GHIssueComment> wrap(GHIssue owner) {
12+
for (GHIssueComment c : comments)
13+
c.owner = owner;
14+
return comments;
15+
}
16+
}

0 commit comments

Comments
 (0)