Skip to content

Commit

Permalink
Support multiple assignees in IssuesApi#assignIssue(..) (gitlab4j#1170)
Browse files Browse the repository at this point in the history
Co-authored-by: Mirko Tschäni <[email protected]>
  • Loading branch information
jmini and mirkotschaeni authored Sep 23, 2024
1 parent 5f91f01 commit db3b639
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/main/java/org/gitlab4j/api/IssuesApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ public Issue updateIssue(Object projectIdOrPath, Long issueIid, String title, St
}

/**
* Updates an existing project issue. This call can also be used to mark an issue as closed.
* Updates an existing project issue to change the assignee.
*
* <pre><code>GitLab Endpoint: PUT /projects/:id/issues/:issue_iid</code></pre>
*
Expand All @@ -561,12 +561,32 @@ public Issue updateIssue(Object projectIdOrPath, Long issueIid, String title, St
* @throws GitLabApiException if any exception occurs
*/
public Issue assignIssue(Object projectIdOrPath, Long issueIid, Long assigneeId) throws GitLabApiException {
return assignIssue(projectIdOrPath, issueIid, Collections.singletonList(assigneeId));
}

/**
* Updates an existing project issue to change the assignees.
*
* <pre><code>GitLab Endpoint: PUT /projects/:id/issues/:issue_iid</code></pre>
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance, required
* @param issueIid the issue IID to update, required
* @param assigneeIds the IDs of the user to assign issue to, required, use an empty list to clear the assignees
* @return an instance of the updated Issue
* @throws GitLabApiException if any exception occurs
*/
public Issue assignIssue(Object projectIdOrPath, Long issueIid, List<Long> assigneeIds) throws GitLabApiException {

if (issueIid == null) {
throw new RuntimeException("issue IID cannot be null");
}

GitLabApiForm formData = new GitLabApiForm().withParam("assignee_ids", Collections.singletonList(assigneeId));
// replace empty list with an invalid userId (clears the assignees in gitlab)
if (assigneeIds.isEmpty()) {
assigneeIds = Collections.singletonList(0L);
}

GitLabApiForm formData = new GitLabApiForm().withParam("assignee_ids", assigneeIds);
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid);
return (response.readEntity(Issue.class));
}
Expand Down

0 comments on commit db3b639

Please sign in to comment.