Closed Cleop closed 6 years ago
@Cleop we can split out the cases into their own handler functions which accept the payload
...
My proposed solution: In event_type.ex change the atoms to functions
defp type("issue_comment", action) do
case action do
"created" -> :comment_created
"edited" -> :comment_edited
"deleted" -> comment_deleted(payload, conn)
end
end
E.g. function:
defp comment_deleted(conn, payload) do
comment_id = payload["comment"]["id"]
author = payload["sender"]["login"]
comment = Repo.get_by!(Comment, comment_id: "#{comment_id}")
changeset = Comment.changeset(comment)
changeset = changeset
|> Changeset.put_change(:deleted, true)
|> Changeset.put_change(:deleted_by, author)
Repo.update!(changeset)
conn
|> put_status(200)
|> json(%{ok: "comment deleted"})
end
And simply call the get_event_type function which will funnel down into the individual functions in the event_controller.
EventType.get_event_type(x_github_event, github_webhook_action, conn, payload)
I've implemented this and put the handlers in their own file for neatness.
There is this warning though when you run the server:
which I can lose by doing this:
However, @SimonLab these lines were in place before I refactored, should they be kept? I'm not sure why they're there given that they're not being used but I don't want to take them out and break something!
The atoms remaining in event type lower the test coverage because we're not testing for them in the event_controller_test because they don't have a payload etc. yet because we haven't implemented the functionality for them.
Either I can remove them and the codecov will be as usual or I can leave them in but accept a lower code coverage until we implement the functionality for them and they are no longer atoms. The atoms are: installation_repositories, issues - closed/reopened.
@nelsonic, @SimonLab - what do you think?
@Cleop yeah, comment out the code and include a link to the issue where the feature is described in the "backlog" so that we can return to work on them later.
Closing as merged in and the issue is technical so can't be tested.
In our event controller we have the following error from credo:
For this function:
Admittedly it is a big function but this error message doesn't give us much insight into what about the function credo doesn't like. We need to determine if it's the number of cases or what's within them so that we can resolve this.
This is not the first time we've encountered this on this project when we've had to include the multiple actions in a case statement.