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
1 change: 1 addition & 0 deletions .tool-versions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is useful for those who use asdf. If you prefer, I can remove it.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java temurin-11.0.28+6
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class MergeRequestParams implements Serializable {
private Boolean discussionLocked;
private Boolean allowCollaboration;
private Integer approvalsBeforeMerge;
private Boolean draft;

/**
* Set the source branch. This is for merge request creation only.
Expand Down Expand Up @@ -220,6 +221,17 @@ public MergeRequestParams withApprovalsBeforeMerge(Integer approvalsBeforeMerge)
return (this);
}

/**
* Set the draft flag of the merge request.
*
* @param draft the draft flag to set
* @return the reference to this MergeRequestParams instance
*/
public MergeRequestParams withDraft(Boolean draft) {
this.draft = draft;
return (this);
}

/**
* Get the form params specified by this instance.
*
Expand All @@ -229,9 +241,14 @@ public MergeRequestParams withApprovalsBeforeMerge(Integer approvalsBeforeMerge)
*/
public GitLabForm getForm(boolean isCreate) {

String titleToUse = title;
if (Boolean.TRUE.equals(draft)) {
titleToUse = "Draft: " + (title != null ? title : "");
}

GitLabForm form = new GitLabForm()
.withParam("target_branch", targetBranch, isCreate)
.withParam("title", title, isCreate)
.withParam("title", titleToUse, isCreate)
.withParam("assignee_id", assigneeId)
.withParam("assignee_ids", assigneeIds)
.withParam("reviewer_ids", reviewerIds)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.gitlab4j.api.models;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.gitlab4j.models.GitLabForm;
import org.gitlab4j.models.GitLabFormValue;
import org.junit.jupiter.api.Test;

public class TestMergeRequestParams {

@Test
public void testDraftPrefix() {
MergeRequestParams params =
new MergeRequestParams().withTitle("My Title").withDraft(true);

GitLabForm form = params.getForm(true);
Object titleValue = form.getFormValues().get("title").getValue();
assertEquals("Draft: My Title", titleValue);
}

@Test
public void testNoDraftPrefix() {
MergeRequestParams params =
new MergeRequestParams().withTitle("My Title").withDraft(false);

GitLabForm form = params.getForm(true);
Object titleValue = form.getFormValues().get("title").getValue();
assertEquals("My Title", titleValue);
}

@Test
public void testNullDraftPrefix() {
MergeRequestParams params =
new MergeRequestParams().withTitle("My Title").withDraft(null);

GitLabForm form = params.getForm(true);
Object titleValue = form.getFormValues().get("title").getValue();
assertEquals("My Title", titleValue);
}

@Test
public void testDraftWithNullTitle() {
MergeRequestParams params = new MergeRequestParams().withTitle(null).withDraft(true);

GitLabForm form = params.getForm(true);
Object titleValue = form.getFormValues().get("title").getValue();
assertEquals("Draft: ", titleValue);
}

@Test
public void testNoDraftWithNullTitle() {
MergeRequestParams params = new MergeRequestParams().withTitle(null).withDraft(false);

GitLabForm form = params.getForm(true);
GitLabFormValue titleFormValue = form.getFormValues().get("title");
assertNotNull(titleFormValue);
assertNull(titleFormValue.getValue());
}
}
Loading