Refactor comments to support markup types (#707) #717
Conversation
27006f4
to
19d7370
Compare
Added a `markup` column in the `comments` table using a migration script. When creating or updating a comment, the default markup is used if none was provided. When showing comments, the default markup is also returned if none was found in the database (ie, for older comments). Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
19d7370
to
748a186
Compare
Codecov Report@@ Coverage Diff @@
## master #717 +/- ##
==========================================
+ Coverage 71.12% 71.16% +0.03%
==========================================
Files 80 80
Lines 4603 4616 +13
==========================================
+ Hits 3274 3285 +11
- Misses 1013 1016 +3
+ Partials 316 315 -1
Continue to review full report at Codecov.
|
@@ -44,6 +47,9 @@ var createCommentAttributes = a.Type("CreateCommentAttributes", func() { | |||
a.MinLength(1) // Empty comment not allowed | |||
a.Example("This is really interesting") | |||
}) | |||
a.Attribute("markup", d.String, "The comment markup associated with the body", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to have this attribute outsourced because you define it tiwce?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is outsourced twice just as body
is, because it is used in the types associated with the create and update operations
comments_blackbox_test.go
Outdated
@@ -45,6 +46,10 @@ func (s *CommentsSuite) TearDownTest() { | |||
s.clean() | |||
} | |||
|
|||
var markdownMarkup = rendering.SystemMarkupMarkdown |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it is a code convention but you could also define it like this:
var (
markdownMarkup = rendering.SystemMarkupMarkdown
plaintextMarkup = rendering.SystemMarkupPlainText
defaultMarkup = rendering.SystemMarkupDefault
)
You type less characters :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok ;-)
rendering/markup_content_test.go
Outdated
// when | ||
result := NilSafeGetMarkup(nil) | ||
// then | ||
require.NotNil(t, result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure you need this nil check because the assert.Equal
below just compares values and it is safe to compare nil values as long as you don't dereference a nil value. Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, correct, I can probably remove that
rendering/markup_content_test.go
Outdated
// when | ||
result := NilSafeGetMarkup(&markup) | ||
// then | ||
require.NotNil(t, result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure you need this nil check because the assert.Equal
below just compares values and it is safe to compare nil values as long as you don't dereference a nil value. Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
rendering/markup_content_test.go
Outdated
// when | ||
result := NilSafeGetMarkup(&markup) | ||
// then | ||
require.NotNil(t, result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure you need this nil check because the assert.Equal
below just compares values and it is safe to compare nil values as long as you don't dereference a nil value. Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
rendering/markup_content_test.go
Outdated
import "github.com/stretchr/testify/assert" | ||
import "github.com/stretchr/testify/require" | ||
|
||
func TestGetDefaultMarkupFromNil(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the functions TestGetDefaultMarkupFromNil
, TestGetMarkupFromValue
, and TestGetMarkupFromEmptyValue
can be merged into one test function, don't you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kwk why would I do that ? I want short unit tests that follow as much as possible the "given/when/then" pattern, which is why I have 3 tests here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, agreed. they just seemed so small, tiny, and cozy. Those poor little tests looked like they should be sleeping under a shared blanket. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kwk I've had enough of co-sleeping in the past ;-)
work-item-comments.go
Outdated
reqComment := ctx.Payload.Data | ||
|
||
fmt.Println(fmt.Sprintf("Processing markup value: '%v'", reqComment.Attributes.Markup)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, remove print.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
work-item-comments_test.go
Outdated
@@ -181,6 +193,7 @@ func assertComment(t *testing.T, c *app.Comment) { | |||
assert.Equal(t, "comments", c.Type) | |||
assert.NotNil(t, c.ID) | |||
assert.NotNil(t, c.Attributes.Body) | |||
assert.NotNil(t, c.Attributes.Markup) | |||
assert.NotNil(t, c.Attributes.CreatedAt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be require.NotNil
because you dereference the value one line below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
work-item-comments_test.go
Outdated
@@ -181,6 +193,7 @@ func assertComment(t *testing.T, c *app.Comment) { | |||
assert.Equal(t, "comments", c.Type) | |||
assert.NotNil(t, c.ID) | |||
assert.NotNil(t, c.Attributes.Body) | |||
assert.NotNil(t, c.Attributes.Markup) | |||
assert.NotNil(t, c.Attributes.CreatedAt) | |||
assert.WithinDuration(t, time.Now(), *c.Attributes.CreatedAt, 2*time.Second) | |||
assert.NotNil(t, c.Relationships) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be require.NotNil
because you dereference the value one line below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
Taking review comments into account Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
ebcf0e9
to
638b67e
Compare
@@ -0,0 +1,2 @@ | |||
-- add a 'markup' column in the 'comments' table | |||
alter table comments add column markup text; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add PlainText to the existing ones?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can provide an SQL script for that, indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, that I didn't notice that.
newComment := comment.Comment{ | ||
ParentID: ctx.ID, | ||
Body: reqComment.Attributes.Body, | ||
Markup: markup, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
htmlescape?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will be addressed in #724, actually
…ric8-services#717) * Refactor comments to support markup types (fabric8-services#707) Added a `markup` column in the `comments` table using a migration script. When creating or updating a comment, the default markup is used if none was provided. When showing comments, the default markup is also returned if none was found in the database (ie, for older comments). Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
Added a
markup
column in thecomments
table usinga migration script.
When creating or updating a comment, the default markup
is used if none was provided.
When showing comments, the default markup is also returned
if none was found in the database (ie, for older comments).
Fixes #707