-
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
Changes from 4 commits
2ac75ae
81c88e3
f0dd395
5fae2f3
e01f4e1
f086e6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -308,9 +308,9 @@ Assignees: {{range $i, $el := .Assignees -}} {{- if $i}}, {{end}}{{template "use | |
|
||
template.Must(masterTemplate.New("pullRequestReviewEvent").Funcs(funcMap).Parse(` | ||
{{template "repo" .GetRepo}} {{template "user" .GetSender}} | ||
{{- if eq .GetReview.GetState "APPROVED"}} approved | ||
{{- else if eq .GetReview.GetState "COMMENTED"}} commented on | ||
{{- else if eq .GetReview.GetState "CHANGES_REQUESTED"}} requested changes on | ||
{{- if eq .GetReview.GetState "approved"}} approved | ||
{{- else if eq .GetReview.GetState "commented"}} commented on | ||
{{- else if eq .GetReview.GetState "changes_requested"}} requested changes on | ||
{{- end }} {{template "pullRequest" .GetPullRequest}}: | ||
|
||
{{.Review.GetBody | replaceAllGitHubUsernames}} | ||
|
@@ -319,7 +319,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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{{.GetComment.GetBody | trimBody | replaceAllGitHubUsernames}} | ||
`)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -843,10 +843,10 @@ func (p *Plugin) postPullRequestReviewEvent(event *github.PullRequestReviewEvent | |
return | ||
} | ||
|
||
switch strings.ToUpper(event.GetReview().GetState()) { | ||
case "APPROVED": | ||
case "COMMENTED": | ||
case "CHANGES_REQUESTED": | ||
switch event.GetReview().GetState() { | ||
case "approved": | ||
case "commented": | ||
case "changes_requested": | ||
default: | ||
p.client.Log.Debug("Unhandled review state", "state", event.GetReview().GetState()) | ||
return | ||
|
@@ -908,6 +908,19 @@ func (p *Plugin) postPullRequestReviewCommentEvent(event *github.PullRequestRevi | |
return | ||
} | ||
|
||
post := &model.Post{ | ||
Kshitij-Katiyar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
UserId: p.BotUserID, | ||
Type: "custom_git_pr_comment", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
Message: newReviewMessage, | ||
} | ||
|
||
repoName := strings.ToLower(repo.GetFullName()) | ||
commentID := event.GetComment().GetID() | ||
Kshitij-Katiyar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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() | ||
|
@@ -935,15 +948,6 @@ func (p *Plugin) postPullRequestReviewCommentEvent(event *github.PullRequestRevi | |
continue | ||
} | ||
|
||
post := p.makeBotPost(newReviewMessage, "custom_git_pull_review_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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.Log.Warn("Error webhook post", "post", post, "error", err.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.
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