Skip to content
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

Merged
merged 6 commits into from
Jul 4, 2024

Conversation

Kshitij-Katiyar
Copy link
Contributor

@Kshitij-Katiyar Kshitij-Katiyar commented Apr 15, 2024

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

@hanzei hanzei added 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Apr 18, 2024
Copy link
Contributor

@hanzei hanzei left a 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 🚀

@@ -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",
Copy link
Contributor

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?

Copy link
Contributor Author

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

Comment on lines -306 to -313
{{- if eq .GetReview.GetState "APPROVED"}} approved
{{- else if eq .GetReview.GetState "COMMENTED"}} commented on
{{- else if eq .GetReview.GetState "CHANGES_REQUESTED"}} requested changes on
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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
Screenshot from 2024-06-21 12-33-38

Copy link
Contributor

@mickmister mickmister left a 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}}
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 provide a screenshot for what this looks like?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Old UI
Screenshot from 2024-06-21 12-46-20

New UI
new

@Kshitij-Katiyar
Copy link
Contributor Author

@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?

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",
Copy link
Contributor

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

Copy link
Contributor Author

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.

webapp/src/components/sidebar_right/github_items.tsx Outdated Show resolved Hide resolved
server/plugin/webhook.go Outdated Show resolved Hide resolved
server/plugin/webhook.go Outdated Show resolved Hide resolved
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 {
Copy link
Contributor

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

@Kshitij-Katiyar
Copy link
Contributor Author

@mickmister Fixed the comments, please look into it.

Comment on lines 948 to 949
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())
Copy link
Contributor

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.

Copy link
Contributor

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)

Copy link
Contributor

@mickmister mickmister Jun 27, 2024

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

Copy link
Contributor

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

webapp/src/components/sidebar_right/github_items.tsx Outdated Show resolved Hide resolved
Comment on lines 948 to 949
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())
Copy link
Contributor

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

@Kshitij-Katiyar
Copy link
Contributor Author

@mickmister Fixed the comments, please have a look

Copy link

@AayushChaudhary0001 AayushChaudhary0001 left a 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

@raghavaggarwal2308 raghavaggarwal2308 merged commit 2402ae6 into master Jul 4, 2024
9 checks passed
@raghavaggarwal2308 raghavaggarwal2308 deleted the MM-405 branch July 4, 2024 12:28
@hanzei hanzei added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pull request review and Pull request review comments not working
5 participants