-
Notifications
You must be signed in to change notification settings - Fork 127
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-507] Add support for DM subscriptions based on "watching" an issue in Jira (#507) #792
Conversation
…mattermost#507) * add command setting watching * add new client api for GetWatchers * add function to add notification for the user who enable watching in setting
Hello @vicky-demansol, 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. Per the Mattermost Contribution Guide, we need to add you to the list of approved contributors for the Mattermost project. Please help complete the Mattermost contribution license agreement? This is a standard procedure for many open source projects. Please let us know if you have any questions. We are very happy to have you join our growing community! If you're not yet a member, please consider joining our Contributors community channel to meet other contributors and discuss new opportunities with the core team. |
Codecov Report
@@ Coverage Diff @@
## master #792 +/- ##
==========================================
- Coverage 34.93% 34.51% -0.43%
==========================================
Files 52 52
Lines 5945 6038 +93
==========================================
+ Hits 2077 2084 +7
- Misses 3659 3744 +85
- Partials 209 210 +1
Continue to review full report at Codecov.
|
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.
Great work @vicky-demansol! I'm really looking forward to this feature 👍
I have some requests regarding:
- Checking watchers before calling
PostNotifications
- Only fetch watchers once
- Other requests regarding processing watchers
server/user.go
Outdated
@@ -44,6 +44,7 @@ func (c *Connection) JiraAccountID() types.ID { | |||
|
|||
type ConnectionSettings struct { | |||
Notifications bool `json:"notifications"` | |||
Watching bool `json:"watching"` |
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.
Can we make this *bool
, and use a similar strategy as described here? I'd like users to be able to get these notifications without enabling this.
@DHaussermann Maybe we should be clear about why the user got the notification, and note that they can opt-out of this feature? If we have it off by default, I think it won't be discovered by most users.
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.
@mickmister I've pushed a new commit for this change, could you please check it?
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.
@DHaussermann @aaronrothschild Please see my comment above
-
If the current settings for a user has notifications "on" before this PR, should we assume the user also wants reporter and watcher notifications when we introduce the changes from this PR? Should we tell the user how to change their settings? Maybe we only tell them how to change their settings the next time they get a notification. We tell them how to change their settings, and don't remind them again.
-
Should we tell the user the reason they are getting a notification? It would be one of the following reasons:
- Mentioned
- Assignee
- Reporter
- Watching
server/webhook.go
Outdated
@@ -199,3 +202,79 @@ func (p *Plugin) GetWebhookURL(jiraURL string, teamID, channelID string) (subURL | |||
|
|||
return subURL, legacyURL, nil | |||
} | |||
|
|||
func (wh *webhook) getConnection(p *Plugin, instance Instance, notification webhookUserNotification) (con *Connection, 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.
Does this method need to be defined on *webhook
? Is something similar already implemented on the *Plugin
struct?
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.
@vicky-demansol I don't think this method needs to be defined on *webhook
. Can we just call an existing method to fetch the connection instead?
This PR has been automatically labelled "stale" because it hasn't had recent activity. |
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.
@vicky-demansol thanks for the PR! This is going to be a great new feature! I've left some suggestions and one question for @mickmister. Do you need any help with the suggestions from @mickmister?
…k in the URL (mattermost#773) * change variable name from issue to watcher in server/client.go * change variable type from bool to pointer bool in server/user.go * add constants for error store new settings and error connect to Jira * move CheckWatcherUser before PostNotifications (server/webhook_worker.go) * remove LoadConnection after StoreConnection (server/settings.go)
@mickmister @vicky-demansol has signed the CLA and I can see his name on the CLA spreadsheet but for some reason it still says he needs to sign the CLA. Could you please take a look? |
/check-cla |
@maisnamrajusingh When this occurs, you can create a |
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.
Thanks for implementing the requested changes @vicky-demansol 👍
I've requested some more changes. For some reason GitHub isn't letting me reply to my older comments so I had to create new threads.
server/webhook.go
Outdated
message: message, | ||
postType: postType, |
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.
What happens here when the wh.notifications
array is empty and message
is blank? How do we access the message to create a notification? Maybe we need to call a function to generate a message for this webhook call.
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.
@mickmister I've pushed a new commit for this change, could you please check it?
I put the same logic with func PostNotifications
mattermost-plugin-jira/server/webhook.go
Lines 100 to 103 in 6678cae
func (wh *webhook) PostNotifications(p *Plugin, instanceID types.ID) ([]*model.Post, int, error) { | |
if len(wh.notifications) == 0 { | |
return nil, http.StatusOK, nil | |
} |
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.
See #792 (comment)
server/webhook.go
Outdated
} | ||
|
||
// if setting watching value is false don't put into webhookUserNotification | ||
if err != nil || c.Settings == nil || (c.Settings.Watching != nil && !*c.Settings.Watching) { |
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.
I'd like to encapsulate part of this logic in its own method for backwards compatibility:
if err != nil || c.Settings == nil || (c.Settings.Watching != nil && !*c.Settings.Watching) { | |
if err != nil || c.Settings == nil || ! c.Settings.ShouldReceiveWatcherNotifications() { |
func (s *ConnectionSettings) ShouldReceiveWatcherNotifications() bool {
if s.Watching != nil {
return *s.Watching
}
// Check old setting for backwards compatibility
return s.Notifications
}
There would then be an equivalent for assignee and mention notifications. Please see #705 (comment) for my explanation on introducing new notification settings. Whichever PR is merged first should have separate notification settings for assignee and mentions.
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.
Also, can we move these two if
blocks above, before we instantiate the webhookUserNotification
?
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.
@mickmister I've pushed a new commit for this change, could you please check it?
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.
Notice my comment above:
Whichever PR is merged first should have separate notification settings for assignee and mentions.
Which means this PR should have separate notification settings for assignee and mention notifications.
@@ -43,7 +43,8 @@ func (c *Connection) JiraAccountID() types.ID { | |||
} | |||
|
|||
type ConnectionSettings struct { | |||
Notifications bool `json:"notifications"` | |||
Notifications bool `json:"notifications"` | |||
Watching *bool `json:"watching"` |
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.
We'll need to update display logic of settings to include this new setting. It needs to included added here:
mattermost-plugin-jira/server/user.go
Lines 49 to 55 in 6678cae
func (s *ConnectionSettings) String() string { | |
notifications := "off" | |
if s != nil && s.Notifications { | |
notifications = "on" | |
} | |
return fmt.Sprintf("\tNotifications: %s", notifications) | |
} |
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.
@mickmister I've pushed a new commit for this change, could you please check it?
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.
In this PR, can we also add separate settings for assignee and mention notifications, as explained here #705 (comment)? The Reporter
notifications will not be included here however.
server/client.go
Outdated
@@ -195,6 +196,15 @@ func (client JiraClient) GetIssue(key string, options *jira.GetQueryOptions) (*j | |||
return issue, nil | |||
} | |||
|
|||
// GetWatchers returns an array of Jira watchers for a given issue. |
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.
// GetWatchers returns an array of Jira watchers for a given issue. | |
// GetWatchers returns an array of Jira users watching a given issue. |
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.
@mickmister I've pushed a new commit for this change, could you please check it?
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.
The new text you've committed says "Jira users watching for a given issue.", but I think it should be "Jira users watching a given issue."
…k in the URL (mattermost#773) * bug fixing return on/off in fun settingsWatching * fixing wording in settings.go * change variable name from CheckWatcherUser to CheckIssueWatchers (webhook_worker.go) * display logic of watching in ConnectionSettings
…k in the URL (mattermost#773) * handling wh.notifications array is empty * fixing shouldNotReceiveNotification condition
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.
Approving on my end, but comments from @mickmister still need to be resolved. Thanks for the PR, @vicky-demansol!
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.
Great work @vicky-demansol, I have a few more requests on the PR
@@ -43,7 +43,8 @@ func (c *Connection) JiraAccountID() types.ID { | |||
} | |||
|
|||
type ConnectionSettings struct { | |||
Notifications bool `json:"notifications"` | |||
Notifications bool `json:"notifications"` | |||
Watching *bool `json:"watching"` |
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.
In this PR, can we also add separate settings for assignee and mention notifications, as explained here #705 (comment)? The Reporter
notifications will not be included here however.
|
||
instance, err := p.instanceStore.LoadInstance(instanceID) | ||
if err != nil { | ||
// This isn't an internal server error. There's just no instance installed. |
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.
This isn't an internal server error. There's just no instance installed.
How do you know this is true? It looks like there are several kinds of errors that can happen in LoadInstance
. Can we make it so the LoadInstance
function returns a nil
error, and nil
for instance
, so we know whether it was a real error if there is no instance?
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.
@vicky-demansol This request hasn't been addressed yet the comment was marked as resolved
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.
@mickmister @vicky-demansol is doing just that. But if it returns nil, do we log it here
mattermost-plugin-jira/server/webhook.go
Line 204 in 2325e8e
return |
server/webhook.go
Outdated
if len(wh.notifications) == 0 { | ||
return | ||
} |
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.
I don't think we should return here. This just means no users will receive assignee or mention notifications, but we should still look at which users are watching the issue.
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.
@mickmister are i just need to delete the statement or add something to ?
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.
We should delete this if
block
@vicky-demansol Please take a look at all comments on the PR that are still "Unresolved" |
if err != nil { | ||
if errors.Is(errors.Wrap(kvstore.ErrNotFound, hashedKey), err) { | ||
return nil, nil |
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.
@vicky-demansol can we log the error and in below case too.
|
||
instanceID, err := p.ResolveWebhookInstanceURL(jiraURL) | ||
if err != nil { | ||
return "", "", err |
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.
adding error log will help
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.
done i was add the logging
con, err = p.userStore.LoadConnection(instance.GetID(), mattermostUserID) | ||
if err != nil { | ||
// Not connected to Jira, so can't check permissions | ||
return |
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.
seems logging and returning error can help to understand better the situation
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.
done i was add the logging
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.
few suggestions and request to be made from my side
Co-authored-by: sibasankarnayak <86650698+sibasankarnayak@users.noreply.github.com>
Co-authored-by: sibasankarnayak <86650698+sibasankarnayak@users.noreply.github.com>
Co-authored-by: sibasankarnayak <86650698+sibasankarnayak@users.noreply.github.com>
Co-authored-by: sibasankarnayak <86650698+sibasankarnayak@users.noreply.github.com>
mattermostUserID, err = p.userStore.LoadMattermostUserID(instance.GetID(), notification.jiraUsername) | ||
} | ||
if err != nil { | ||
return |
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.
i think error was declare as err in function return and it will return if it has error value
Co-authored-by: sibasankarnayak <86650698+sibasankarnayak@users.noreply.github.com>
@mickmister Gentle reminder to review the PR |
@mickmister @hanzei will be taking up this Issue from here to complete it asap, will create a new PR and close it once i create new one |
… (#507)