From cce02aec3d5d767ceb8f921114aa523f961f5c0b Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Fri, 22 May 2015 09:50:52 +0200 Subject: [PATCH 1/3] Add delete and update for GHIssueComment --- src/main/java/org/kohsuke/github/GHIssue.java | 5 +++-- .../org/kohsuke/github/GHIssueComment.java | 19 +++++++++++++++++++ .../github/GHPullRequestReviewComment.java | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 8c071a93f8..71394a6b0f 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -141,8 +141,9 @@ public URL getApiURL(){ /** * Updates the issue by adding a comment. */ - public void comment(String message) throws IOException { - new Requester(root).with("body",message).to(getIssuesApiRoute() + "/comments"); + public GHIssueComment comment(String message) throws IOException { + GHIssueComment r = new Requester(root).with("body",message).to(getIssuesApiRoute() + "/comments", GHIssueComment.class); + return r.wrapUp(this); } private void edit(String key, Object value) throws IOException { diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index 732c508a2d..f36b110499 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -79,4 +79,23 @@ public GHUser getUser() throws IOException { public URL getHtmlUrl() { return null; } + + /** + * Updates the body of the issue comment. + */ + public void update(String body) throws IOException { + new Requester(owner.root).with("body", body).method("PATCH").to(getCommentApiTail(), GHIssueComment.class); + this.body = body; + } + + /** + * Deletes this issue comment. + */ + public void delete() throws IOException { + new Requester(owner.root).method("DELETE").to(getCommentApiTail()); + } + + private String getCommentApiTail() { + return "/repos/"+owner.getRepository().getOwnerName()+"/"+owner.getRepository().getName()+"/issues/comments/" + id; + } } diff --git a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java index 09863f78cf..3051f4b700 100644 --- a/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java +++ b/src/main/java/org/kohsuke/github/GHPullRequestReviewComment.java @@ -94,6 +94,7 @@ protected String getApiRoute() { */ public void update(String body) throws IOException { new Requester(owner.root).method("PATCH").with("body", body).to(getApiRoute(),this); + this.body = body; } /** From b0c54ef0f10cbaea45fafe830832f13cf1b69f24 Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 17 Jul 2015 13:27:20 +0300 Subject: [PATCH 2/3] Restored backward compatibility with the former signature --- src/main/java/org/kohsuke/github/GHIssue.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHIssue.java b/src/main/java/org/kohsuke/github/GHIssue.java index 71394a6b0f..e7864087dd 100644 --- a/src/main/java/org/kohsuke/github/GHIssue.java +++ b/src/main/java/org/kohsuke/github/GHIssue.java @@ -24,6 +24,8 @@ package org.kohsuke.github; +import com.infradna.tool.bridge_method_injector.WithBridgeMethods; + import java.io.IOException; import java.net.URL; import java.util.Collection; @@ -140,7 +142,11 @@ public URL getApiURL(){ /** * Updates the issue by adding a comment. + * + * @return + * Newly posted comment. */ + @WithBridgeMethods(void.class) public GHIssueComment comment(String message) throws IOException { GHIssueComment r = new Requester(root).with("body",message).to(getIssuesApiRoute() + "/comments", GHIssueComment.class); return r.wrapUp(this); @@ -177,7 +183,7 @@ public void setBody(String body) throws IOException { } public void assignTo(GHUser user) throws IOException { - editIssue("assignee",user.getLogin()); + editIssue("assignee", user.getLogin()); } public void setLabels(String... labels) throws IOException { From 025806f0fd56b423f6f94d887e9858da6348b5ba Mon Sep 17 00:00:00 2001 From: Kohsuke Kawaguchi Date: Fri, 17 Jul 2015 13:29:07 +0300 Subject: [PATCH 3/3] Consistent name with other classes --- src/main/java/org/kohsuke/github/GHIssueComment.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/kohsuke/github/GHIssueComment.java b/src/main/java/org/kohsuke/github/GHIssueComment.java index f36b110499..3179fa93a6 100644 --- a/src/main/java/org/kohsuke/github/GHIssueComment.java +++ b/src/main/java/org/kohsuke/github/GHIssueComment.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.net.URL; -import java.util.Date; /** * Comment to the issue @@ -84,7 +83,7 @@ public URL getHtmlUrl() { * Updates the body of the issue comment. */ public void update(String body) throws IOException { - new Requester(owner.root).with("body", body).method("PATCH").to(getCommentApiTail(), GHIssueComment.class); + new Requester(owner.root).with("body", body).method("PATCH").to(getApiRoute(), GHIssueComment.class); this.body = body; } @@ -92,10 +91,10 @@ public void update(String body) throws IOException { * Deletes this issue comment. */ public void delete() throws IOException { - new Requester(owner.root).method("DELETE").to(getCommentApiTail()); + new Requester(owner.root).method("DELETE").to(getApiRoute()); } - private String getCommentApiTail() { + private String getApiRoute() { return "/repos/"+owner.getRepository().getOwnerName()+"/"+owner.getRepository().getName()+"/issues/comments/" + id; } }