-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MM-405]: Fixed the pull review request events not working #768
Conversation
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.
Glad to see this bug getting fixed 🚀
server/plugin/webhook.go
Outdated
@@ -937,7 +937,7 @@ func (p *Plugin) postPullRequestReviewCommentEvent(event *github.PullRequestRevi | |||
|
|||
post := &model.Post{ | |||
UserId: p.BotUserID, | |||
Type: "custom_git_pull_review_comment", | |||
Type: "custom_git_pr_comment", |
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.
While we are not using the custom type currently, I think there is value in keeping the type the same for each post.
What is the reason behind changing it?
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 kept getting the error that the length of the type should be less than 2, that's why I have reduced it.
@hanzei
{{- if eq .GetReview.GetState "APPROVED"}} approved | ||
{{- else if eq .GetReview.GetState "COMMENTED"}} commented on | ||
{{- else if eq .GetReview.GetState "CHANGES_REQUESTED"}} requested changes on |
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.
Did GitHub document the changes anywhere?
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.
@hanzei I was getting the state in small case and in the code as well they have been changed to lower case in the using toLower. Let me try to find the GitHub documentation for this.
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.
@hanzei Can't find a documentation but here is a screenshot of the webhook payload
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.
@Kshitij-Katiyar There's a PR that was submitted that solves this same issue #778. Can you please take a look there and compare any changes that may need to be added here?
@@ -314,7 +314,6 @@ Assignees: {{range $i, $el := .Assignees -}} {{- if $i}}, {{end}}{{template "use | |||
template.Must(masterTemplate.New("newReviewComment").Funcs(funcMap).Parse(` | |||
{{template "repo" .GetRepo}} New review comment by {{template "user" .GetSender}} on {{template "pullRequest" .GetPullRequest}}: | |||
|
|||
{{.GetComment.GetDiffHunk}} |
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.
Can you provide a screenshot for what this looks like?
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.
Thanks for the PR, added some useful changes from the PR |
@@ -58,7 +58,7 @@ | |||
"sass": "1.60.0", | |||
"sass-loader": "10.4.1", | |||
"style-loader": "1.2.1", | |||
"typescript": "4.0.3", | |||
"typescript": "4.2.3", |
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 is adding a lot to the diff of the PR
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.
@mickmister Without these changes the ci-lint
will fail. Let me know if you want us to find any other way around to fix the failing lint test other than this.
server/plugin/webhook.go
Outdated
post.AddProp(postPropGithubRepo, repoName) | ||
post.AddProp(postPropGithubObjectID, commentID) | ||
post.AddProp(postPropGithubObjectType, githubObjectTypePRReviewComment) | ||
|
||
post.ChannelId = sub.ChannelID | ||
if err = p.client.Post.CreatePost(post); err != nil { |
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.
Referencing https://github.com/mattermost/mattermost-plugin-github/pull/768/files#r1649049447 the p.client.Post.CreatePost(post)
here mutates the post instead of returning the created post, which has had side effects in this plugin. I think we should instead use p.API.CreatePost(post)
to avoid the risk of introducing the issue on unrelated code changes cc @hanzei
@mickmister Fixed the comments, please look into it. |
server/plugin/webhook.go
Outdated
if err = p.client.Post.CreatePost(post); err != nil { | ||
p.client.Log.Warn("Error webhook post", "post", post, "error", err.Error()) | ||
if _, appErr := p.API.CreatePost(post); appErr != nil { | ||
p.client.Log.Warn("Error webhook post", "post", post, "error", appErr.Error()) |
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.
p.API
should not be used. The returned model.AppError
makes things way too hard. p.client
is they way to go.
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.
@hanzei Please refer to this comment: #768 (comment)
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.
In this case, the p.client.Post
method has essentially a bug in it, that has caused issues in this plugin because it mutates the post that is passed in. Is it really a "bug"? Maybe not, but I think we should avoid using it since it has caused issues in production that we then need to fix
2/5 The benefits of using error
over AppError
in this case are not worth it imo. I think keeping it as p.client.Post
will make potential issues come back, just as they did in this PR. This can be changed in a different PR though
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.
@Kshitij-Katiyar I'm thinking we should keep the changes in this PR to a minimum so let's keep this as-is
server/plugin/webhook.go
Outdated
if err = p.client.Post.CreatePost(post); err != nil { | ||
p.client.Log.Warn("Error webhook post", "post", post, "error", err.Error()) | ||
if _, appErr := p.API.CreatePost(post); appErr != nil { | ||
p.client.Log.Warn("Error webhook post", "post", post, "error", appErr.Error()) |
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.
@Kshitij-Katiyar I'm thinking we should keep the changes in this PR to a minimum so let's keep this as-is
@mickmister Fixed the comments, please have a look |
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.
The above PR has been tested for the following scenarios:
- Checked the pull review request events
- Tested the notification for pull review request events
The PR was working fine for all the conditions, LGTM. Approved
Summary
Fixed the issue that the pull request review event not working. Removed the GetComment.GetDiffHunk from the template as it can be very long and not that very useful. Also changed the name for the type of the post.
Ticket Link
Fixes #405