Changeset - 6cb54b9ef4de
[Not reviewed]
stable
0 2 0
Manuel Jacob - 3 years ago 2023-03-29 13:01:32
me@manueljacob.de
api: include creation date in comments
2 files changed with 5 insertions and 1 deletions:
0 comments (0 inline, 0 general)
kallithea/model/db.py
Show inline comments
 
@@ -1905,24 +1905,25 @@ class ChangesetComment(meta.Base, BaseDb
 

	
 
    def url(self):
 
        anchor = "comment-%s" % self.comment_id
 
        if self.revision:
 
            return webutils.url('changeset_home', repo_name=self.repo.repo_name, revision=self.revision, anchor=anchor)
 
        elif self.pull_request_id is not None:
 
            return self.pull_request.url(anchor=anchor)
 

	
 
    def __json__(self):
 
        return dict(
 
            comment_id=self.comment_id,
 
            username=self.author.username,
 
            created_on=self.created_on.replace(microsecond=0),
 
            text=self.text,
 
        )
 

	
 
    def deletable(self):
 
        return self.created_on > datetime.datetime.now() - datetime.timedelta(minutes=5)
 

	
 

	
 
class ChangesetStatus(meta.Base, BaseDbModel):
 
    __tablename__ = 'changeset_statuses'
 
    __table_args__ = (
 
        Index('cs_revision_idx', 'revision'),
 
        Index('cs_version_idx', 'version'),
kallithea/tests/api/api_base.py
Show inline comments
 
@@ -2508,44 +2508,46 @@ class _BaseTestApi(object):
 
                                  with_comments=True)
 
        response = api_call(self, params)
 
        result = ext_json.loads(response.body)["result"]
 
        assert result["raw_id"] == self.TEST_REVISION
 
        assert "reviews" not in result
 
        assert "comments" in result
 
        assert "inline_comments" not in result
 
        comment = result["comments"][-1]
 
        expected = {
 
            'comment_id': commentobj.comment_id,
 
            'text': 'example changeset comment',
 
            'username': 'test_admin',
 
            'created_on': commentobj.created_on.replace(microsecond=0).isoformat(),
 
        }
 
        assert comment == expected
 

	
 
    def test_api_get_changeset_with_inline_comments(self):
 
        commentobj = fixture.add_changeset_comment(self.REPO, self.TEST_REVISION, "example inline comment", f_path='vcs/__init__.py', line_no="n3")
 
        id_, params = _build_data(self.apikey, 'get_changeset',
 
                                  repoid=self.REPO, raw_id=self.TEST_REVISION,
 
                                  with_inline_comments=True)
 
        response = api_call(self, params)
 
        result = ext_json.loads(response.body)["result"]
 
        assert result["raw_id"] == self.TEST_REVISION
 
        assert "reviews" not in result
 
        assert "comments" not in result
 
        assert "inline_comments" in result
 
        expected = [
 
            ['vcs/__init__.py', {
 
                'n3': [{
 
                    'comment_id': commentobj.comment_id,
 
                    'text': 'example inline comment',
 
                    'username': 'test_admin',
 
                    'created_on': commentobj.created_on.replace(microsecond=0).isoformat(),
 
                }]
 
            }]
 
        ]
 
        assert result["inline_comments"] == expected
 

	
 
    def test_api_get_changeset_that_does_not_exist(self):
 
        """ Fetch changeset status for non-existant changeset.
 
        revision id is the above git hash used in the test above with the
 
        last 3 nibbles replaced with 0xf.  Should not exist for git _or_ hg.
 
        """
 
        id_, params = _build_data(self.apikey, 'get_changeset',
 
                                  repoid=self.REPO, raw_id = '7ab37bc680b4aa72c34d07b230c866c28e9fcfff')
 
@@ -2575,25 +2577,26 @@ class _BaseTestApi(object):
 
        response = api_call(self, params)
 
        pullrequest = db.PullRequest().get(pull_request_id)
 
        expected = {
 
            "status": "new",
 
            "pull_request_id": pull_request_id,
 
            "description": "No description",
 
            "url": "/%s/pull-request/%s/_/%s" % (self.REPO, pull_request_id, "stable"),
 
            "reviewers": [{"username": "test_regular"}],
 
            "org_repo_url": "http://localhost:80/%s" % self.REPO,
 
            "org_ref_parts": ["branch", "stable", self.TEST_PR_SRC],
 
            "other_ref_parts": ["branch", "default", self.TEST_PR_DST],
 
            "comments": [{"username": base.TEST_USER_ADMIN_LOGIN, "text": "",
 
                         "comment_id": pullrequest.comments[0].comment_id}],
 
                          "comment_id": pullrequest.comments[0].comment_id,
 
                          "created_on": "2000-01-01T00:00:00"}],
 
            "owner": base.TEST_USER_ADMIN_LOGIN,
 
            "statuses": [{"status": "under_review", "reviewer": base.TEST_USER_ADMIN_LOGIN, "modified_at": "2000-01-01T00:00:00"} for i in range(0, len(self.TEST_PR_REVISIONS))],
 
            "title": "get test",
 
            "revisions": self.TEST_PR_REVISIONS,
 
            "created_on": "2000-01-01T00:00:00",
 
            "updated_on": "2000-01-01T00:00:00",
 
        }
 
        self._compare_ok(random_id, expected,
 
                         given=re.sub(br"\d\d\d\d\-\d\d\-\d\dT\d\d\:\d\d\:\d\d",
 
                                      b"2000-01-01T00:00:00", response.body))
 

	
 
    def test_api_close_pullrequest(self):
0 comments (0 inline, 0 general)