##// END OF EJS Templates
api: add possibility to optionally return comments from get_changeset()
Manuel Jacob -
r8759:a1363834 stable
parent child Browse files
Show More
@@ -1847,7 +1847,7 b' class ApiController(JSONRPCController):'
1847 1847 raise JSONRPCError('Repository is empty')
1848 1848
1849 1849 # permission check inside
1850 def get_changeset(self, repoid, raw_id, with_reviews=False):
1850 def get_changeset(self, repoid, raw_id, with_reviews=False, with_comments=False, with_inline_comments=False):
1851 1851 """
1852 1852 TODO
1853 1853 """
@@ -1865,6 +1865,16 b' class ApiController(JSONRPCController):'
1865 1865 repo.repo_name, changeset.raw_id)
1866 1866 info["reviews"] = reviews
1867 1867
1868 if with_comments:
1869 comments = ChangesetCommentsModel().get_comments(
1870 repo.repo_id, changeset.raw_id)
1871 info["comments"] = comments
1872
1873 if with_inline_comments:
1874 inline_comments = ChangesetCommentsModel().get_inline_comments(
1875 repo.repo_id, changeset.raw_id)
1876 info["inline_comments"] = inline_comments
1877
1868 1878 return info
1869 1879
1870 1880 # permission check inside
@@ -2478,6 +2478,8 b' class _BaseTestApi(object):'
2478 2478 result = ext_json.loads(response.body)["result"]
2479 2479 assert result["raw_id"] == self.TEST_REVISION
2480 2480 assert "reviews" not in result
2481 assert "comments" not in result
2482 assert "inline_comments" not in result
2481 2483
2482 2484 def test_api_get_changeset_with_reviews(self):
2483 2485 reviewobjs = fixture.review_changeset(self.REPO, self.TEST_REVISION, "approved")
@@ -2488,6 +2490,8 b' class _BaseTestApi(object):'
2488 2490 result = ext_json.loads(response.body)["result"]
2489 2491 assert result["raw_id"] == self.TEST_REVISION
2490 2492 assert "reviews" in result
2493 assert "comments" not in result
2494 assert "inline_comments" not in result
2491 2495 assert len(result["reviews"]) == 1
2492 2496 review = result["reviews"][0]
2493 2497 expected = {
@@ -2497,6 +2501,47 b' class _BaseTestApi(object):'
2497 2501 }
2498 2502 assert review == expected
2499 2503
2504 def test_api_get_changeset_with_comments(self):
2505 commentobj = fixture.add_changeset_comment(self.REPO, self.TEST_REVISION, "example changeset comment")
2506 id_, params = _build_data(self.apikey, 'get_changeset',
2507 repoid=self.REPO, raw_id=self.TEST_REVISION,
2508 with_comments=True)
2509 response = api_call(self, params)
2510 result = ext_json.loads(response.body)["result"]
2511 assert result["raw_id"] == self.TEST_REVISION
2512 assert "reviews" not in result
2513 assert "comments" in result
2514 assert "inline_comments" not in result
2515 comment = result["comments"][-1]
2516 expected = {
2517 'comment_id': commentobj.comment_id,
2518 'text': 'example changeset comment',
2519 'username': 'test_admin',
2520 }
2521 assert comment == expected
2522
2523 def test_api_get_changeset_with_inline_comments(self):
2524 commentobj = fixture.add_changeset_comment(self.REPO, self.TEST_REVISION, "example inline comment", f_path='vcs/__init__.py', line_no="n3")
2525 id_, params = _build_data(self.apikey, 'get_changeset',
2526 repoid=self.REPO, raw_id=self.TEST_REVISION,
2527 with_inline_comments=True)
2528 response = api_call(self, params)
2529 result = ext_json.loads(response.body)["result"]
2530 assert result["raw_id"] == self.TEST_REVISION
2531 assert "reviews" not in result
2532 assert "comments" not in result
2533 assert "inline_comments" in result
2534 expected = [
2535 ['vcs/__init__.py', {
2536 'n3': [{
2537 'comment_id': commentobj.comment_id,
2538 'text': 'example inline comment',
2539 'username': 'test_admin',
2540 }]
2541 }]
2542 ]
2543 assert result["inline_comments"] == expected
2544
2500 2545 def test_api_get_changeset_that_does_not_exist(self):
2501 2546 """ Fetch changeset status for non-existant changeset.
2502 2547 revision id is the above git hash used in the test above with the
@@ -329,6 +329,11 b' class Fixture(object):'
329 329 meta.Session().commit()
330 330 return csm
331 331
332 def add_changeset_comment(self, repo, revision, text, author=TEST_USER_ADMIN_LOGIN, f_path=None, line_no=None):
333 comment = ChangesetCommentsModel().create(text, repo, author, revision=revision, f_path=f_path, line_no=line_no, send_email=False)
334 meta.Session().commit()
335 return comment
336
332 337 def create_pullrequest(self, testcontroller, repo_name, pr_src_rev, pr_dst_rev, title='title'):
333 338 org_ref = 'branch:stable:%s' % pr_src_rev
334 339 other_ref = 'branch:default:%s' % pr_dst_rev
General Comments 0
You need to be logged in to leave comments. Login now