Skip to content

Commit

Permalink
Merge pull request #1981 from psttf/master
Browse files Browse the repository at this point in the history
Added support for GitLab draft MRs
  • Loading branch information
fthomas authored Mar 2, 2021
2 parents 1a10544 + 9d1f4b9 commit f6ccb08
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ final private[gitlab] case class MergeRequestPayload(

private[gitlab] object MergeRequestPayload {
def apply(id: String, projectId: Long, data: NewPullRequestData): MergeRequestPayload =
MergeRequestPayload(id, data.title, data.body, projectId, data.head, data.base)
MergeRequestPayload(
id,
List(if (data.draft) "Draft: " else "", data.title).mkString,
data.body,
projectId,
data.head,
data.base
)
}

final private[gitlab] case class MergeRequestOut(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.scalasteward.core.vcs.gitlab

import io.circe.syntax._
import io.circe.literal._
import munit.FunSuite
import org.scalasteward.core.git.Branch
import org.scalasteward.core.vcs.data.NewPullRequestData
import org.scalasteward.core.vcs.gitlab.GitLabJsonCodec._

class MergeRequestPayloadTest extends FunSuite {
private val master = Branch("master")
private val data = NewPullRequestData(
"Test MR title",
"Test MR body",
"source",
master
)
private val id = "123"
private val projectId = 321L

test("asJson") {
val obtained = MergeRequestPayload(id, projectId, data).asJson
val expected =
json"""{
"id" : "123",
"title" : "Test MR title",
"description" : "Test MR body",
"target_project_id" : 321,
"source_branch" : "source",
"target_branch" : "master"
}"""
assertEquals(obtained, expected)
}

test("asJson for draft MR") {
val obtained = MergeRequestPayload(id, projectId, data.copy(draft = true)).asJson
val expected =
json"""{
"id" : "123",
"title" : "Draft: Test MR title",
"description" : "Test MR body",
"target_project_id" : 321,
"source_branch" : "source",
"target_branch" : "master"
}"""
assertEquals(obtained, expected)
}
}

0 comments on commit f6ccb08

Please sign in to comment.