gitlab4j-api icon indicating copy to clipboard operation
gitlab4j-api copied to clipboard

IssuesApi: introduce new method for issue locking

Open tarnonero opened this issue 4 years ago • 0 comments

Hello dear maintainers, it would be nice to have a new method for issue locking inside the IssuesApi class. Actually it could be implemented in two ways:

  1. This implemention is a rework of an already existing method
  public Issue updateIssue(Object projectIdOrPath, Integer issueIid, String title, String description, Boolean confidential,  List<Integer> assigneeIds,
            Integer milestoneId, String labels, StateEvent stateEvent, Boolean discussionLocked, Date updatedAt, Date dueDate) throws GitLabApiException {

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

        GitLabApiForm formData = new GitLabApiForm()
                .withParam("title", title)
                .withParam("description", description)
                .withParam("confidential", confidential)
                .withParam("assignee_ids", assigneeIds)
                .withParam("milestone_id", milestoneId)
                .withParam("labels", labels)
                .withParam("state_event", stateEvent)
                .withParam("discussion_locked", discussionLocked)
                .withParam("due_date", dueDate);
        Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "issues", issueIid);
        return (response.readEntity(Issue.class));
    }

updateIssue() method would need and additional input parameter Boolean discussionLocked used lock the given issue.

  1. This implementation creates the specific lockIssue() method for locking the given issue and it could look like:
 public Issue lockIssue(Object projectIdOrPath, Integer issueIid, Boolean discussionLocked) throws GitLabApiException {

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

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

The first implementation is better as it allows to update the given issue with need parameters and make only one API call. Thanks, Taras

#nonèperfarepolemica

tarnonero avatar Sep 29 '21 16:09 tarnonero