From 60259a69da23a8df4904869fb4643358d19bdca7 Mon Sep 17 00:00:00 2001 From: MadnessIRL <78970141+MadnessIRL@users.noreply.github.com> Date: Thu, 28 Nov 2024 20:13:28 +0100 Subject: [PATCH] Add attributes "created_at", "internal" for NotesApi commits and DiscussionApi merge requests (#1194) Co-authored-by: Davide Santonocito --- .../java/org/gitlab4j/api/DiscussionsApi.java | 34 +++++++++++++++++++ src/main/java/org/gitlab4j/api/NotesApi.java | 11 ++++-- .../java/org/gitlab4j/api/models/Setting.java | 6 ++-- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/DiscussionsApi.java b/src/main/java/org/gitlab4j/api/DiscussionsApi.java index 78fd58295..71f0c7e01 100644 --- a/src/main/java/org/gitlab4j/api/DiscussionsApi.java +++ b/src/main/java/org/gitlab4j/api/DiscussionsApi.java @@ -11,6 +11,7 @@ import org.gitlab4j.api.models.Discussion; import org.gitlab4j.api.models.Note; import org.gitlab4j.api.models.Position; +import org.gitlab4j.api.utils.ISO8601; /** * This class implements the client side API for the GitLab Discussions API. @@ -657,6 +658,39 @@ public Discussion createCommitDiscussion( return (response.readEntity(Discussion.class)); } + /** + * Creates a new discussion to a single project commit. This is similar to creating + * a note but other comments (replies) can be added to it later. + * + *
GitLab Endpoint: POST /projects/:id/repository/commits/:commit_sha/discussions
+ * + * @param projectIdOrPath projectIdOrPath the project in the form of an Long(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) (Optional) + * @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) + throws GitLabApiException { + + GitLabApiForm formData = new GitLabApiForm().withParam("body", body, true); + if (createdAt != null) { + formData.withParam("created_at", ISO8601.toString(createdAt)); + } + + 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. * diff --git a/src/main/java/org/gitlab4j/api/NotesApi.java b/src/main/java/org/gitlab4j/api/NotesApi.java index 9ef939a8a..27b594827 100644 --- a/src/main/java/org/gitlab4j/api/NotesApi.java +++ b/src/main/java/org/gitlab4j/api/NotesApi.java @@ -8,6 +8,7 @@ import javax.ws.rs.core.Response; import org.gitlab4j.api.models.Note; +import org.gitlab4j.api.utils.ISO8601; public class NotesApi extends AbstractApi { @@ -500,12 +501,18 @@ public Note getMergeRequestNote(Object projectIdOrPath, Long mergeRequestIid, Lo * @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance * @param mergeRequestIid the merge request IID to create the notes for * @param body the content of note + * @param createdAt date the discussion was created (requires admin or project/group owner rights) (Optional) * @return the created Note instance * @throws GitLabApiException if any exception occurs */ - public Note createMergeRequestNote(Object projectIdOrPath, Long mergeRequestIid, String body) + public Note createMergeRequestNote( + Object projectIdOrPath, Long mergeRequestIid, String body, Date createdAt, boolean internal) throws GitLabApiException { - GitLabApiForm formData = new GitLabApiForm().withParam("body", body, true); + GitLabApiForm formData = + new GitLabApiForm().withParam("body", body, true).withParam("internal", internal); + if (createdAt != null) { + formData.withParam("created_at", ISO8601.toString(createdAt)); + } Response response = post( Response.Status.CREATED, formData, diff --git a/src/main/java/org/gitlab4j/api/models/Setting.java b/src/main/java/org/gitlab4j/api/models/Setting.java index cc48a72f4..781f9dabb 100644 --- a/src/main/java/org/gitlab4j/api/models/Setting.java +++ b/src/main/java/org/gitlab4j/api/models/Setting.java @@ -488,7 +488,7 @@ public enum Setting { /** * Gitaly fast operation timeout, in seconds. Some Gitaly operations are * expected to be fast. If they exceed this threshold, there may be a problem - * with a storage shard and ‘failing fast’ can help maintain the stability of + * with a storage shard and 'failing fast' can help maintain the stability of * the GitLab instance. Set to 0 to disable timeouts. */ GITALY_TIMEOUT_FAST(Integer.class), @@ -1534,7 +1534,7 @@ public enum Setting { /** * When rate limiting is enabled via the throttle_* settings, send this plain text response - * when a rate limit is exceeded. ‘Retry later’ is sent if this is blank. + * when a rate limit is exceeded. 'Retry later' is sent if this is blank. */ RATE_LIMITING_RESPONSE_TEXT(String.class), @@ -1575,7 +1575,7 @@ public enum Setting { USER_DEACTIVATION_EMAILS_ENABLED(Boolean.class), /** - * track or compress. Sets the behavior for Sidekiq job size limits. Default: ‘compress’. + * track or compress. Sets the behavior for Sidekiq job size limits. Default: 'compress'. */ SIDEKIQ_JOB_LIMITER_MODE(String.class),