Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b5514b8

Browse filesBrowse files
committed
added a method to create a new commit comment
1 parent 31a6eca commit b5514b8
Copy full SHA for b5514b8

File tree

Expand file treeCollapse file tree

4 files changed

+36
-2
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+36
-2
lines changed

‎src/main/java/org/kohsuke/github/GHCommit.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHCommit.java
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,26 @@ protected void wrapUp(GHCommitComment[] page) {
216216
};
217217
}
218218

219+
/**
220+
* Creates a commit comment.
221+
*
222+
* I'm not sure how path/line/position parameters interact with each other.
223+
*/
224+
public GHCommitComment createComment(String body, String path, Integer line, Integer position) throws IOException {
225+
GHCommitComment r = new Poster(owner.root,V3)
226+
.with("body",body)
227+
.with("path",path)
228+
.with("line",line)
229+
.with("position",position)
230+
.withCredential()
231+
.to(String.format("/repos/%s/%s/commits/%s/comments",owner.getOwnerName(),owner.getName(),sha),GHCommitComment.class);
232+
return r.wrap(owner);
233+
}
234+
235+
public GHCommitComment createComment(String body) throws IOException {
236+
return createComment(body,null,null,null);
237+
}
238+
219239
GHCommit wrapUp(GHRepository owner) {
220240
this.owner = owner;
221241
return this;

‎src/main/java/org/kohsuke/github/GHCommitComment.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/GHCommitComment.java
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
* @author Kohsuke Kawaguchi
1111
* @see GHRepository#listCommitComments()
1212
* @see GHCommit#listComments()
13+
* @see GHCommit#createComment(String, String, Integer, Integer)
1314
*/
1415
public class GHCommitComment {
1516
private GHRepository owner;

‎src/main/java/org/kohsuke/github/Poster.java

Copy file name to clipboardExpand all lines: src/main/java/org/kohsuke/github/Poster.java
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ public Poster with(String key, int value) {
8686
return _with(key, value);
8787
}
8888

89+
public Poster with(String key, Integer value) {
90+
if (value!=null)
91+
_with(key, value.intValue());
92+
return this;
93+
}
94+
8995
public Poster with(String key, boolean value) {
9096
return _with(key, value);
9197
}

‎src/test/java/org/kohsuke/AppTest.java

Copy file name to clipboardExpand all lines: src/test/java/org/kohsuke/AppTest.java
+9-2Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,17 @@ public void testCommitComment() throws Exception {
117117
List<GHCommitComment> batch = comments.iterator().nextPage();
118118
for (GHCommitComment comment : batch) {
119119
System.out.println(comment.getBody());
120-
assertSame(comment.getOwner(),r);
120+
assertSame(comment.getOwner(), r);
121121
}
122122
}
123-
123+
124+
public void tryCreateCommitComment() throws Exception {
125+
GitHub gitHub = GitHub.connect();
126+
GHCommit commit = gitHub.getUser("kohsuke").getRepository("sandbox-ant").getCommit("8ae38db0ea5837313ab5f39d43a6f73de3bd9000");
127+
GHCommitComment c = commit.createComment("[testing](http://kohsuse.org/)");
128+
System.out.println(c);
129+
}
130+
124131
public void tryHook() throws Exception {
125132
GitHub gitHub = GitHub.connect();
126133
GHRepository r = gitHub.getMyself().getRepository("test2");

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.