Skip to content

Commit 9a640c0

Browse files
committed
Add test for unmarshalling github issue form JSON
1 parent 0423e4b commit 9a640c0

File tree

4 files changed

+143
-88
lines changed

4 files changed

+143
-88
lines changed

bot/resources/test-pr.json

Lines changed: 90 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
{
2-
"action": "opened",
3-
"number": 1943,
2+
"action": "synchronize",
3+
"number": 1958,
44
"pull_request": {
5-
"url": "https://api.github.com/repos/lampepfl/dotty/pulls/1943",
6-
"id": 104705912,
7-
"html_url": "https://github.com/lampepfl/dotty/pull/1943",
8-
"diff_url": "https://github.com/lampepfl/dotty/pull/1943.diff",
9-
"patch_url": "https://github.com/lampepfl/dotty/pull/1943.patch",
10-
"issue_url": "https://api.github.com/repos/lampepfl/dotty/issues/1943",
11-
"number": 1943,
5+
"url": "https://api.github.com/repos/lampepfl/dotty/pulls/1958",
6+
"id": 105198014,
7+
"html_url": "https://github.com/lampepfl/dotty/pull/1958",
8+
"diff_url": "https://github.com/lampepfl/dotty/pull/1958.diff",
9+
"patch_url": "https://github.com/lampepfl/dotty/pull/1958.patch",
10+
"issue_url": "https://api.github.com/repos/lampepfl/dotty/issues/1958",
11+
"number": 1958,
1212
"state": "open",
1313
"locked": false,
14-
"title": "Positioned#initialPos: Union the position of every children",
14+
"title": "WIP Add \"enum\" construct",
1515
"user": {
16-
"login": "smarter",
17-
"id": 63430,
18-
"avatar_url": "https://avatars.githubusercontent.com/u/63430?v=3",
16+
"login": "odersky",
17+
"id": 795990,
18+
"avatar_url": "https://avatars.githubusercontent.com/u/795990?v=3",
1919
"gravatar_id": "",
20-
"url": "https://api.github.com/users/smarter",
21-
"html_url": "https://github.com/smarter",
22-
"followers_url": "https://api.github.com/users/smarter/followers",
23-
"following_url": "https://api.github.com/users/smarter/following{/other_user}",
24-
"gists_url": "https://api.github.com/users/smarter/gists{/gist_id}",
25-
"starred_url": "https://api.github.com/users/smarter/starred{/owner}{/repo}",
26-
"subscriptions_url": "https://api.github.com/users/smarter/subscriptions",
27-
"organizations_url": "https://api.github.com/users/smarter/orgs",
28-
"repos_url": "https://api.github.com/users/smarter/repos",
29-
"events_url": "https://api.github.com/users/smarter/events{/privacy}",
30-
"received_events_url": "https://api.github.com/users/smarter/received_events",
20+
"url": "https://api.github.com/users/odersky",
21+
"html_url": "https://github.com/odersky",
22+
"followers_url": "https://api.github.com/users/odersky/followers",
23+
"following_url": "https://api.github.com/users/odersky/following{/other_user}",
24+
"gists_url": "https://api.github.com/users/odersky/gists{/gist_id}",
25+
"starred_url": "https://api.github.com/users/odersky/starred{/owner}{/repo}",
26+
"subscriptions_url": "https://api.github.com/users/odersky/subscriptions",
27+
"organizations_url": "https://api.github.com/users/odersky/orgs",
28+
"repos_url": "https://api.github.com/users/odersky/repos",
29+
"events_url": "https://api.github.com/users/odersky/events{/privacy}",
30+
"received_events_url": "https://api.github.com/users/odersky/received_events",
3131
"type": "User",
3232
"site_admin": false
3333
},
34-
"body": "Previously we missed some children, one consequence of this is that the\r\nposition of the typed tree corresponding to the lambda \"z => 1\" did not\r\ncontain the position of \"z\".\r\n\r\nReview by @odersky ",
35-
"created_at": "2017-02-05T16:51:01Z",
36-
"updated_at": "2017-02-05T16:51:01Z",
34+
"body": "This is a prototype implementation to add an \"enum\" construct to Scala. Scala enums give a more concise notation for \r\n\r\n - enums as in Java\r\n - ADTs\r\n - GADTs\r\n\r\nCurrent status\r\n\r\n - [x] First implementation\r\n - [x] Some test cases\r\n - [ ] A specification\r\n - [ ] An implementation of generic programming in the style of SYB. We need to clarify first exactly\r\n what we want from the compiler\r\n - [ ] A decision whether we want to go ahead with this",
35+
"created_at": "2017-02-08T11:29:18Z",
36+
"updated_at": "2017-02-09T09:18:27Z",
3737
"closed_at": null,
3838
"merged_at": null,
39-
"merge_commit_sha": null,
39+
"merge_commit_sha": "7100d31c76a0317b8cd3445970c463b133215252",
4040
"assignee": null,
4141
"assignees": [
4242

4343
],
4444
"milestone": null,
45-
"commits_url": "https://api.github.com/repos/lampepfl/dotty/pulls/1943/commits",
46-
"review_comments_url": "https://api.github.com/repos/lampepfl/dotty/pulls/1943/comments",
45+
"commits_url": "https://api.github.com/repos/lampepfl/dotty/pulls/1958/commits",
46+
"review_comments_url": "https://api.github.com/repos/lampepfl/dotty/pulls/1958/comments",
4747
"review_comment_url": "https://api.github.com/repos/lampepfl/dotty/pulls/comments{/number}",
48-
"comments_url": "https://api.github.com/repos/lampepfl/dotty/issues/1943/comments",
49-
"statuses_url": "https://api.github.com/repos/lampepfl/dotty/statuses/9e9206dbf3e1cbd378adcb9f65637d2cf331cc10",
48+
"comments_url": "https://api.github.com/repos/lampepfl/dotty/issues/1958/comments",
49+
"statuses_url": "https://api.github.com/repos/lampepfl/dotty/statuses/ce4051743d590721dc969c92c44a35147e1e3abc",
5050
"head": {
51-
"label": "dotty-staging:fix/lambda-position",
52-
"ref": "fix/lambda-position",
53-
"sha": "9e9206dbf3e1cbd378adcb9f65637d2cf331cc10",
51+
"label": "dotty-staging:add-enum",
52+
"ref": "add-enum",
53+
"sha": "ce4051743d590721dc969c92c44a35147e1e3abc",
5454
"user": {
5555
"login": "dotty-staging",
5656
"id": 6998674,
@@ -136,13 +136,13 @@
136136
"deployments_url": "https://api.github.com/repos/dotty-staging/dotty/deployments",
137137
"created_at": "2014-03-19T13:06:15Z",
138138
"updated_at": "2016-07-11T14:41:18Z",
139-
"pushed_at": "2017-02-05T16:50:41Z",
139+
"pushed_at": "2017-02-09T09:18:27Z",
140140
"git_url": "git://github.com/dotty-staging/dotty.git",
141141
"ssh_url": "git@github.com:dotty-staging/dotty.git",
142142
"clone_url": "https://github.com/dotty-staging/dotty.git",
143143
"svn_url": "https://github.com/dotty-staging/dotty",
144144
"homepage": "",
145-
"size": 27650,
145+
"size": 27676,
146146
"stargazers_count": 4,
147147
"watchers_count": 4,
148148
"language": "Scala",
@@ -162,7 +162,7 @@
162162
"base": {
163163
"label": "lampepfl:master",
164164
"ref": "master",
165-
"sha": "da7d7231b7f21fe1085abc569eb783590074a359",
165+
"sha": "75bea8dccce2bc3c0e8298ee71061c9871fd26ac",
166166
"user": {
167167
"login": "lampepfl",
168168
"id": 2684793,
@@ -247,68 +247,73 @@
247247
"releases_url": "https://api.github.com/repos/lampepfl/dotty/releases{/id}",
248248
"deployments_url": "https://api.github.com/repos/lampepfl/dotty/deployments",
249249
"created_at": "2012-12-06T12:57:33Z",
250-
"updated_at": "2017-02-05T01:04:39Z",
251-
"pushed_at": "2017-02-05T16:50:21Z",
250+
"updated_at": "2017-02-08T13:10:05Z",
251+
"pushed_at": "2017-02-09T08:51:58Z",
252252
"git_url": "git://github.com/lampepfl/dotty.git",
253253
"ssh_url": "git@github.com:lampepfl/dotty.git",
254254
"clone_url": "https://github.com/lampepfl/dotty.git",
255255
"svn_url": "https://github.com/lampepfl/dotty",
256256
"homepage": "http://dotty.epfl.ch",
257-
"size": 28511,
258-
"stargazers_count": 1447,
259-
"watchers_count": 1447,
257+
"size": 28896,
258+
"stargazers_count": 1452,
259+
"watchers_count": 1452,
260260
"language": "Scala",
261261
"has_issues": true,
262262
"has_downloads": true,
263263
"has_wiki": false,
264264
"has_pages": true,
265-
"forks_count": 212,
265+
"forks_count": 213,
266266
"mirror_url": null,
267-
"open_issues_count": 243,
268-
"forks": 212,
269-
"open_issues": 243,
270-
"watchers": 1447,
267+
"open_issues_count": 250,
268+
"forks": 213,
269+
"open_issues": 250,
270+
"watchers": 1452,
271271
"default_branch": "master"
272272
}
273273
},
274274
"_links": {
275275
"self": {
276-
"href": "https://api.github.com/repos/lampepfl/dotty/pulls/1943"
276+
"href": "https://api.github.com/repos/lampepfl/dotty/pulls/1958"
277277
},
278278
"html": {
279-
"href": "https://github.com/lampepfl/dotty/pull/1943"
279+
"href": "https://github.com/lampepfl/dotty/pull/1958"
280280
},
281281
"issue": {
282-
"href": "https://api.github.com/repos/lampepfl/dotty/issues/1943"
282+
"href": "https://api.github.com/repos/lampepfl/dotty/issues/1958"
283283
},
284284
"comments": {
285-
"href": "https://api.github.com/repos/lampepfl/dotty/issues/1943/comments"
285+
"href": "https://api.github.com/repos/lampepfl/dotty/issues/1958/comments"
286286
},
287287
"review_comments": {
288-
"href": "https://api.github.com/repos/lampepfl/dotty/pulls/1943/comments"
288+
"href": "https://api.github.com/repos/lampepfl/dotty/pulls/1958/comments"
289289
},
290290
"review_comment": {
291291
"href": "https://api.github.com/repos/lampepfl/dotty/pulls/comments{/number}"
292292
},
293293
"commits": {
294-
"href": "https://api.github.com/repos/lampepfl/dotty/pulls/1943/commits"
294+
"href": "https://api.github.com/repos/lampepfl/dotty/pulls/1958/commits"
295295
},
296296
"statuses": {
297-
"href": "https://api.github.com/repos/lampepfl/dotty/statuses/9e9206dbf3e1cbd378adcb9f65637d2cf331cc10"
297+
"href": "https://api.github.com/repos/lampepfl/dotty/statuses/ce4051743d590721dc969c92c44a35147e1e3abc"
298298
}
299299
},
300+
"requested_reviewers": [
301+
302+
],
300303
"merged": false,
301304
"mergeable": null,
302305
"mergeable_state": "unknown",
303306
"merged_by": null,
304-
"comments": 0,
305-
"review_comments": 0,
307+
"comments": 1,
308+
"review_comments": 2,
306309
"maintainer_can_modify": true,
307-
"commits": 1,
308-
"additions": 2,
309-
"deletions": 0,
310-
"changed_files": 1
310+
"commits": 13,
311+
"additions": 501,
312+
"deletions": 173,
313+
"changed_files": 29
311314
},
315+
"before": "a51a963005eb6f5a42a0cef7420a7008956e622a",
316+
"after": "ce4051743d590721dc969c92c44a35147e1e3abc",
312317
"repository": {
313318
"id": 7035651,
314319
"name": "dotty",
@@ -374,27 +379,27 @@
374379
"releases_url": "https://api.github.com/repos/lampepfl/dotty/releases{/id}",
375380
"deployments_url": "https://api.github.com/repos/lampepfl/dotty/deployments",
376381
"created_at": "2012-12-06T12:57:33Z",
377-
"updated_at": "2017-02-05T01:04:39Z",
378-
"pushed_at": "2017-02-05T16:50:21Z",
382+
"updated_at": "2017-02-08T13:10:05Z",
383+
"pushed_at": "2017-02-09T08:51:58Z",
379384
"git_url": "git://github.com/lampepfl/dotty.git",
380385
"ssh_url": "git@github.com:lampepfl/dotty.git",
381386
"clone_url": "https://github.com/lampepfl/dotty.git",
382387
"svn_url": "https://github.com/lampepfl/dotty",
383388
"homepage": "http://dotty.epfl.ch",
384-
"size": 28511,
385-
"stargazers_count": 1447,
386-
"watchers_count": 1447,
389+
"size": 28896,
390+
"stargazers_count": 1452,
391+
"watchers_count": 1452,
387392
"language": "Scala",
388393
"has_issues": true,
389394
"has_downloads": true,
390395
"has_wiki": false,
391396
"has_pages": true,
392-
"forks_count": 212,
397+
"forks_count": 213,
393398
"mirror_url": null,
394-
"open_issues_count": 243,
395-
"forks": 212,
396-
"open_issues": 243,
397-
"watchers": 1447,
399+
"open_issues_count": 250,
400+
"forks": 213,
401+
"open_issues": 250,
402+
"watchers": 1452,
398403
"default_branch": "master"
399404
},
400405
"organization": {
@@ -411,21 +416,21 @@
411416
"description": null
412417
},
413418
"sender": {
414-
"login": "smarter",
415-
"id": 63430,
416-
"avatar_url": "https://avatars.githubusercontent.com/u/63430?v=3",
419+
"login": "felixmulder",
420+
"id": 1530049,
421+
"avatar_url": "https://avatars.githubusercontent.com/u/1530049?v=3",
417422
"gravatar_id": "",
418-
"url": "https://api.github.com/users/smarter",
419-
"html_url": "https://github.com/smarter",
420-
"followers_url": "https://api.github.com/users/smarter/followers",
421-
"following_url": "https://api.github.com/users/smarter/following{/other_user}",
422-
"gists_url": "https://api.github.com/users/smarter/gists{/gist_id}",
423-
"starred_url": "https://api.github.com/users/smarter/starred{/owner}{/repo}",
424-
"subscriptions_url": "https://api.github.com/users/smarter/subscriptions",
425-
"organizations_url": "https://api.github.com/users/smarter/orgs",
426-
"repos_url": "https://api.github.com/users/smarter/repos",
427-
"events_url": "https://api.github.com/users/smarter/events{/privacy}",
428-
"received_events_url": "https://api.github.com/users/smarter/received_events",
423+
"url": "https://api.github.com/users/felixmulder",
424+
"html_url": "https://github.com/felixmulder",
425+
"followers_url": "https://api.github.com/users/felixmulder/followers",
426+
"following_url": "https://api.github.com/users/felixmulder/following{/other_user}",
427+
"gists_url": "https://api.github.com/users/felixmulder/gists{/gist_id}",
428+
"starred_url": "https://api.github.com/users/felixmulder/starred{/owner}{/repo}",
429+
"subscriptions_url": "https://api.github.com/users/felixmulder/subscriptions",
430+
"organizations_url": "https://api.github.com/users/felixmulder/orgs",
431+
"repos_url": "https://api.github.com/users/felixmulder/repos",
432+
"events_url": "https://api.github.com/users/felixmulder/events{/privacy}",
433+
"received_events_url": "https://api.github.com/users/felixmulder/received_events",
429434
"type": "User",
430435
"site_admin": false
431436
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package dotty.tools.bot
2+
package model
3+
4+
object Github {
5+
case class PullRequest(
6+
url: String,
7+
id: Long,
8+
commits_url: String
9+
)
10+
11+
case class Issue(
12+
number: Int,
13+
pull_request: Option[PullRequest]
14+
)
15+
}

bot/test/PRServiceTests.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dotty.tools.bot
2+
3+
import org.junit.Assert._
4+
import org.junit.Test
5+
6+
import io.circe._
7+
import io.circe.generic.auto._
8+
import io.circe.syntax._
9+
import io.circe.parser.decode
10+
11+
import model.Github._
12+
import org.http4s.client.blaze._
13+
import scalaz.concurrent.Task
14+
15+
class PRServiceTests extends PullRequestService {
16+
val user = sys.env("USER")
17+
val token = sys.env("TOKEN")
18+
19+
def getResource(r: String): String =
20+
Option(getClass.getResourceAsStream(r)).map(scala.io.Source.fromInputStream)
21+
.map(_.mkString)
22+
.getOrElse(throw new Exception(s"resource not found: $r"))
23+
24+
25+
@Test def canUnmarshalIssueJson = {
26+
val json = getResource("/test-pr.json")
27+
val issue: Issue = decode[Issue](json) match {
28+
case Right(is: Issue) => is
29+
case Left(ex) => throw ex
30+
}
31+
32+
assert(issue.pull_request.isDefined, "missing pull request")
33+
}
34+
}

project/Build.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,13 @@ object DottyBuild extends Build {
172172
settings(sourceStructure).
173173
settings(
174174
libraryDependencies ++= {
175-
val github4sVersion = "0.9.0"
175+
val circeVersion = "0.7.0"
176176
val http4sVersion = "0.15.3"
177177
Seq(
178-
"io.circe" %% "circe-generic" % "0.6.1",
178+
"com.novocode" % "junit-interface" % "0.11" % "test",
179+
"io.circe" %% "circe-generic" % circeVersion,
180+
"io.circe" %% "circe-parser" % circeVersion,
179181
"ch.qos.logback" % "logback-classic" % "1.1.7",
180-
"com.fortysevendeg" %% "github4s" % "0.10.0",
181182
"org.http4s" %% "http4s-dsl" % http4sVersion,
182183
"org.http4s" %% "http4s-blaze-server" % http4sVersion,
183184
"org.http4s" %% "http4s-blaze-client" % http4sVersion,

0 commit comments

Comments
 (0)