1919import java .util .Collections ;
2020import java .util .List ;
2121
22+ import de .linsin .github .rest .domain .Comment ;
2223import de .linsin .github .rest .domain .Issue ;
2324import de .linsin .github .rest .domain .Repository ;
25+ import de .linsin .github .rest .resource .IssueCommentRequest ;
2426import de .linsin .github .rest .resource .IssueRequest ;
2527import de .linsin .github .rest .resource .IssueResponse ;
2628import de .linsin .github .rest .resource .IssuesResponse ;
27- import de .linsin .github .rest .resource .ManipulateIssueRequest ;
29+ import de .linsin .github .rest .resource .Request ;
30+ import de .linsin .github .rest .resource .IssueCommentResponse ;
2831import org .springframework .util .Assert ;
2932import org .springframework .web .client .RestTemplate ;
3033
@@ -126,7 +129,7 @@ public Issue open(Repository argRepository, Issue argIssue) {
126129 Assert .hasText (argIssue .getTitle ());
127130 Assert .hasText (argIssue .getBody ());
128131
129- ManipulateIssueRequest req = new ManipulateIssueRequest (username , apiToken , argIssue .getTitle (), argIssue .getBody ());
132+ IssueRequest req = new IssueRequest (username , apiToken , argIssue .getTitle (), argIssue .getBody ());
130133 IssueResponse resp = template .postForObject (OPEN_ISSUE_URL , req , IssueResponse .class , argRepository .getOwner (), argRepository .getName ());
131134
132135 return resp .getIssue ();
@@ -147,7 +150,7 @@ public Issue reopen(Repository argRepository, Issue argIssue) {
147150
148151 Assert .isTrue (argIssue .getNumber () > 0 );
149152
150- IssueRequest req = new IssueRequest (username , apiToken );
153+ Request req = new Request (username , apiToken );
151154 IssueResponse resp = template .postForObject (REOPEN_ISSUE_URL , req , IssueResponse .class , argRepository .getOwner (), argRepository .getName (), String .valueOf (argIssue .getNumber ()));
152155
153156 return resp .getIssue ();
@@ -167,7 +170,7 @@ public void close(Repository argRepository, Issue argIssue) {
167170
168171 Assert .isTrue (argIssue .getNumber () > 0 );
169172
170- IssueRequest req = new IssueRequest (username , apiToken );
173+ Request req = new Request (username , apiToken );
171174 template .postForObject (CLOSE_ISSUE_URL , req , IssueResponse .class , argRepository .getOwner (), argRepository .getName (), String .valueOf (argIssue .getNumber ()));
172175 }
173176
@@ -176,7 +179,7 @@ public void close(Repository argRepository, Issue argIssue) {
176179 * Edits the existing {@link Issue} passed, which resides in the provided {@link Repository}
177180 * Note: so far only id, title and body are used from passed instance
178181 *
179- * @param argRepository {@link Repository} instance used to open issue
182+ * @param argRepository {@link Repository} instance used to edit issue
180183 * @param argIssue {@link Issue} instance containing id, title and body of the issue
181184 * @return the {@link Issue} instance which was edited
182185 * @throws IllegalArgumentException in case passed Issue doesn't contain an id, body or title
@@ -190,12 +193,36 @@ public Issue edit(Repository argRepository, Issue argIssue) {
190193 Assert .hasText (argIssue .getTitle ());
191194 Assert .hasText (argIssue .getBody ());
192195
193- ManipulateIssueRequest req = new ManipulateIssueRequest (username , apiToken , argIssue .getTitle (), argIssue .getBody ());
196+ IssueRequest req = new IssueRequest (username , apiToken , argIssue .getTitle (), argIssue .getBody ());
194197 IssueResponse resp = template .postForObject (EDIT_ISSUE_URL , req , IssueResponse .class , argRepository .getOwner (), argRepository .getName (), String .valueOf (argIssue .getNumber ()));
195198
196199 return resp .getIssue ();
197200 }
198201
202+ /**
203+ * Adds a comment to an exisiting {@link Issue}, which resides in the provided {@link Repository}
204+ * Note: only adding comments is supported by the github API http://support.github.com/discussions/repos/1112-retreiving-comments-for-an-issue
205+ *
206+ * @param argRepository {@link Repository} instance used to retrieve issue
207+ * @param argIssue {@link Issue} instance which exists in passed Repository
208+ * @param argComment {@link Comment} which must contain a comment
209+ * @return the {@link Comment} which was added
210+ * @throws IllegalArgumentException in case passed Issue doesn't contain an id
211+ * @throws NullPointerException in case passed repository, issue or comment is null
212+ * @throws HttpClientErrorException in case passed user, repository or issue doesn't exist
213+ */
214+ public Comment comment (Repository argRepository , Issue argIssue , Comment argComment ) {
215+ RestTemplate template = initTemplate ();
216+
217+ Assert .isTrue (argIssue .getNumber () > 0 );
218+ Assert .hasText (argComment .getComment ());
219+
220+ IssueCommentRequest req = new IssueCommentRequest (username , apiToken , argComment .getComment ());
221+ IssueCommentResponse resp = template .postForObject (COMMENT_ISSUE_URL , req , IssueCommentResponse .class , argRepository .getOwner (), argRepository .getName (), String .valueOf (argIssue .getNumber ()));
222+
223+ return resp .getComment ();
224+ }
225+
199226 // TODO implement comment
200227
201228 protected List <Issue > doBrowse (Repository argRepository , String argUrl ) {
0 commit comments