Skip to content

[GH-470] allow users to specify notifications verbosity using a new render-style flag - #534

Merged
mickmister merged 9 commits into
mattermost:masterfrom
ijansky:GH-470_title-only-notifications
Aug 22, 2022
Merged

[GH-470] allow users to specify notifications verbosity using a new render-style flag#534
mickmister merged 9 commits into
mattermost:masterfrom
ijansky:GH-470_title-only-notifications

Conversation

@ijansky

@ijansky ijansky commented Feb 16, 2022

Copy link
Copy Markdown
Contributor

Summary

This pull request adds a --render-style flag to the subscription command to define the notification verbosity of an event rather than the full body as it can be quite lengthy and easily spam a team mattermost channel. It is a shared effort of myself and @TeodorPt and we raised this PR to get early feedback on the direction that this PR takes

Ticket Link

Fixes #470

@mattermod

Copy link
Copy Markdown
Contributor

Hello @ijansky,

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.

@TeodorPt
TeodorPt force-pushed the GH-470_title-only-notifications branch 3 times, most recently from ca92c97 to 6c88096 Compare February 17, 2022 08:15
@codecov-commenter

codecov-commenter commented Feb 17, 2022

Copy link
Copy Markdown

Codecov Report

Merging #534 (ced9364) into master (75bcaa1) will increase coverage by 0.29%.
The diff coverage is 39.37%.

@@            Coverage Diff             @@
##           master     #534      +/-   ##
==========================================
+ Coverage   15.51%   15.80%   +0.29%     
==========================================
  Files          15       15              
  Lines        4151     4201      +50     
==========================================
+ Hits          644      664      +20     
- Misses       3465     3494      +29     
- Partials       42       43       +1     
Impacted Files Coverage Δ
server/plugin/command.go 8.33% <0.00%> (-0.29%) ⬇️
server/plugin/subscriptions.go 9.52% <0.00%> (-0.59%) ⬇️
server/plugin/webhook.go 0.95% <31.81%> (+0.95%) ⬆️
server/plugin/template.go 95.60% <100.00%> (+0.21%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75bcaa1...ced9364. Read the comment docs.

@ijansky
ijansky force-pushed the GH-470_title-only-notifications branch from 6c88096 to 8cbf330 Compare February 17, 2022 15:15
@hanzei hanzei added the 2: Dev Review Requires review by a core committer label Feb 18, 2022
@hanzei
hanzei requested a review from mickmister February 18, 2022 18:22
@hanzei hanzei added the 3: QA Review Requires review by a QA tester label Feb 18, 2022

@hanzei hanzei left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Great work 👍

This change will increase the load of the webhook handler a bit as there is additional parsing of the template, but that is fine.

@ijansky
ijansky marked this pull request as ready for review February 23, 2022 13:10
@ijansky ijansky changed the title [GH-470] title only notifications - WIP [GH-470] title only notifications Feb 23, 2022
@ijansky

ijansky commented Feb 23, 2022

Copy link
Copy Markdown
Contributor Author

Thanks for the review @hanzei!

@hanzei

hanzei commented Feb 23, 2022

Copy link
Copy Markdown
Contributor

Your welcome! There was nothing to complain about 😉

@rinkimekari

rinkimekari commented Mar 2, 2022

Copy link
Copy Markdown
Contributor

@hanzei
I tested this fix out because it has to do with my PR #545 and I wanted to compare them. However, I can't seem to get it to work. Deploying the plugin works fine, and autocomplete for the command works perfectly, but whether or not the flag is enabled, it always shows the normal expanded message for notifications. There should definitely be tests in template_test.go for the cases when the flag is enabled.

@mickmister

Copy link
Copy Markdown
Contributor

@ijansky Do you mind posting a screenshot of what this feature looks like?

@TeodorPt

TeodorPt commented Mar 8, 2022

Copy link
Copy Markdown
Contributor

Hi @mickmister @rinkimekari, sorry for the delay, had a busy week. I have tested this locally now and it works - the way to subscribe would be /github subscriptions add [owner/repo] [features] --title-only. See screenshots below:

Long version:
image

Title-only:
image

Of course I will add unit tests for the flag enabled as well before merging. Also the "title-only" version could be displayed even more collapsed if you prefer, it's easy to change.
But we opened this PR initially as a request for comments, to get a sense of the direction and see if you would prefer this approach, since we identified 2 ways of doing it:

  1. This approach: passing an event with config options to the template, and then letting the template decide how to present the event based on the config.
  2. Multiple templates approach (similar to @rinkimekari 's solution): having one template for no-title/collapsed and one for full and deciding between the two.

We went for the former approach because it keeps a nice separation of rendering logic and business logic (whole rendering is the responsibility of the template itself), and it makes it easier to add additional configuration options in the future, without having to add if-else statements where the templates are used.

It seems there was duplicate work here, since there were 2 opened issues for the same issue. Let me know if you're happy for me to proceed and I'll turn this PR into something merge-worthy asap.

Thanks!

@TeodorPt

Copy link
Copy Markdown
Contributor

@mickmister can you help me with a review when you have the chance? Thank you very much!

@mickmister mickmister left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @ijansky and @TeodorPt for implementing this!

This mostly looks good. I just have one request to modify how the command flags work in the command autocomplete, so that we can use multiple flags in the same command.

Comment thread server/plugin/command.go Outdated
Hint: "(optional)",
Item: "--title-only",
}}
subscriptionsAdd.AddStaticListArgument("Currently supports --exclude-org-member and --title-only", false, flags)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In the state of this PR, we are not able to use both the exclude-org-member and title-only flags simultaneously. This is because they are being treated as a single positional argument, each showing up as a single selectable option in the same argument.

Similar to what was discussed in #505 (comment), we should use "named" arguments with explicit true/false values, rather than using positional arguments that implicitly mean true.

Also, this title-only flag should be available even when config.GitHubOrg is not defined, but it's currently added in this if block which restricts to when config.GitHubOrg is defined.

Comment thread server/plugin/webhook.go
Comment on lines +313 to +320
actual, err := renderTemplate("newPR", GetEventWithRenderConfig(
&github.PullRequestEvent{
Repo: &repo,
PullRequest: &pullRequestWithMultipleLabelsAndAssignees,
Sender: &user,
},
nil,
))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add tests for all templates that support the title-only flag?

@TeodorPt
TeodorPt force-pushed the GH-470_title-only-notifications branch 3 times, most recently from c82a29a to f5f20e3 Compare April 1, 2022 12:16
@TeodorPt

TeodorPt commented Apr 1, 2022

Copy link
Copy Markdown
Contributor

Hi @mickmister, I've made several changes to the PR, PTAL again:

  • flags now accept a value as well, per your suggestion
  • taking advantage of that and the EventWithConfig approach, the flag is now not title-only anymore, but render-style, which could either be collapsed, skip-body or default
  • added tests

Here's the rendered output for all 3 formats in my tests:
Screenshot from 2022-04-01 14-55-50

@TeodorPt
TeodorPt force-pushed the GH-470_title-only-notifications branch 3 times, most recently from a0899b1 to fea4888 Compare April 1, 2022 12:28

@dipak-demansol dipak-demansol left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@dipak-demansol dipak-demansol added QA Review Done PR has been approved by QA and removed 3: QA Review Requires review by a QA tester labels May 12, 2022
@mattermod

Copy link
Copy Markdown
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!

@TeodorPt

Copy link
Copy Markdown
Contributor

@mickmister ptal, this needs a maintainer approval it seems

@mickmister mickmister left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Just one suggestion to namespace the flag name constants

Thanks @TeodorPt @ijansky @dipak-demansol

Comment thread server/plugin/subscriptions.go Outdated
Comment on lines +18 to +20
excludeOrgMemberFlag = "exclude-org-member"
renderStyleFlag = "render-style"
FeaturesFlag = "features"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@TeodorPt What do you think about namespacing the constants like so:

Suggested change
excludeOrgMemberFlag = "exclude-org-member"
renderStyleFlag = "render-style"
FeaturesFlag = "features"
flagExcludeOrgMember = "exclude-org-member"
flagRenderStyle = "render-style"
flagFeatures = "features"

@TeodorPt

Copy link
Copy Markdown
Contributor

It's been a while since updating this, been caught up in a lot of other things. I've made the changes and will do a re-test asap and ping you when it's ready (some changes to the documentation were also needed).

@TeodorPt
TeodorPt force-pushed the GH-470_title-only-notifications branch from 1c38648 to f3f5c61 Compare June 25, 2022 05:33
@TeodorPt

Copy link
Copy Markdown
Contributor

@mickmister I finally got around to addressing your comments. I also identified some omissions in the help documentation - I've updated that as well and re-tested everything end-to-end to make sure things are still working.

I've forced-pushed due to CI tests timing out (you can check with Compare that no changes were made in the force push). However, the tests are still timing out, do you know why?

Thank you!

@mickmister mickmister left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@mickmister
mickmister requested a review from DHaussermann July 22, 2022 07:59
@mickmister mickmister removed 2: Dev Review Requires review by a core committer Lifecycle/1:stale QA Review Done PR has been approved by QA labels Jul 22, 2022
@mickmister

Copy link
Copy Markdown
Contributor

@DHaussermann After looking at the changes from last QA review from Dipak, there are no significant changes, so I think this is good to merge

@DHaussermann

Copy link
Copy Markdown

/update-branch

@DHaussermann DHaussermann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested and passed

  • All 3 renders styles work as expected
  • Render styles behaves as default when not set
  • --render-style shows in subscriptions list when set
    LGTM!

Huge thanks @ijansky for this enhancement 🎉
Sorry for the delay on this.

@DHaussermann DHaussermann added the 4: Reviews Complete All reviewers have approved the pull request label Jul 29, 2022
@ijansky

ijansky commented Jul 29, 2022

Copy link
Copy Markdown
Contributor Author

@TeodorPt thank you for addressing code review comments. 👍

@mattermod

Copy link
Copy Markdown
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!

@mickmister
mickmister merged commit 4043d0b into mattermost:master Aug 22, 2022
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 Contributor Lifecycle/1:stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a way to shrink notification bodies per-subscription

10 participants