diff --git a/README.md b/README.md
index fce3587da..6f863b4c1 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,7 @@ To utilize GitLab4J™ API in your Java project, simply add the following de
```java
dependencies {
...
- compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.11.1'
+ compile group: 'org.gitlab4j', name: 'gitlab4j-api', version: '4.11.2'
}
```
@@ -23,7 +23,7 @@ dependencies {
GitLab Endpoint: GET /projects/:id/commits/:commit_id/discussions
+ * GitLab Endpoint: GET /projects/:id/repository/commits/:commit_sha/discussions
*
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
- * @param commitId the internal ID of the commit
+ * @param commitSha the SHA of the commit to get discussions for
* @return a list containing all the discussions for the specified commit
* @throws GitLabApiException if any exception occurs during execution
*/
- public ListGitLab Endpoint: GET /projects/:id/commits/:commit_id/discussions
+ * GitLab Endpoint: GET /projects/:id/repository/commits/:commit_sha/discussions
*
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
- * @param commitId the internal ID of the commit
+ * @param commitSha the SHA of the commit to get discussions for
* @param maxItems the maximum number of Discussion instances to get, if < 1 will fetch all Discussion instances for the commit
* @return a list containing the discussions for the specified commit
* @throws GitLabApiException if any exception occurs during execution
*/
- public ListGitLab Endpoint: GET /projects/:id/commits/:commit_id/discussions
+ * GitLab Endpoint: GET /projects/:id/repository/commits/:commit_sha/discussions
*
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
- * @param commitId the internal ID of the commit
+ * @param commitSha the SHA of the commit to get discussions for
* @param itemsPerPage the number of Discussion instances that will be fetched per page
* @return a Pager containing the Discussion instances for the specified commit
* @throws GitLabApiException if any exception occurs during execution
*/
- public PagerGitLab Endpoint: GET /projects/:id/commits/:commit_id/discussions
+ * GitLab Endpoint: GET /projects/:id/repository/commits/:commit_sha/discussions
*
* @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
- * @param commitId the internal ID of the commit
+ * @param commitSha the SHA of the commit to get discussions for
* @return a Stream instance containing the Discussion instances for the specified commit
* @throws GitLabApiException if any exception occurs during execution
*/
- public StreamGitLab Endpoint: GET /projects/:id/repository/commits/:commit_sha/discussions/:discussion_id
+ *
+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param commitSha the SHA of the commit to get discussions for
+ * @param discussionId the ID of the discussion
+ * @return the Discussion instance specified by discussionId for the specified commit
+ * @throws GitLabApiException if any exception occurs during execution
+ */
+ public Discussion getCommitDiscussion(Object projectIdOrPath, String commitSha, String discussionId) throws GitLabApiException {
+ Response response = get(Response.Status.OK, null,
+ "projects", getProjectIdOrPath(projectIdOrPath), "repository", "commits", commitSha, "discussions", discussionId);
+ return (response.readEntity(Discussion.class));
+ }
+
+ /**
+ * Get an Optional instance of a single discussion for the specified commit.
+ *
+ * GitLab Endpoint: GET /projects/:id/repository/commits/:commit_sha/discussions/:discussion_id
+ *
+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param commitSha the SHA of the commit to get discussions for
+ * @param discussionId the ID of the discussion
+ * @return an Optional instance with the specified Discussion instance as a value
+ */
+ public OptionalGitLab Endpoint: POST /projects/:id/repository/commits/:commit_sha/discussions
+ *
+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param commitSha the commit SHA to create the discussion for
+ * @param body the content of a discussion
+ * @param createdAt date the discussion was created (requires admin or project/group owner rights)
+ * @param positionHash position when creating a diff note
+ * @param position a Position instance holding the position attributes
+ * @return a Discussion instance containing the newly created discussion
+ * @throws GitLabApiException if any exception occurs during execution
+ */
+ public Discussion createCommitDiscussion(Object projectIdOrPath, String commitSha,
+ String body, Date createdAt, String positionHash, Position position) throws GitLabApiException {
+
+ if (position == null) {
+ throw new GitLabApiException("position instance can not be null");
+ }
+
+ GitLabApiForm formData = new GitLabApiForm()
+ .withParam("body", body, true)
+ .withParam("created_at", createdAt)
+ .withParam("position", positionHash)
+ .withParam("position[base_sha]", position.getBaseSha(), true)
+ .withParam("position[start_sha]", position.getStartSha(), true)
+ .withParam("position[head_sha]", position.getHeadSha(), true)
+ .withParam("position[position_type]", position.getPositionType(), true)
+ .withParam("position[new_path]", position.getNewPath())
+ .withParam("position[new_line]", position.getNewLine())
+ .withParam("position[old_path]", position.getOldPath())
+ .withParam("position[old_line]", position.getOldLine())
+ .withParam("position[width]", position.getWidth())
+ .withParam("position[height]", position.getHeight())
+ .withParam("position[x]", position.getX())
+ .withParam("position[y]", position.getY());
+
+ Response response = post(Response.Status.CREATED, formData,
+ "projects", getProjectIdOrPath(projectIdOrPath), "repository", "commits", commitSha, "discussions");
+ return (response.readEntity(Discussion.class));
+ }
+
+ /**
+ * Adds a note to an existing commit discussion.
+ *
+ * GitLab Endpoint: POST /projects/:id/repository/commits/:commit_sha/discussions/:discussion_id/notes
+ *
+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param commitSha the commit SHA to create the discussion for
+ * @param discussionId the ID of a discussion
+ * @param body the content of a discussion
+ * @param createdAt date the discussion was created (requires admin or project/group owner rights)
+ * @return a Note instance containing the newly created discussion note
+ * @throws GitLabApiException if any exception occurs during execution
+ */
+ public Note addCommitDiscussionNote(Object projectIdOrPath, String commitSha, String discussionId,
+ String body, Date createdAt) throws GitLabApiException {
+
+ GitLabApiForm formData = new GitLabApiForm()
+ .withParam("body", body, true)
+ .withParam("created_at", createdAt);
+
+ Response response = post(Response.Status.CREATED, formData,
+ "projects", getProjectIdOrPath(projectIdOrPath),
+ "repository", "commits", commitSha, "discussions", discussionId, "notes");
+ return (response.readEntity(Note.class));
+ }
+
+ /**
+ * Modify an existing discussion note of a commit.
+ *
+ * GitLab Endpoint: PUT /projects/:id/repository/commits/:commit_sha/discussions/:discussion_id/notes
+ *
+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param commitSha the commit SHA to delete the discussion from
+ * @param discussionId the ID of a discussion
+ * @param noteId the note ID to delete
+ * @param body the content of a discussion
+ * @return a Note instance containing the updated discussion note
+ * @throws GitLabApiException if any exception occurs during execution
+ */
+ public Note modifyCommitDiscussionNote(Object projectIdOrPath,
+ String commitSha, String discussionId, Integer noteId, String body) throws GitLabApiException {
+
+ GitLabApiForm formData = new GitLabApiForm().withParam("body", body, true);
+ Response response = this.putWithFormData(Response.Status.OK, formData,
+ "projects", getProjectIdOrPath(projectIdOrPath),
+ "repository", "commits", commitSha, "discussions", discussionId, "notes", noteId);
+ return (response.readEntity(Note.class));
+ }
+
+ /**
+ *Resolve or unresolve an existing discussion note of a commit.
+ *
+ * GitLab Endpoint: PUT /projects/:id/repository/commits/:commit_sha/discussions/:discussion_id/notes
+ *
+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param commitSha the commit SHA to delete the discussion from
+ * @param discussionId the ID of a discussion
+ * @param noteId the note ID to delete
+ * @param resolved if true will resolve the note, false will unresolve the note
+ * @return a Note instance containing the updated discussion note
+ * @throws GitLabApiException if any exception occurs during execution
+ */
+ public Note resolveCommitDiscussionNote(Object projectIdOrPath,
+ String commitSha, String discussionId, Integer noteId, Boolean resolved) throws GitLabApiException {
+
+ GitLabApiForm queryParams = new GitLabApiForm().withParam("resolved", resolved);
+ Response response = this.put(Response.Status.OK, queryParams.asMap(),
+ "projects", getProjectIdOrPath(projectIdOrPath),
+ "repository", "commits", commitSha, "discussions", discussionId, "notes", noteId);
+ return (response.readEntity(Note.class));
+ }
+
+ /**
+ * Deletes an existing discussion note of a commit.
+ *
+ * GitLab Endpoint: DELETE /projects/:id/repository/commits/:commit_sha/discussions/:discussion_id/notes/:note_id
+ *
+ * @param projectIdOrPath projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
+ * @param commitSha the commit SHA to delete the discussion from
+ * @param discussionId the ID of a discussion
+ * @param noteId the note ID to delete
+ * @throws GitLabApiException if any exception occurs during execution
+ */
+ public void deleteCommitDiscussionNote(Object projectIdOrPath, String commitSha,
+ String discussionId, Integer noteId) throws GitLabApiException {
+ delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath),
+ "repository", commitSha, "discussions", discussionId, "notes", noteId);
+ }
}
diff --git a/src/test/java/org/gitlab4j/api/TestCommitDiscussionsApi.java b/src/test/java/org/gitlab4j/api/TestCommitDiscussionsApi.java
index fed14edb1..2472c6205 100644
--- a/src/test/java/org/gitlab4j/api/TestCommitDiscussionsApi.java
+++ b/src/test/java/org/gitlab4j/api/TestCommitDiscussionsApi.java
@@ -24,6 +24,7 @@
public class TestCommitDiscussionsApi implements Constants {
+ private static final String COMMIT_SHA = "abcdef1234567890";
@Mock private GitLabApi gitLabApi;
@Mock private GitLabApiClient gitLabApiClient;
@Spy private FakeResponse response;
@@ -32,7 +33,7 @@ public class TestCommitDiscussionsApi implements Constants {
@Before
public void setUp() throws Exception {
initMocks(this);
- response.init(Discussion.class, null, "commit-discussions.json");
+ response.init(Discussion.class, null, "commit-discussions.json");
when(gitLabApi.getApiClient()).thenReturn(gitLabApiClient);
when(gitLabApiClient.validateSecretToken(any())).thenReturn(true);
when(gitLabApiClient.get(attributeCaptor.capture(), Mockito.