github: Introduce `get_pull_comments`
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 11 Jul 2019 01:05:13 +0000 (21:05 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Thu, 11 Jul 2019 02:07:02 +0000 (22:07 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/github/api.nit
lib/github/tests/mock/repo_pulls_945_comments.res [new file with mode: 0644]
lib/github/tests/test_api.nit

index 597c05f..cc0bf6b 100644 (file)
@@ -369,6 +369,12 @@ class GithubAPI
                return get("/repos/{repo_slug}/pulls/{number}").as(nullable PullRequest)
        end
 
+       # List of comments on a pull request
+       fun get_pull_comments(repo_slug: String, pull_number: Int, page, per_page: nullable Int): Array[PullComment] do
+               return new GithubArray[PullComment].from(get(
+                       "/repos/{repo_slug}/pulls/{pull_number}/comments?{pagination(page, per_page)}"))
+       end
+
        # Get a specific pull request comment
        fun get_pull_comment(repo_slug: String, id: Int): nullable PullComment do
                return get("/repos/{repo_slug}/pulls/comments/{id}").as(nullable PullComment)
diff --git a/lib/github/tests/mock/repo_pulls_945_comments.res b/lib/github/tests/mock/repo_pulls_945_comments.res
new file mode 100644 (file)
index 0000000..8f8161f
--- /dev/null
@@ -0,0 +1 @@
+[{"url":"https://api.github.com/repos/nitlang/nit/pulls/comments/21010363","pull_request_review_id":null,"id":21010363,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMDEwMzYz","diff_hunk":"@@ -981,11 +983,11 @@ redef class AAttrPropdef\n \n \t\t\t\tif mtype == null then return\n \t\t\tend\n-\t\telse if ntype != null then\n+\t\telse if ntype != null and inherited_type == mtype then\n \t\t\tif nexpr isa ANewExpr then\n \t\t\t\tvar xmtype = modelbuilder.resolve_mtype(mmodule, mclassdef, nexpr.n_type)\n \t\t\t\tif xmtype == mtype then\n-\t\t\t\t\tmodelbuilder.advice(ntype, \"useless-type\", \"Warning: useless type definition\")\n+\t\t\t\t\tmodelbuilder.advice(ntype, \"useless-type\", \"Warning: useless type definition {inherited_type or else \"?\"}\")","path":"src/modelize/modelize_property.nit","position":null,"original_position":26,"commit_id":"ce5e187a87ed5c41144ea5637188a0677d840fdc","original_commit_id":"5f0ab1c7f3c560a67867d5eb08f5c3082f251c20","user":{"login":"jcbrinfo","id":6044484,"node_id":"MDQ6VXNlcjYwNDQ0ODQ=","avatar_url":"https://avatars0.githubusercontent.com/u/6044484?v=4","gravatar_id":"","url":"https://api.github.com/users/jcbrinfo","html_url":"https://github.com/jcbrinfo","followers_url":"https://api.github.com/users/jcbrinfo/followers","following_url":"https://api.github.com/users/jcbrinfo/following{/other_user}","gists_url":"https://api.github.com/users/jcbrinfo/gists{/gist_id}","starred_url":"https://api.github.com/users/jcbrinfo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcbrinfo/subscriptions","organizations_url":"https://api.github.com/users/jcbrinfo/orgs","repos_url":"https://api.github.com/users/jcbrinfo/repos","events_url":"https://api.github.com/users/jcbrinfo/events{/privacy}","received_events_url":"https://api.github.com/users/jcbrinfo/received_events","type":"User","site_admin":false},"body":"Warning: `inherited_type` is always non null here.\n","created_at":"2014-11-27T20:39:29Z","updated_at":"2014-11-28T01:05:12Z","html_url":"https://github.com/nitlang/nit/pull/945#discussion_r21010363","pull_request_url":"https://api.github.com/repos/nitlang/nit/pulls/945","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/nitlang/nit/pulls/comments/21010363"},"html":{"href":"https://github.com/nitlang/nit/pull/945#discussion_r21010363"},"pull_request":{"href":"https://api.github.com/repos/nitlang/nit/pulls/945"}}},{"url":"https://api.github.com/repos/nitlang/nit/pulls/comments/21010554","pull_request_review_id":null,"id":21010554,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxMDEwNTU0","diff_hunk":"@@ -981,11 +983,11 @@ redef class AAttrPropdef\n \n \t\t\t\tif mtype == null then return\n \t\t\tend\n-\t\telse if ntype != null then\n+\t\telse if ntype != null and inherited_type == mtype then\n \t\t\tif nexpr isa ANewExpr then\n \t\t\t\tvar xmtype = modelbuilder.resolve_mtype(mmodule, mclassdef, nexpr.n_type)\n \t\t\t\tif xmtype == mtype then\n-\t\t\t\t\tmodelbuilder.advice(ntype, \"useless-type\", \"Warning: useless type definition\")\n+\t\t\t\t\tmodelbuilder.advice(ntype, \"useless-type\", \"Warning: useless type definition {inherited_type or else \"?\"}\")","path":"src/modelize/modelize_property.nit","position":null,"original_position":26,"commit_id":"ce5e187a87ed5c41144ea5637188a0677d840fdc","original_commit_id":"5f0ab1c7f3c560a67867d5eb08f5c3082f251c20","user":{"login":"privat","id":135828,"node_id":"MDQ6VXNlcjEzNTgyOA==","avatar_url":"https://avatars1.githubusercontent.com/u/135828?v=4","gravatar_id":"","url":"https://api.github.com/users/privat","html_url":"https://github.com/privat","followers_url":"https://api.github.com/users/privat/followers","following_url":"https://api.github.com/users/privat/following{/other_user}","gists_url":"https://api.github.com/users/privat/gists{/gist_id}","starred_url":"https://api.github.com/users/privat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/privat/subscriptions","organizations_url":"https://api.github.com/users/privat/orgs","repos_url":"https://api.github.com/users/privat/repos","events_url":"https://api.github.com/users/privat/events{/privacy}","received_events_url":"https://api.github.com/users/privat/received_events","type":"User","site_admin":false},"body":"Oups. C'est du debug qui traine :/\n","created_at":"2014-11-27T20:50:42Z","updated_at":"2014-11-28T01:05:12Z","html_url":"https://github.com/nitlang/nit/pull/945#discussion_r21010554","pull_request_url":"https://api.github.com/repos/nitlang/nit/pulls/945","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/nitlang/nit/pulls/comments/21010554"},"html":{"href":"https://github.com/nitlang/nit/pull/945#discussion_r21010554"},"pull_request":{"href":"https://api.github.com/repos/nitlang/nit/pulls/945"}}}]
\ No newline at end of file
index 1976877..967b631 100644 (file)
@@ -71,10 +71,11 @@ class MockGithubAPI
                map["/repos/nitlang/nit/issues/events/199674194"] = "repo_issues_events_199674194"
                map["/repos/nitlang/nit/pulls?page=1&per_page=3"] = "repo_pulls_nit"
                map["/repos/nitlang/nit/pulls/1000"] = "repo_pulls_1000"
+               map["/repos/nitlang/nit/pulls/945/comments?page=1&per_page=3"] = "repo_pulls_945_comments"
+               map["/repos/nitlang/nit/pulls/comments/21010363"] = "repo_pulls_comment_21010363"
                map["/repos/nitlang/nit/commits/64ce1f"] = "repo_commits_64ce1f"
                map["/repos/nitlang/nit/commits/4e3c688d/status"] = "repo_commits_4e3c68_status"
                map["/repos/nitlang/nit/comments/8982707"] = "repo_comments_8982707"
-               map["/repos/nitlang/nit/pulls/comments/21010363"] = "repo_pulls_comment_21010363"
                map["/search/issues?q=foo repo:nitlang/nit&page=1&per_page=3"] = "repo_search_issues_nit"
                # errors
                map["/users/not_found/not_found"] = "errors_404"
@@ -336,6 +337,12 @@ class TestGithubAPI
                assert pull.body == "Raise dead on `nitc`.\nIt's super effective...\n"
        end
 
+       fun test_get_pull_comments is test do
+               var comments = api.get_pull_comments("nitlang/nit", 945, 1, 3)
+               assert comments.length == 2
+               assert comments.first.path == "src/modelize/modelize_property.nit"
+       end
+
        fun test_get_pull_comment is test do
                var comment = api.get_pull_comment("nitlang/nit", 21010363)
                assert comment isa PullComment