Skip to content

Commit 145d46b

Browse files
authored
Merge pull request #2980 from danielleontiev/github-create-pr-new-model
github: add dedicated model for create PR body
2 parents f12a861 + ab676e0 commit 145d46b

File tree

5 files changed

+415
-150
lines changed

5 files changed

+415
-150
lines changed

modules/core/src/main/scala/org/scalasteward/core/forge/data/NewPullRequestData.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
package org.scalasteward.core.forge.data
1818

1919
import cats.syntax.all._
20-
import io.circe.Encoder
21-
import io.circe.generic.semiauto._
2220
import org.http4s.Uri
2321
import org.scalasteward.core.data._
2422
import org.scalasteward.core.edit.EditAttempt
@@ -43,9 +41,6 @@ final case class NewPullRequestData(
4341
)
4442

4543
object NewPullRequestData {
46-
implicit val newPullRequestDataEncoder: Encoder[NewPullRequestData] =
47-
deriveEncoder
48-
4944
def bodyFor(
5045
update: Update,
5146
edits: List[EditAttempt],

modules/core/src/main/scala/org/scalasteward/core/forge/github/GitHubApiAlg.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,9 @@ final class GitHubApiAlg[F[_]](
4646

4747
/** https://developer.github.com/v3/pulls/#create-a-pull-request */
4848
override def createPullRequest(repo: Repo, data: NewPullRequestData): F[PullRequestOut] = {
49+
val payload = PullRequestPayload.from(data)
4950
val create = client
50-
.postWithBody[PullRequestOut, NewPullRequestData](url.pulls(repo), data, modify(repo))
51+
.postWithBody[PullRequestOut, PullRequestPayload](url.pulls(repo), payload, modify(repo))
5152
.adaptErr(SecondaryRateLimitExceeded.fromThrowable)
5253

5354
for {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2018-2023 Scala Steward contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.scalasteward.core.forge.github
18+
19+
import io.circe.Encoder
20+
import io.circe.generic.semiauto.deriveEncoder
21+
import org.scalasteward.core.forge.data.NewPullRequestData
22+
import org.scalasteward.core.git.Branch
23+
24+
final case class PullRequestPayload(
25+
title: String,
26+
body: String,
27+
head: String,
28+
base: Branch,
29+
draft: Boolean
30+
)
31+
object PullRequestPayload {
32+
implicit val encoder: Encoder[PullRequestPayload] = deriveEncoder
33+
34+
def from(newPullRequestData: NewPullRequestData): PullRequestPayload =
35+
PullRequestPayload(
36+
title = newPullRequestData.title,
37+
body = newPullRequestData.body,
38+
head = newPullRequestData.head,
39+
base = newPullRequestData.base,
40+
draft = newPullRequestData.draft
41+
)
42+
}

0 commit comments

Comments
 (0)