|
9 | 9 | import javax.ws.rs.core.GenericType; |
10 | 10 | import javax.ws.rs.core.Response; |
11 | 11 |
|
| 12 | +import org.gitlab4j.api.models.Comment; |
12 | 13 | import org.gitlab4j.api.models.Commit; |
13 | 14 | import org.gitlab4j.api.models.Diff; |
14 | 15 | import org.gitlab4j.api.utils.ISO8601; |
@@ -183,4 +184,44 @@ public List<Diff> getDiff(String projectPath, String sha) throws GitLabApiExcept |
183 | 184 | Response response = get(Response.Status.OK, null, "projects", projectPath, "repository", "commits", sha, "diff"); |
184 | 185 | return (response.readEntity(new GenericType<List<Diff>>() {})); |
185 | 186 | } |
| 187 | + |
| 188 | + /** |
| 189 | + * Get the comments of a commit in a project. |
| 190 | + * |
| 191 | + * GET /projects/:id/repository/commits/:sha/comments |
| 192 | + * |
| 193 | + * @param projectId the project ID that the commit belongs to |
| 194 | + * @param sha a commit hash or name of a branch or tag |
| 195 | + * @return a List of Comment instances for the specified project ID/sha pair |
| 196 | + * @throws GitLabApiException GitLabApiException if any exception occurs during execution |
| 197 | + */ |
| 198 | + public List<Comment> getComments(int projectId, String sha) throws GitLabApiException { |
| 199 | + Response response = get(Response.Status.OK, null, "projects", projectId, "repository", "commits", sha, "comments"); |
| 200 | + return (response.readEntity(new GenericType<List<Comment>>() {})); |
| 201 | + } |
| 202 | + |
| 203 | + /** |
| 204 | + * Add a comment to a commit. In order to post a comment in a particular line of a particular file, |
| 205 | + * you must specify the full commit SHA, the path, the line and lineType should be NEW. |
| 206 | + * |
| 207 | + * POST /projects/:id/repository/commits/:sha/comments |
| 208 | + * |
| 209 | + * @param projectId the project ID that the commit belongs to |
| 210 | + * @param sha a commit hash or name of a branch or tag |
| 211 | + * @param note the text of the comment, required |
| 212 | + * @param path the file path relative to the repository, optional |
| 213 | + * @param line the line number where the comment should be placed, optional |
| 214 | + * @param lineType the line type, optional |
| 215 | + * @return a Comment instance for the posted comment |
| 216 | + * @throws GitLabApiException GitLabApiException if any exception occurs during execution |
| 217 | + */ |
| 218 | + public Comment addComment(int projectId, String sha, String note, String path, Integer line, LineType lineType) throws GitLabApiException { |
| 219 | + GitLabApiForm formData = new GitLabApiForm() |
| 220 | + .withParam("note", note, true) |
| 221 | + .withParam("path", path) |
| 222 | + .withParam("line", line) |
| 223 | + .withParam("line_type", lineType); |
| 224 | + Response response = post(Response.Status.OK, formData, "projects", projectId, "repository", "commits", sha, "comments"); |
| 225 | + return (response.readEntity(Comment.class)); |
| 226 | + } |
186 | 227 | } |
0 commit comments