Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class MergeRequestParams implements Serializable {
private List<Long> reviewerIds;
private Long milestoneId;
private List<String> labels;
private List<String> addLabels;
private List<String> removeLabels;
private String description;
private Long targetProjectId;
private StateEvent stateEvent;
Expand Down Expand Up @@ -132,6 +134,56 @@ public MergeRequestParams withLabels(String[] labels) {
return (this);
}

/**
* Add labels to the merge request (without affecting existing labels).
* If a label does not already exist, this creates a new project label and assigns it to the merge request.
* This is for merge request updates only.
*
* @param addLabels the List of labels to add
* @return the reference to this MergeRequestParams instance
*/
public MergeRequestParams withAddLabels(List<String> addLabels) {
this.addLabels = addLabels;
return (this);
}

/**
* Add labels to the merge request (without affecting existing labels).
* If a label does not already exist, this creates a new project label and assigns it to the merge request.
* This is for merge request updates only.
*
* @param addLabels the array of labels to add
* @return the reference to this MergeRequestParams instance
*/
public MergeRequestParams withAddLabels(String[] addLabels) {
this.addLabels = (addLabels != null ? Arrays.asList(addLabels) : null);
return (this);
}

/**
* Remove labels from the merge request (without affecting other labels).
* This is for merge request updates only.
*
* @param removeLabels the List of labels to remove
* @return the reference to this MergeRequestParams instance
*/
public MergeRequestParams withRemoveLabels(List<String> removeLabels) {
this.removeLabels = removeLabels;
return (this);
}

/**
* Remove labels from the merge request (without affecting other labels).
* This is for merge request updates only.
*
* @param removeLabels the array of labels to remove
* @return the reference to this MergeRequestParams instance
*/
public MergeRequestParams withRemoveLabels(String[] removeLabels) {
this.removeLabels = (removeLabels != null ? Arrays.asList(removeLabels) : null);
return (this);
}

/**
* Set the description of the merge request. Limited to 1,048,576 characters.
*
Expand Down Expand Up @@ -266,7 +318,10 @@ public GitLabForm getForm(boolean isCreate) {
.withParam("target_project_id", targetProjectId)
.withParam("approvals_before_merge", approvalsBeforeMerge);
} else {
form.withParam("state_event", stateEvent).withParam("discussion_locked", discussionLocked);
form.withParam("state_event", stateEvent)
.withParam("discussion_locked", discussionLocked)
.withParam("add_labels", (addLabels != null ? String.join(",", addLabels) : null))
.withParam("remove_labels", (removeLabels != null ? String.join(",", removeLabels) : null));
}

return (form);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.util.Arrays;

import org.gitlab4j.models.GitLabForm;
import org.gitlab4j.models.GitLabFormValue;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -58,4 +60,32 @@ public void testNoDraftWithNullTitle() {
assertNotNull(titleFormValue);
assertNull(titleFormValue.getValue());
}

@Test
public void testAddLabels() {
MergeRequestParams params = new MergeRequestParams().withAddLabels(Arrays.asList("bug", "urgent"));

GitLabForm form = params.getForm(false);
assertEquals("bug,urgent", form.getFormValues().get("add_labels").getValue());
}

@Test
public void testRemoveLabels() {
MergeRequestParams params = new MergeRequestParams().withRemoveLabels(new String[] {"wontfix"});

GitLabForm form = params.getForm(false);
assertEquals("wontfix", form.getFormValues().get("remove_labels").getValue());
}

@Test
public void testNoAddRemoveLabelsOnCreate() {
MergeRequestParams params = new MergeRequestParams()
.withTitle("T")
.withAddLabels(Arrays.asList("bug"))
.withRemoveLabels(Arrays.asList("wontfix"));

GitLabForm form = params.getForm(true);
assertNull(form.getFormValues().get("add_labels"));
assertNull(form.getFormValues().get("remove_labels"));
}
}
Loading