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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions server/plugin/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -908,19 +908,6 @@ func (p *Plugin) postPullRequestReviewCommentEvent(event *github.PullRequestRevi
return
}

post := &model.Post{
UserId: p.BotUserID,
Type: "custom_git_pr_comment",
Message: newReviewMessage,
}

repoName := strings.ToLower(repo.GetFullName())
commentID := event.GetComment().GetID()

post.AddProp(postPropGithubRepo, repoName)
post.AddProp(postPropGithubObjectID, commentID)
post.AddProp(postPropGithubObjectType, githubObjectTypePRReviewComment)

labels := make([]string, len(event.GetPullRequest().Labels))
for i, v := range event.GetPullRequest().Labels {
labels[i] = v.GetName()
Expand Down Expand Up @@ -948,9 +935,18 @@ func (p *Plugin) postPullRequestReviewCommentEvent(event *github.PullRequestRevi
continue
}

post := p.makeBotPost(newReviewMessage, "custom_git_pr_comment")

repoName := strings.ToLower(repo.GetFullName())
commentID := event.GetComment().GetID()

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 {
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

}
}
}
Expand Down
27 changes: 15 additions & 12 deletions webapp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions webapp/src/components/sidebar_right/github_items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import TickIcon from '../../images/icons/tick';
import SignIcon from '../../images/icons/sign';
import ChangesRequestedIcon from '../../images/icons/changes_requested';
import {getLabelFontColor} from '../../utils/styles';
import {ReviewState} from '../../constants/index';
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved

const notificationReasons = {
assign: 'You were assigned to the issue',
Expand Down Expand Up @@ -350,7 +351,7 @@ function getReviewText(item: GithubItem, style: any, secondLine: boolean) {
return false;
}

if (v.state === 'commented' || v.state === 'dismissed') {
if (v.state === ReviewState.Commented || v.state === ReviewState.Dismissed) {
return false;
}

Expand All @@ -363,14 +364,14 @@ function getReviewText(item: GithubItem, style: any, secondLine: boolean) {
});

const approved = lastReviews.reduce((accum: number, cur: Review) => {
if (cur.state === 'approved') {
if (cur.state === ReviewState.Approved) {
return accum + 1;
}
return accum;
}, 0);

const changesRequested = lastReviews.reduce((accum: number, cur: Review) => {
if (cur.state === 'changes_requested') {
if (cur.state === ReviewState.ChangesRequested) {
return accum + 1;
}
return accum;
Expand Down
7 changes: 7 additions & 0 deletions webapp/src/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@ export const RHSStates = {
UNREADS: 'unreads',
ASSIGNMENTS: 'assignments',
};

export const ReviewState = {
Commented: 'commented',
Dismissed: 'dismissed',
Approved: 'approved',
ChangesRequested: 'changes_requested',
};
Loading