Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Epics notes #1205

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading