From 385f2bc357bcd544c156fec154a814148146bb6a Mon Sep 17 00:00:00 2001 From: Olga Borzenkova Date: Fri, 20 Nov 2020 15:03:02 +0300 Subject: [PATCH 1/3] add draft PRs support --- .../src/main/scala/github4s/domain/PullRequest.scala | 11 +++++++---- .../interpreters/PullRequestsInterpreter.scala | 4 ++-- .../src/test/scala/github4s/unit/EncodersSpec.scala | 9 ++++++++- .../test/scala/github4s/unit/PullRequestsSpec.scala | 3 ++- github4s/src/test/scala/github4s/utils/TestData.scala | 10 +++++++--- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/github4s/src/main/scala/github4s/domain/PullRequest.scala b/github4s/src/main/scala/github4s/domain/PullRequest.scala index 99ac51a8f..ad65a3f1d 100644 --- a/github4s/src/main/scala/github4s/domain/PullRequest.scala +++ b/github4s/src/main/scala/github4s/domain/PullRequest.scala @@ -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( @@ -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( @@ -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, diff --git a/github4s/src/main/scala/github4s/interpreters/PullRequestsInterpreter.scala b/github4s/src/main/scala/github4s/interpreters/PullRequestsInterpreter.scala index eceef6e77..c78b51f3b 100644 --- a/github4s/src/main/scala/github4s/interpreters/PullRequestsInterpreter.scala +++ b/github4s/src/main/scala/github4s/interpreters/PullRequestsInterpreter.scala @@ -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) } diff --git a/github4s/src/test/scala/github4s/unit/EncodersSpec.scala b/github4s/src/test/scala/github4s/unit/EncodersSpec.scala index 3816c82dc..d140d79a8 100644 --- a/github4s/src/test/scala/github4s/unit/EncodersSpec.scala +++ b/github4s/src/test/scala/github4s/unit/EncodersSpec.scala @@ -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), + isDraft + ) val expectedJsonString = s""" diff --git a/github4s/src/test/scala/github4s/unit/PullRequestsSpec.scala b/github4s/src/test/scala/github4s/unit/PullRequestsSpec.scala index 1be951d64..00ac1c9fa 100644 --- a/github4s/src/test/scala/github4s/unit/PullRequestsSpec.scala +++ b/github4s/src/test/scala/github4s/unit/PullRequestsSpec.scala @@ -82,7 +82,8 @@ class PullRequestsSpec extends BaseSpec { validHead, validBase, "Please pull this in!", - Some(true) + Some(true), + isDraft ) implicit val httpClientMock = httpClientMockPost[CreatePullRequestData, PullRequest]( diff --git a/github4s/src/test/scala/github4s/utils/TestData.scala b/github4s/src/test/scala/github4s/utils/TestData.scala index 89f66f607..6c11b947e 100644 --- a/github4s/src/test/scala/github4s/utils/TestData.scala +++ b/github4s/src/test/scala/github4s/utils/TestData.scala @@ -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 isDraft = false + + val validNewPullRequestData = + NewPullRequestData("Amazing new feature", "Please pull this in!", isDraft) + val invalidNewPullRequestData = NewPullRequestData("", "", isDraft) val validNewPullRequestIssue = NewPullRequestIssue(31) val invalidNewPullRequestIssue = NewPullRequestIssue(5) @@ -249,7 +252,8 @@ trait TestData { base = None, head = None, user = None, - assignee = None + assignee = None, + draft = isDraft ) val pullRequestFile = PullRequestFile( From 82f1e3e3cded90ad6cf9e6f836aaadf00fa33a68 Mon Sep 17 00:00:00 2001 From: Olga Borzenkova Date: Mon, 23 Nov 2020 10:51:51 +0300 Subject: [PATCH 2/3] fix doc, rename param in tests --- github4s/src/test/scala/github4s/unit/EncodersSpec.scala | 2 +- .../src/test/scala/github4s/unit/PullRequestsSpec.scala | 2 +- github4s/src/test/scala/github4s/utils/TestData.scala | 8 ++++---- microsite/docs/pull_request.md | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/github4s/src/test/scala/github4s/unit/EncodersSpec.scala b/github4s/src/test/scala/github4s/unit/EncodersSpec.scala index d140d79a8..47d8eaccf 100644 --- a/github4s/src/test/scala/github4s/unit/EncodersSpec.scala +++ b/github4s/src/test/scala/github4s/unit/EncodersSpec.scala @@ -73,7 +73,7 @@ class EncodersSpec extends AnyFlatSpec with Matchers with TestData { validBase, validCommitMsg, Some(false), - isDraft + draft ) val expectedJsonString = diff --git a/github4s/src/test/scala/github4s/unit/PullRequestsSpec.scala b/github4s/src/test/scala/github4s/unit/PullRequestsSpec.scala index 00ac1c9fa..b66f929e7 100644 --- a/github4s/src/test/scala/github4s/unit/PullRequestsSpec.scala +++ b/github4s/src/test/scala/github4s/unit/PullRequestsSpec.scala @@ -83,7 +83,7 @@ class PullRequestsSpec extends BaseSpec { validBase, "Please pull this in!", Some(true), - isDraft + draft ) implicit val httpClientMock = httpClientMockPost[CreatePullRequestData, PullRequest]( diff --git a/github4s/src/test/scala/github4s/utils/TestData.scala b/github4s/src/test/scala/github4s/utils/TestData.scala index 6c11b947e..f4e8241ed 100644 --- a/github4s/src/test/scala/github4s/utils/TestData.scala +++ b/github4s/src/test/scala/github4s/utils/TestData.scala @@ -141,11 +141,11 @@ trait TestData { val validBase = "master" val invalidBase = "" - val isDraft = false + val draft = false val validNewPullRequestData = - NewPullRequestData("Amazing new feature", "Please pull this in!", isDraft) - val invalidNewPullRequestData = NewPullRequestData("", "", isDraft) + NewPullRequestData("Amazing new feature", "Please pull this in!", draft) + val invalidNewPullRequestData = NewPullRequestData("", "", draft) val validNewPullRequestIssue = NewPullRequestIssue(31) val invalidNewPullRequestIssue = NewPullRequestIssue(5) @@ -253,7 +253,7 @@ trait TestData { head = None, user = None, assignee = None, - draft = isDraft + draft = draft ) val pullRequestFile = PullRequestFile( diff --git a/microsite/docs/pull_request.md b/microsite/docs/pull_request.md index 9bc7f2157..d0d19214c 100644 --- a/microsite/docs/pull_request.md +++ b/microsite/docs/pull_request.md @@ -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)) From 015f1a3c08a9adf0b1cb15ee48163392c053a274 Mon Sep 17 00:00:00 2001 From: Olga Borzenkova Date: Mon, 23 Nov 2020 11:01:24 +0300 Subject: [PATCH 3/3] fix EncodersSpec --- github4s/src/test/scala/github4s/unit/EncodersSpec.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/github4s/src/test/scala/github4s/unit/EncodersSpec.scala b/github4s/src/test/scala/github4s/unit/EncodersSpec.scala index 47d8eaccf..7dece3e69 100644 --- a/github4s/src/test/scala/github4s/unit/EncodersSpec.scala +++ b/github4s/src/test/scala/github4s/unit/EncodersSpec.scala @@ -83,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