Skip to content

Commit

Permalink
Add support for Epics notes (#1205)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini authored Dec 16, 2024
1 parent bed8df5 commit 6fe39a4
Showing 1 changed file with 216 additions and 0 deletions.
216 changes: 216 additions & 0 deletions gitlab4j-api/src/main/java/org/gitlab4j/api/NotesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,4 +534,220 @@ public void deleteMergeRequestNote(Object projectIdOrPath, Long mergeRequestIid,
"notes",
noteId);
}

/**
* Get a list of the epics's notes.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_id/notes</code></pre>
*
* @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<Note> 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.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_id/notes</code></pre>
*
* @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<Note> 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<List<Note>>() {}));
}

/**
* Get a Pager of epics's notes.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_id/notes</code></pre>
*
* @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<Note> getEpicNotes(Object groupIdOrPath, Long epicId, int itemsPerPage) throws GitLabApiException {
return (new Pager<Note>(
this,
Note.class,
itemsPerPage,
null,
"groups",
getGroupIdOrPath(groupIdOrPath),
"epics",
epicId,
"notes"));
}

/**
* Get a Stream of the epics's notes.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_id/notes</code></pre>
*
* @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<Note> getEpicNotesStream(Object groupIdOrPath, Long epicId) throws GitLabApiException {
return (getEpicNotes(groupIdOrPath, epicId, getDefaultPerPage()).stream());
}

/**
* Get the specified epics's note.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_id/notes/:note_id</code></pre>
*
* @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.
*
* <pre><code>GitLab Endpoint: POST /groups/:id/epics/:epic_id/notes/:note_id</code></pre>
*
* @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.
*
* <pre><code>GitLab Endpoint: POST /groups/:id/epics/:epic_id/notes/:note_id</code></pre>
*
* @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.
*
* <pre><code>GitLab Endpoint: POST /groups/:id/epics/:epic_id/notes/:note_id</code></pre>
*
* @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.
*
* <pre><code>GitLab Endpoint: PUT /groups/:id/epics/:epic_id/notes/:note_id</code></pre>
*
* @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.
*
* <pre><code>GitLab Endpoint: DELETE /groups/:id/epics/:epic_id/notes/:note_id</code></pre>
*
* @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);
}
}

0 comments on commit 6fe39a4

Please sign in to comment.