From f24e3a1f250d0080e346a351a9c7d8f2a3c61ae3 Mon Sep 17 00:00:00 2001 From: Jeremie Bresson Date: Wed, 4 Dec 2024 10:22:43 +0100 Subject: [PATCH] Add support for Epics notes --- .../main/java/org/gitlab4j/api/NotesApi.java | 216 ++++++++++++++++++ 1 file changed, 216 insertions(+) diff --git a/gitlab4j-api/src/main/java/org/gitlab4j/api/NotesApi.java b/gitlab4j-api/src/main/java/org/gitlab4j/api/NotesApi.java index 3f296323..2530db96 100644 --- a/gitlab4j-api/src/main/java/org/gitlab4j/api/NotesApi.java +++ b/gitlab4j-api/src/main/java/org/gitlab4j/api/NotesApi.java @@ -534,4 +534,220 @@ public void deleteMergeRequestNote(Object projectIdOrPath, Long mergeRequestIid, "notes", noteId); } + + /** + * Get a list of the epics's notes. + * + *
GitLab Endpoint: GET /groups/:id/epics/:epic_id/notes
+ * + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance + * @param epicId the epic ID (not the IID!) to get the notes for + * @return a list of the epics's notes + * @throws GitLabApiException if any exception occurs + */ + public List getEpicNotes(Object groupIdOrPath, Long epicId) throws GitLabApiException { + return (getEpicNotes(groupIdOrPath, epicId, getDefaultPerPage()).all()); + } + + /** + * Get a list of the epic's notes using the specified page and per page settings. + * + *
GitLab Endpoint: GET /groups/:id/epics/:epic_id/notes
+ * + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance + * @param epicId the epic ID (not the IID!) to get the notes for + * @param page the page to get + * @param perPage the number of notes per page + * @return the list of notes in the specified range + * @throws GitLabApiException if any exception occurs + */ + public List getEpicNotes(Object groupIdOrPath, Long epicId, int page, int perPage) throws GitLabApiException { + Response response = get( + Response.Status.OK, + getPageQueryParams(page, perPage), + "groups", + getGroupIdOrPath(groupIdOrPath), + "epics", + epicId, + "notes"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get a Pager of epics's notes. + * + *
GitLab Endpoint: GET /groups/:id/epics/:epic_id/notes
+ * + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance + * @param epicId the epic ID (not the IID!) to get the notes for + * @param itemsPerPage the number of notes per page + * @return the list of notes in the specified range + * @throws GitLabApiException if any exception occurs + */ + public Pager getEpicNotes(Object groupIdOrPath, Long epicId, int itemsPerPage) throws GitLabApiException { + return (new Pager( + this, + Note.class, + itemsPerPage, + null, + "groups", + getGroupIdOrPath(groupIdOrPath), + "epics", + epicId, + "notes")); + } + + /** + * Get a Stream of the epics's notes. + * + *
GitLab Endpoint: GET /groups/:id/epics/:epic_id/notes
+ * + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance + * @param epicId the epic ID (not the IID!) to get the notes for + * @return a Stream of the epics's notes + * @throws GitLabApiException if any exception occurs + */ + public Stream getEpicNotesStream(Object groupIdOrPath, Long epicId) throws GitLabApiException { + return (getEpicNotes(groupIdOrPath, epicId, getDefaultPerPage()).stream()); + } + + /** + * Get the specified epics's note. + * + *
GitLab Endpoint: GET /groups/:id/epics/:epic_id/notes/:note_id
+ * + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance + * @param epicId the epic ID (not the IID!) to get the notes for + * @param noteId the ID of the Note to get + * @return a Note instance for the specified IDs + * @throws GitLabApiException if any exception occurs + */ + public Note getEpicNote(Object groupIdOrPath, Long epicId, Long noteId) throws GitLabApiException { + Response response = get( + Response.Status.OK, + getDefaultPerPageParam(), + "groups", + getGroupIdOrPath(groupIdOrPath), + "epics", + epicId, + "notes", + noteId); + return (response.readEntity(Note.class)); + } + + /** + * Create a epics's note. + * + *
GitLab Endpoint: POST /groups/:id/epics/:epic_id/notes/:note_id
+ * + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance @param groupIdOrPath the group ID to create the epics for + * @param epicId the epic ID (not the IID!) to create the notes for + * @param body the content of note + * @return the created Note instance + * @throws GitLabApiException if any exception occurs + */ + public Note createEpicNote(Object groupIdOrPath, Long epicId, String body) throws GitLabApiException { + return (createEpicNote(groupIdOrPath, epicId, body, null, null)); + } + + /** + * Create a epics's note. + * + *
GitLab Endpoint: POST /groups/:id/epics/:epic_id/notes/:note_id
+ * + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance + * @param epicId the epic ID (not the IID!) to create the notes for + * @param body the content of note + * @param createdAt the created time of note + * @return the created Note instance + * @throws GitLabApiException if any exception occurs + */ + public Note createEpicNote(Object groupIdOrPath, Long epicId, String body, Date createdAt) + throws GitLabApiException { + return (createEpicNote(groupIdOrPath, epicId, body, null, null)); + } + + /** + * Create a epics's note. + * + *
GitLab Endpoint: POST /groups/:id/epics/:epic_id/notes/:note_id
+ * + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance + * @param epicId the epic ID (not the IID!) to create the notes for + * @param body the content of note + * @param createdAt the created time of note + * @param internal whether the note shall be marked 'internal' + * @return the created Note instance + * @throws GitLabApiException if any exception occurs + */ + public Note createEpicNote(Object groupIdOrPath, Long epicId, String body, Date createdAt, Boolean internal) + throws GitLabApiException { + + GitLabApiForm formData = new GitLabApiForm() + .withParam("body", body, true) + .withParam("created_at", createdAt) + .withParam("internal", internal); + ; + Response response = post( + Response.Status.CREATED, formData, "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicId, "notes"); + return (response.readEntity(Note.class)); + } + + /** + * Update the specified epics's note. + * + *
GitLab Endpoint: PUT /groups/:id/epics/:epic_id/notes/:note_id
+ * + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance + * @param epicId the epic ID (not the IID!) to update the notes for + * @param noteId the ID of the node to update + * @param body the update content for the Note + * @return the modified Note instance + * @throws GitLabApiException if any exception occurs + */ + public Note updateEpicNote(Object groupIdOrPath, Long epicId, Long noteId, String body) throws GitLabApiException { + + GitLabApiForm formData = new GitLabApiForm().withParam("body", body, true); + Response response = put( + Response.Status.OK, + formData.asMap(), + "groups", + getGroupIdOrPath(groupIdOrPath), + "epics", + epicId, + "notes", + noteId); + return (response.readEntity(Note.class)); + } + + /** + * Delete the specified epics's note. + * + *
GitLab Endpoint: DELETE /groups/:id/epics/:epic_id/notes/:note_id
+ * + * @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance + * @param epicId the epic ID (not the IID!) to delete the notes for + * @param noteId the ID of the node to delete + * @throws GitLabApiException if any exception occurs + */ + public void deleteEpicNote(Object groupIdOrPath, Long epicId, Long noteId) throws GitLabApiException { + + if (epicId == null) { + throw new RuntimeException("epicId cannot be null"); + } + + if (noteId == null) { + throw new RuntimeException("noteId cannot be null"); + } + + delete( + Response.Status.NO_CONTENT, + getDefaultPerPageParam(), + "groups", + getGroupIdOrPath(groupIdOrPath), + "epics", + epicId, + "notes", + noteId); + } }