Skip to content

Conversation

@HirotoShioi
Copy link
Contributor

Description

This PR will introduce responses to tickets with no logs attached.

Related issue

https://iohk.myjetbrains.com/youtrack/issue/TSD-40

@HirotoShioi
Copy link
Contributor Author

Currently, I don't have a template response for "No log files". Asking carl to provide them!

@HirotoShioi HirotoShioi changed the title [TSD 40] Send the message in to all requesters with no log in the ticket [TSD-40] Send the message in to all requesters with no log in the ticket Jun 13, 2018
Copy link
Contributor

@ksaric ksaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally very good, nice tests, a couple of minor changes and I'm not sure if we should run this before fixing that processTicket returns a single ZendeskResponse, otherwise we might send a couple of responses back to the user which will confuse him.

src/Lib.hs Outdated

processTicket :: TicketId -> App [ZendeskResponse]
processTicket ticketId = do
processTicket tid = do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tid = tId

src/Lib.hs Outdated
isAttachmentZip attachment = "application/zip" == aContentType attachment

-- | Get zendesk responses
getZendeskResponses :: [Comment] -> [Attachment] -> TicketInfo -> App [ZendeskResponse]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the mapping one TicketInfo - one ZendeskResponse? We should fix this, as noted above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first impression is that fixing this could be a little tricky. I'll try to fix it today and if I couldn't get it done by today, then I'll have to ask for your help

src/Lib.hs Outdated
isTicketBlacklisted :: TicketInfo -> Bool
isTicketBlacklisted TicketInfo{..} = ticketId `notElem` [9377,10815]

isGoguenTestnetTicket :: TicketInfo -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isTicketInGoguenTestnet

src/Lib.hs Outdated
ticketsFilter ticketInfo =
isTicketAnalyzed ticketInfo && isTicketOpen ticketInfo && isTicketBlacklisted ticketInfo
ticketsFilter ticketInfo =
all (\predicate -> predicate ticketInfo) [ isTicketAnalyzed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A complicated way to say a simple thing. Remember that you will have to maintain this code and that doing something smart may not be the best things to do - do something simple instead.
I know it seems kind of harsh to say that, but it's important that you understand how little changes like these make the code more complex. I actually have to think about this, which is something I like to avoid as much as possible.
And if this builds, isn't all ticketInfo [ ... ] an option?

test/Spec.hs Outdated
zendeskResponses <- run appExecution
assert $ not (null zendeskResponses) && not (isTaggedWithNoLogs zendeskResponses)

isTaggedWithNoLogs :: [ZendeskResponse] -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you insert the param name? I know this is also a convention, but I have to look at the type to know what this is doing, which is not helping readability.
Try to be as explicit as possible, it helps readability and maintainability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not sure what this means. Do you want me to fix the name of the function?

src/Lib.hs Outdated
getZendeskResponses :: [Comment] -> [Attachment] -> TicketInfo -> App [ZendeskResponse]
getZendeskResponses comments attachments ticketInfo
| not (null attachments) = mapM (inspectAttachment ticketInfo) attachments
| not (null comments) = pure <$> responseNoLogs ticketInfo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pure <$> responseNoLogs ticketInfo == responseNoLogs ticketInfo

src/Lib.hs Outdated
mapM_ extractEmailAddress ticketIds


processTicket :: TicketId -> App [ZendeskResponse]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to fix this. We should take the last comment attachments and process the last attachment.

test/Spec.hs Outdated

zendeskResponses <- run appExecution

assert $ not (null zendeskResponses) && isTaggedWithNoLogs zendeskResponses
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice 👍

forAll arbitrary $ \ticketInfo ->
monadicIO $ do

pre $ any (not . null . cAttachments) comments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all (not . null . cAttachments) comments - we require that all the comments have attachments, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I thought the intended behavior was that if user had submitted multiple comments and at least one of them has log file attached(so not all comments needs log file), then processTicket should return ZendeskResponses

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good thinking but I didn't even notice we were returning multiple ZendeskResponse, my bad.

Copy link
Contributor Author

@HirotoShioi HirotoShioi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed most of the things, I'll try to apply the fix but it might be little tricky.

forAll arbitrary $ \ticketInfo ->
monadicIO $ do

pre $ any (not . null . cAttachments) comments
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I thought the intended behavior was that if user had submitted multiple comments and at least one of them has log file attached(so not all comments needs log file), then processTicket should return ZendeskResponses

test/Spec.hs Outdated
zendeskResponses <- run appExecution
assert $ not (null zendeskResponses) && not (isTaggedWithNoLogs zendeskResponses)

isTaggedWithNoLogs :: [ZendeskResponse] -> Bool
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not sure what this means. Do you want me to fix the name of the function?

src/Lib.hs Outdated
isAttachmentZip attachment = "application/zip" == aContentType attachment

-- | Get zendesk responses
getZendeskResponses :: [Comment] -> [Attachment] -> TicketInfo -> App [ZendeskResponse]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My first impression is that fixing this could be a little tricky. I'll try to fix it today and if I couldn't get it done by today, then I'll have to ask for your help

Copy link
Contributor

@ksaric ksaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, just a few more little details.

src/Lib.hs Outdated
inspectAttachments :: TicketInfo -> [Attachment] -> App (Maybe ZendeskResponse)
inspectAttachments ticketInfo attachments = do
-- Inspecting the last element since it'll be the latest attachment
let latestAttachment = last <$> nonEmpty attachments
Copy link
Contributor

@ksaric ksaric Jun 14, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about inspectAttachment ticketInfo =<< safeHead . sort $ attachments where the Ord instance should be AttachmentId? Or the expanded form of the same which is even better.

src/Lib.hs Outdated
inspectAttachments ticketInfo attachments = do
-- Inspecting the last element since it'll be the latest attachment
let latestAttachment = last <$> nonEmpty attachments
case latestAttachment of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a bind - latestAttachment >>= \att -> inspectAttachment ticketInfo att or similar.
See how they align? Nothing goes to Nothing while Just goes to Just.
You do work when it's Just otherwise return nothing.

forAll arbitrary $ \ticketInfo ->
monadicIO $ do

pre $ any (not . null . cAttachments) comments
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good thinking but I didn't even notice we were returning multiple ZendeskResponse, my bad.

HirotoShioi and others added 6 commits June 14, 2018 16:53
- Unwrap newtype so the request api will be valid
- Make assignee_id field to be maybe since ticket could be unassigned in that case classifier will not be able to parse the json
@HirotoShioi HirotoShioi merged commit 0d57a90 into develop Jun 15, 2018
@HirotoShioi HirotoShioi deleted the hiroto/tsd-40 branch June 15, 2018 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants