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

[GH-262] Merge request approval subscription #307

Merged

Conversation

MatthewDorner
Copy link
Contributor

Summary

Add DM and Channel notifications for Merge Request approved and unapproved webhook actions.

Ticket Link

Fixes #282

@mattermod
Copy link
Contributor

Hello @MatthewDorner,

Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here.

Removed incorrect commandHelp text.
Clean up comment formatting.
@mattermod
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

Copy link
Member

@spirosoik spirosoik left a comment

Choose a reason for hiding this comment

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

a few changes

case actionApproved:
message = fmt.Sprintf("[%s](%s) approved your merge request [%s!%v](%s)", senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), event.ObjectAttributes.Target.PathWithNamespace, event.ObjectAttributes.IID, event.ObjectAttributes.URL)
case actionUnapproved:
message = fmt.Sprintf("[%s](%s) unapproved your merge request [%s!%v](%s)", senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), event.ObjectAttributes.Target.PathWithNamespace, event.ObjectAttributes.IID, event.ObjectAttributes.URL)
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest a bit better wording like asked for changes. Something like that

case actionApproved:
message = fmt.Sprintf("[%s] Merge request [!%v %s](%s) was approved by [%s](%s)", repo.PathWithNamespace, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
case actionUnapproved:
message = fmt.Sprintf("[%s] Merge request [!%v %s](%s) was unapproved by [%s](%s)", repo.PathWithNamespace, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
Copy link
Member

Choose a reason for hiding this comment

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

ditto. something like needs changes

@spirosoik spirosoik added 2: Dev Review Requires review by a core committer and removed Lifecycle/1:stale labels Jul 6, 2022
@MatthewDorner
Copy link
Contributor Author

Not sure why the CircleCI checks are timing out.

@mattermod
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

@MatthewDorner
Copy link
Contributor Author

Changed the messages, anything else to do?

case actionApproved:
message = fmt.Sprintf("[%s](%s) approved your merge request [%s!%v](%s)", senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), event.ObjectAttributes.Target.PathWithNamespace, event.ObjectAttributes.IID, event.ObjectAttributes.URL)
case actionUnapproved:
message = fmt.Sprintf("[%s](%s) requested changes to your merge request [%s!%v](%s)", senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), event.ObjectAttributes.Target.PathWithNamespace, event.ObjectAttributes.IID, event.ObjectAttributes.URL)
Copy link
Member

Choose a reason for hiding this comment

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

GitHub's convention is to use # here, not sure about GitLab. I see other references to ! here though

Suggested change
message = fmt.Sprintf("[%s](%s) requested changes to your merge request [%s!%v](%s)", senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), event.ObjectAttributes.Target.PathWithNamespace, event.ObjectAttributes.IID, event.ObjectAttributes.URL)
message = fmt.Sprintf("[%s](%s) requested changes to your merge request [%s#%v](%s)", senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername), event.ObjectAttributes.Target.PathWithNamespace, event.ObjectAttributes.IID, event.ObjectAttributes.URL)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

GitLab does use ! (https://docs.gitlab.com/ee/user/markdown.html) but the MR references in the Channel messages are formatted differently from the DM ones. Looks like the DM ones are doing it the correct way.

I can quickly fix it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this screenshot, the second set of messages would be after my proposed changes where you can see the DM and Channel messages now format the MR reference in the same way. But I'd go even further and suggest that the sentence structure should also be the same instead of one being "X approved MR" and the other "MR was approved by". There's a bunch of little stuff like that I'm seeing but probably should be separate PRs.

2022_07_24_0lg_Kleki

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 should I also mention the reviewer in replies to review threads like this one? It's been a while since I used GitHub...

Anyway I don't think I should commit the screenshotted change as part of this PR. I'd rather review all the different types of webhook message templates and propose fixes in a later PR, but I do think there are multiple things that should be fixed.

But the use of ! itself is correct for GitLab MRs.

@@ -83,6 +87,10 @@ func (w *webhook) handleChannelMergeRequest(ctx context.Context, event *gitlab.M
message = fmt.Sprintf("[%s] Merge request [!%v %s](%s) was closed by [%s](%s)", repo.PathWithNamespace, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
case actionReopen:
message = fmt.Sprintf("[%s] Merge request [!%v %s](%s) was reopened by [%s](%s)", repo.PathWithNamespace, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
case actionApproved:
message = fmt.Sprintf("[%s] Merge request [!%v %s](%s) was approved by [%s](%s)", repo.PathWithNamespace, pr.IID, pr.Title, pr.URL, senderGitlabUsername, w.gitlabRetreiver.GetUserURL(senderGitlabUsername))
Copy link
Member

Choose a reason for hiding this comment

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

(Not part of this PR), but ideally we use the sender's connected Mattermost account to display their Mattermost username instead of their GitLab username

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Couldn't the sender be somebody who hasn't connected their account?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but we should do our best to use the connected account. If they aren't connected, then we should fall back to the default functionality

@mickmister
Copy link
Member

Changed the messages, anything else to do?

@MatthewDorner Make sure you either mention someone when asking a question or re-request review from the person if that's the context of the question

@codecov
Copy link

codecov bot commented Jul 22, 2022

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.15 🎉

Comparison is base (21beec5) 32.27% compared to head (6bc336c) 32.43%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #307      +/-   ##
==========================================
+ Coverage   32.27%   32.43%   +0.15%     
==========================================
  Files          21       21              
  Lines        3433     3441       +8     
==========================================
+ Hits         1108     1116       +8     
  Misses       2215     2215              
  Partials      110      110              
Impacted Files Coverage Δ
server/subscription/subscription.go 95.45% <ø> (ø)
server/webhook/merge_request.go 87.75% <100.00%> (+1.08%) ⬆️
server/webhook/webhook.go 53.26% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@spirosoik spirosoik left a comment

Choose a reason for hiding this comment

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

thanks for the contribution

@mickmister mickmister added 3: QA Review Requires review by a QA tester and removed 2: Dev Review Requires review by a core committer Lifecycle/1:stale labels Aug 25, 2022
@mattermod
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

@hanzei hanzei added this to the v1.6.0 milestone Sep 19, 2022
Makefile Outdated Show resolved Hide resolved
@hanzei hanzei modified the milestones: v1.6.0, v1.7.0 Nov 29, 2022
Revert change to remove --verbose flag in Makefile
@hanzei
Copy link
Collaborator

hanzei commented Feb 22, 2023

/update-branch

@hanzei
Copy link
Collaborator

hanzei commented Feb 22, 2023

@DHaussermann Gentle reminder to review this PR

@mattermost-build
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

Copy link

@DHaussermann DHaussermann left a comment

Choose a reason for hiding this comment

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

Tested and passed

  • Created a subscription that includes merge_request_comments
  • Confirmed that both Approval and Revoke Approval now send webhook events for this feature.
  • A DM is sent to the user

LGTM!

Thanks @MatthewDorner for implementing this! 🎉
Sorry for the delay in getting this approved.

@DHaussermann DHaussermann added 4: Reviews Complete All reviewers have approved the pull request and removed Lifecycle/1:stale 3: QA Review Requires review by a QA tester labels Mar 8, 2023
@hanzei
Copy link
Collaborator

hanzei commented Mar 10, 2023

@MatthewDorner Would you please merge master into your branch?

@hanzei hanzei added the Awaiting Submitter Action Blocked on the author label Mar 10, 2023
@MatthewDorner
Copy link
Contributor Author

@hanzei done

@mattermost-build
Copy link
Contributor

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

@hanzei hanzei merged commit ad1d267 into mattermost:master Mar 22, 2023
@hanzei
Copy link
Collaborator

hanzei commented Mar 22, 2023

Thank you for the contribution @MatthewDorner 👍

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.

Add Merge Request Approval Subscription
7 participants