Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draft PRs support #577

Merged
merged 5 commits into from
Nov 23, 2020
Merged
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
11 changes: 7 additions & 4 deletions github4s/src/main/scala/github4s/domain/PullRequest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ final case class PullRequest(
base: Option[PullRequestBase] = None,
head: Option[PullRequestBase] = None,
user: Option[User] = None,
assignee: Option[User] = None
assignee: Option[User] = None,
draft: Boolean
)

final case class PullRequestBase(
Expand Down Expand Up @@ -66,7 +67,8 @@ final case class CreatePullRequestData(
head: String,
base: String,
body: String,
maintainer_can_modify: Option[Boolean] = Some(true)
maintainer_can_modify: Option[Boolean] = Some(true),
draft: Boolean
) extends CreatePullRequest

final case class CreatePullRequestIssue(
Expand Down Expand Up @@ -103,8 +105,9 @@ final case object PRFilterOrderAsc extends PRFilterDirection("asc")
final case object PRFilterOrderDesc extends PRFilterDirection("desc")

sealed trait NewPullRequest
final case class NewPullRequestData(title: String, body: String) extends NewPullRequest
final case class NewPullRequestIssue(issue: Int) extends NewPullRequest
final case class NewPullRequestData(title: String, body: String, draft: Boolean)
extends NewPullRequest
final case class NewPullRequestIssue(issue: Int) extends NewPullRequest

final case class PullRequestReview(
id: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class PullRequestsInterpreter[F[_]](implicit client: HttpClient[F]) extends Pull
headers: Map[String, String]
): F[GHResponse[PullRequest]] = {
val data: CreatePullRequest = newPullRequest match {
case NewPullRequestData(title, body) =>
CreatePullRequestData(title, head, base, body, maintainerCanModify)
case NewPullRequestData(title, body, draft) =>
CreatePullRequestData(title, head, base, body, maintainerCanModify, draft)
case NewPullRequestIssue(issue) =>
CreatePullRequestIssue(issue, head, base, maintainerCanModify)
}
Expand Down
12 changes: 10 additions & 2 deletions github4s/src/test/scala/github4s/unit/EncodersSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ class EncodersSpec extends AnyFlatSpec with Matchers with TestData {

"CreatePullRequest encoder" should "encode the CreatePullRequestData" in {
val createPullRequest: CreatePullRequest =
CreatePullRequestData(validIssueTitle, validHead, validBase, validCommitMsg, Some(false))
CreatePullRequestData(
validIssueTitle,
validHead,
validBase,
validCommitMsg,
Some(false),
draft
)

val expectedJsonString =
s"""
Expand All @@ -76,7 +83,8 @@ class EncodersSpec extends AnyFlatSpec with Matchers with TestData {
| "head": "$validHead",
| "base": "$validBase",
| "body": "$validCommitMsg",
| "maintainer_can_modify": false
| "maintainer_can_modify": false,
| "draft": $draft
| }
""".stripMargin

Expand Down
3 changes: 2 additions & 1 deletion github4s/src/test/scala/github4s/unit/PullRequestsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class PullRequestsSpec extends BaseSpec {
validHead,
validBase,
"Please pull this in!",
Some(true)
Some(true),
draft
)

implicit val httpClientMock = httpClientMockPost[CreatePullRequestData, PullRequest](
Expand Down
10 changes: 7 additions & 3 deletions github4s/src/test/scala/github4s/utils/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,11 @@ trait TestData {
val validBase = "master"
val invalidBase = ""

val validNewPullRequestData = NewPullRequestData("Amazing new feature", "Please pull this in!")
val invalidNewPullRequestData = NewPullRequestData("", "")
val draft = false

val validNewPullRequestData =
NewPullRequestData("Amazing new feature", "Please pull this in!", draft)
val invalidNewPullRequestData = NewPullRequestData("", "", draft)

val validNewPullRequestIssue = NewPullRequestIssue(31)
val invalidNewPullRequestIssue = NewPullRequestIssue(5)
Expand Down Expand Up @@ -249,7 +252,8 @@ trait TestData {
base = None,
head = None,
user = None,
assignee = None
assignee = None,
draft = draft
)

val pullRequestFile = PullRequestFile(
Expand Down
2 changes: 1 addition & 1 deletion microsite/docs/pull_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ import github4s.domain.NewPullRequestData
val createPullRequestData = gh.pullRequests.createPullRequest(
"47deg",
"github4s",
NewPullRequestData("title", "body"),
NewPullRequestData("title", "body", draft = false),
"my-branch",
"base-branch",
Some(true))
Expand Down