Skip to content

Commit

Permalink
Comments API: Render markdown on explicit request only
Browse files Browse the repository at this point in the history
  • Loading branch information
asdil12 committed Nov 16, 2023
1 parent c0373be commit 5d9c85b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/OpenQA/Schema/Result/Comments.pm
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ sub event_data ($self) {
return $data;
}

sub extended_hash ($self) {
sub extended_hash ($self, $render_markdown = 1) {
return {
id => $self->id,
text => $self->text,
renderedMarkdown => $self->rendered_markdown->to_string,
renderedMarkdown => ($render_markdown) ? $self->rendered_markdown->to_string : undef,
bugrefs => $self->bugrefs,
created => $self->t_created->strftime("%Y-%m-%d %H:%M:%S %z"),
updated => $self->t_updated->strftime("%Y-%m-%d %H:%M:%S %z"),
Expand Down
3 changes: 2 additions & 1 deletion lib/OpenQA/WebAPI/Controller/API/V1/Comment.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ text, date of update and the user name that created the comment.
sub list ($self) {
my $comments = $self->_comments();
return unless $comments;
$self->render(json => [map { $_->extended_hash } $comments->all]);
my $render_markdown = $self->param('render_markdown') // 0;
$self->render(json => [map { $_->extended_hash($render_markdown) } $comments->all]);
}


Expand Down
3 changes: 2 additions & 1 deletion t/16-markdown.t
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ subtest 'bugrefs to markdown' => sub {
'<a href="https://bugs.freedesktop.org/show_bug.cgi?id=9876" title="Bug referenced: fdo#9876">fdo#9876</a>',
'right markdown for fdo';
is bugref_to_html('jsc#9876'),
'<a href="https://jira.suse.de/browse/9876" title="Bug referenced: jsc#9876">jsc#9876</a>', 'right markdown for jsc';
'<a href="https://jira.suse.de/browse/9876" title="Bug referenced: jsc#9876">jsc#9876</a>',
'right markdown for jsc';
is bugref_to_html('pio#foo#1234'),
'<a href="https://pagure.io/foo/issue/1234" title="Bug referenced: pio#foo#1234">pio#foo#1234</a>',
'right markdown for pio';
Expand Down
2 changes: 1 addition & 1 deletion t/api/09-comments.t
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ sub test_comments ($in, $id) {
};

subtest 'list multiple comments' => sub {
$t->get_ok("/api/v1/$in/$id/comments")->status_is(200)
$t->get_ok("/api/v1/$in/$id/comments?render_markdown=1")->status_is(200)
->json_is('/0/text' => $edited_test_message, 'text correct')->json_is(
'/0/renderedMarkdown' =>
"<p>This is a cool test \x{2620} - <a href=\"http://open.qa\">http://open.qa</a> - this message will be\\nappended if editing works \x{2620}</p>\n",
Expand Down

0 comments on commit 5d9c85b

Please sign in to comment.