Repository: scala-steward-org/scala-steward
Pull request #1934 (2021-02-15 18:58:32)

Extract correct PR URL from Bitbucket API response
Also add a test for the JSON decoding of PRs from Bitbucket API responses


Patch:
diff --git a/modules/core/src/main/scala/org/scalasteward/core/vcs/bitbucket/json.scala b/modules/core/src/main/scala/org/scalasteward/core/vcs/bitbucket/json.scala
index fdfbfa84..77166f56 100644
--- a/modules/core/src/main/scala/org/scalasteward/core/vcs/bitbucket/json.scala
+++ b/modules/core/src/main/scala/org/scalasteward/core/vcs/bitbucket/json.scala
@@ -42,7 +42,7 @@ private[bitbucket] object json {
       id <- c.downField("id").as[PullRequestNumber]
       title <- c.downField("title").as[String]
       state <- c.downField("state").as[PullRequestState]
-      html_url <- c.downField("links").downField("self").downField("href").as[Uri]
+      html_url <- c.downField("links").downField("html").downField("href").as[Uri]
     } yield PullRequestOut(html_url, state, id, title)
   }
 }


Test patch:
diff --git a/modules/core/src/test/scala/org/scalasteward/core/vcs/bitbucket/BitbucketApiAlgTest.scala b/modules/core/src/test/scala/org/scalasteward/core/vcs/bitbucket/BitbucketApiAlgTest.scala
index c5514b4b..1842df6a 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/vcs/bitbucket/BitbucketApiAlgTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/vcs/bitbucket/BitbucketApiAlgTest.scala
@@ -101,8 +101,8 @@ class BitbucketApiAlgTest extends FunSuite {
             "title": "scala-steward-pr",
             "state": "OPEN",
             "links": {
-                "self": {
-                    "href": "https://api.bitbucket.org/2.0/repositories/fthomas/base.g8/pullrequests/2"
+                "html": {
+                    "href": "https://bitbucket.org/fthomas/base.g8/pullrequests/2"
                 }
             }
           }"""
@@ -116,8 +116,8 @@ class BitbucketApiAlgTest extends FunSuite {
                   "title": "scala-steward-pr",
                   "state": "OPEN",
                   "links": {
-                      "self": {
-                          "href": "https://api.bitbucket.org/2.0/repositories/fthomas/base.g8/pullrequests/2"
+                      "html": {
+                          "href": "https://bitbucket.org/fthomas/base.g8/pullrequests/2"
                       }
                   }
               }
@@ -133,8 +133,8 @@ class BitbucketApiAlgTest extends FunSuite {
             "title": "scala-steward-pr",
             "state": "DECLINED",
             "links": {
-                "self": {
-                    "href": "https://api.bitbucket.org/2.0/repositories/fthomas/base.g8/pullrequests/2"
+                "html": {
+                    "href": "https://bitbucket.org/fthomas/base.g8/pullrequests/2"
                 }
             }
         }"""
@@ -142,9 +142,9 @@ class BitbucketApiAlgTest extends FunSuite {
     case POST -> Root / "repositories" / "fthomas" / "base.g8" / "pullrequests" /
         IntVar(_) / "comments" =>
       Created(json"""{
-                  "content": { 
+                  "content": {
                       "raw": "Superseded by #1234"
-                  } 
+                  }
           }""")
   }
 
@@ -157,7 +157,7 @@ class BitbucketApiAlgTest extends FunSuite {
     false
   )
 
-  private val prUrl = uri"https://api.bitbucket.org/2.0/repositories/fthomas/base.g8/pullrequests/2"
+  private val prUrl = uri"https://bitbucket.org/fthomas/base.g8/pullrequests/2"
   private val repo = Repo("fthomas", "base.g8")
   private val master = Branch("master")
   private val parent = RepoOut(
diff --git a/modules/core/src/test/scala/org/scalasteward/core/vcs/bitbucket/JsonCodecTest.scala b/modules/core/src/test/scala/org/scalasteward/core/vcs/bitbucket/JsonCodecTest.scala
index 1196ff11..bc39b672 100644
--- a/modules/core/src/test/scala/org/scalasteward/core/vcs/bitbucket/JsonCodecTest.scala
+++ b/modules/core/src/test/scala/org/scalasteward/core/vcs/bitbucket/JsonCodecTest.scala
@@ -1,8 +1,10 @@
 package org.scalasteward.core.vcs.bitbucket
 
 import io.circe.Json
+import io.circe.parser._
 import munit.FunSuite
-import org.scalasteward.core.vcs.data.PullRequestState
+import org.http4s.syntax.literals._
+import org.scalasteward.core.vcs.data.{PullRequestNumber, PullRequestOut, PullRequestState}
 
 class JsonCodecTest extends FunSuite {
   test("PullRequestStatus decoding of expected values") {
@@ -17,4 +19,184 @@ class JsonCodecTest extends FunSuite {
       assertEquals(json.pullRequestStateDecoder.decodeJson(Json.fromString(string)), Right(state))
     }
   }
+
+  test("PullRequestOut decoding") {
+    val rawResponse = """
+    {
+      "rendered": {
+        "description": {
+          "raw": "",
+          "markup": "markdown",
+          "html": "",
+          "type": "rendered"
+        },
+        "title": {
+          "raw": "Dummy PR",
+          "markup": "markdown",
+          "html": "<p>Dummy PR</p>",
+          "type": "rendered"
+        }
+      },
+      "type": "pullrequest",
+      "description": "",
+      "links": {
+        "decline": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/pullrequests/3/decline"
+        },
+        "diffstat": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/diffstat/acme-corp/my-scala-steward:ffbea2df0a61%0D71c045581b38?from_pullrequest_id=3"
+        },
+        "commits": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/pullrequests/3/commits"
+        },
+        "self": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/pullrequests/3"
+        },
+        "comments": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/pullrequests/3/comments"
+        },
+        "merge": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/pullrequests/3/merge"
+        },
+        "html": {
+          "href": "https://bitbucket.org/acme-corp/my-scala-steward/pull-requests/3"
+        },
+        "activity": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/pullrequests/3/activity"
+        },
+        "request-changes": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/pullrequests/3/request-changes"
+        },
+        "diff": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/diff/acme-corp/my-scala-steward:ffbea2df0a61%0D71c045581b38?from_pullrequest_id=3"
+        },
+        "approve": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/pullrequests/3/approve"
+        },
+        "statuses": {
+          "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/pullrequests/3/statuses"
+        }
+      },
+      "title": "Dummy PR",
+      "close_source_branch": false,
+      "reviewers": [],
+      "id": 3,
+      "destination": {
+        "commit": {
+          "hash": "71c045581b38",
+          "type": "commit",
+          "links": {
+            "self": {
+              "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/commit/71c045581b38"
+            },
+            "html": {
+              "href": "https://bitbucket.org/acme-corp/my-scala-steward/commits/71c045581b38"
+            }
+          }
+        },
+        "repository": {
+          "links": {
+            "self": {
+              "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward"
+            },
+            "html": {
+              "href": "https://bitbucket.org/acme-corp/my-scala-steward"
+            },
+            "avatar": {
+              "href": "https://bytebucket.org/ravatar/redacted"
+            }
+          },
+          "type": "repository",
+          "name": "my-scala-steward",
+          "full_name": "acme-corp/my-scala-steward",
+          "uuid": "redacted"
+        },
+        "branch": {
+          "name": "master"
+        }
+      },
+      "created_on": "2021-02-15T18:39:37.593077+00:00",
+      "summary": {
+        "raw": "",
+        "markup": "markdown",
+        "html": "",
+        "type": "rendered"
+      },
+      "source": {
+        "commit": {
+          "hash": "ffbea2df0a61",
+          "type": "commit",
+          "links": {
+            "self": {
+              "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward/commit/ffbea2df0a61"
+            },
+            "html": {
+              "href": "https://bitbucket.org/acme-corp/my-scala-steward/commits/ffbea2df0a61"
+            }
+          }
+        },
+        "repository": {
+          "links": {
+            "self": {
+              "href": "https://api.bitbucket.org/2.0/repositories/acme-corp/my-scala-steward"
+            },
+            "html": {
+              "href": "https://bitbucket.org/acme-corp/my-scala-steward"
+            },
+            "avatar": {
+              "href": "https://bytebucket.org/ravatar/redacted"
+            }
+          },
+          "type": "repository",
+          "name": "my-scala-steward",
+          "full_name": "acme-corp/my-scala-steward",
+          "uuid": "redacted"
+        },
+        "branch": {
+          "name": "dummy"
+        }
+      },
+      "comment_count": 0,
+      "state": "OPEN",
+      "task_count": 0,
+      "participants": [],
+      "reason": "",
+      "updated_on": "2021-02-15T18:39:37.654103+00:00",
+      "author": {
+        "display_name": "John Doe",
+        "uuid": "{redacted}",
+        "links": {
+          "self": {
+            "href": "https://api.bitbucket.org/2.0/users/redacted"
+          },
+          "html": {
+            "href": "https://bitbucket.org/redacted/"
+          },
+          "avatar": {
+            "href": "https://avatar-management--avatars.us-west-2.prod.public.atl-paas.net/initials/JD-0.png"
+          }
+        },
+        "nickname": "john.doe",
+        "type": "user",
+        "account_id": "redacted"
+      },
+      "merge_commit": null,
+      "closed_by": null
+    }
+    """
+
+    val expected = PullRequestOut(
+      html_url = uri"https://bitbucket.org/acme-corp/my-scala-steward/pull-requests/3",
+      state = PullRequestState.Open,
+      number = PullRequestNumber(3),
+      title = "Dummy PR"
+    )
+
+    val actual = for {
+      jsonValue <- parse(rawResponse)
+      decoded <- json.pullRequestOutDecoder.decodeJson(jsonValue)
+    } yield decoded
+
+    assertEquals(actual, Right(expected))
+  }
 }