Skip to content

Commit 92fa67a

Browse files
committed
Change head.repo on pull requests to Option
Pull requests can have their forks deleted: https://stackoverflow.com/questions/36071272/fix-unknown-repository-of-an-opened-pr-after-deleted-the-fork isaacs/github#168 This means the head.repo could be null, although this isn't documented in the API doc for listing pull requests: https://developer.github.com/v3/pulls/#list-pull-requests This causes github-api to throw an exception: java.util.NoSuchElementException: None.get Here's how to recreate the bug with a JSON payload in a file. import org.json4s.JArray import org.json4s.jackson.JsonMethods.parse import codecheck.github.models.PullRequest val json = scala.io.Source.fromFile("data/prs.json").getLines.mkString parse(json).asInstanceOf[JArray].arr.map(PullRequest(_)).map(_.head.repo.name)
1 parent 715c795 commit 92fa67a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/main/scala/codecheck/github/models/PullRequest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ case class PullRequestRef(value: JValue) extends AbstractJson(value) {
5656
def ref = get("ref")
5757
def sha = get("sha")
5858
lazy val user = User(value \ "user")
59-
lazy val repo = Repository(value \ "repo")
59+
lazy val repo = objectOpt("repo")(Repository(_))
6060
}
6161

6262
case class PullRequest(value: JValue) extends AbstractJson(value) {

src/test/scala/PullRequestOpSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ class PullRequestOpSpec extends FunSpec with api.Constants {
2424
assert(list.exists(_.deletions == None))
2525
assert(list.exists(_.changed_files == None))
2626
assert(list.exists(_.maintainer_can_modify == None))
27-
assert(list.exists(_.base.repo.full_name == s"$otherUser/$otherUserRepo"))
27+
assert(list.exists(_.base.repo.exists(_.full_name == s"$otherUser/$otherUserRepo")))
2828
assert(list.exists(_.base.user.login == otherUser))
29-
assert(list.exists(_.base.repo.name == otherUserRepo))
29+
assert(list.exists(_.base.repo.exists(_.name == otherUserRepo)))
3030
}
3131
}
3232

0 commit comments

Comments
 (0)