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

Add support for DM subscriptions based on "watching" an issue in Jira #507

Open
mickmister opened this issue Mar 24, 2020 · 11 comments · May be fixed by #1097
Open

Add support for DM subscriptions based on "watching" an issue in Jira #507

mickmister opened this issue Mar 24, 2020 · 11 comments · May be fixed by #1097
Assignees
Labels
1: PM Review Requires review by a product manager Good First Issue Suitable for first-time contributors Hacktoberfest Help Wanted Community help wanted Tech/Go Type/Enhancement New feature or improvement of existing feature
Milestone

Comments

@mickmister
Copy link
Contributor

mickmister commented Mar 24, 2020

Summary

In order to get a DM notification from the Jira plugin, the user has to meet certain criteria like being assigned or mentioned. If a user is "watching" an issue in Jira's system, they could want to receive notifications for any changes on the issue. This can be a system-wide setting combined with a user-specific setting.

Additional Info

We can use IssueService.GetWatchers(issueID string) during the webhook event processing to compare against our users' settings.

Note that this does not look possible in the GitHub plugin based on GitHub's documented API.

@mickmister mickmister added the 1: PM Review Requires review by a product manager label Mar 24, 2020
@mickmister mickmister added Good First Issue Suitable for first-time contributors Help Wanted Community help wanted Tech/Go Type/Enhancement New feature or improvement of existing feature Up For Grabs Ready for help from the community. Removed when someone volunteers labels Apr 8, 2020
@haardikdharma10
Copy link
Contributor

Hi @mickmister, I'd like to work on this. Can you help me on getting started?

@mickmister
Copy link
Contributor Author

mickmister commented Oct 9, 2020

@haardikdharma10 Sure, thanks for your interest in the ticket!

First, you'll need to set up your development environment. Here's some docs to help get started. Join the Jira plugin channel on our community server and we can discuss the feature or any questions you might have!

@mickmister mickmister removed the Up For Grabs Ready for help from the community. Removed when someone volunteers label Oct 9, 2020
@mickmister
Copy link
Contributor Author

I'm thinking we will add some functionality added to line 60 below, that will call a new function defined on *Plugin to handle the watchers.

wh, err := ParseWebhook(msg.Data)
if err != nil {
return err
}
if _, _, err = wh.PostNotifications(ww.p, msg.InstanceID); err != nil {
ww.p.errorf("WebhookWorker id: %d, error posting notifications, err: %v", ww.id, err)
}

The function should do the following:

  • Fetch the watchers of the issue using a JIRA API client. The wh variable can be used to get the issue key.
  • For each watcher, check if they have their notification settings in our system set to receive watcher notifications. This will be a new user config setting we will introduce to our JIRA User model's settings, adjustable through a slash command like /jira settings watching on
  • Add each appropriate user to the wh.notifications array
  • Avoid duplicate users that are already in the array

Here's some code to create a new notification to append to the array:

wh.notifications = append(wh.notifications, webhookUserNotification{
jiraUsername: jwh.Issue.Fields.Assignee.Name,
jiraAccountID: jwh.Issue.Fields.Assignee.AccountID,
message: fmt.Sprintf("%s **commented** on %s:\n>%s", commentAuthor, jwh.mdKeySummaryLink(), jwh.Comment.Body),
postType: PostTypeComment,
commentSelf: jwh.Comment.Self,
})

@haardikdharma10
Copy link
Contributor

Thanks for such a brief explanation @mickmister, really appreciated. After going through the docs and some minimal research, first question I have here is, we can have 2 things here, a type called 'Watcher' and a type called 'Watches' wherein the latter will look something like this:

type Watches struct {
    Self       string     `json:"self,omitempty" structs:"self,omitempty"`
    WatchCount int        `json:"watchCount,omitempty" structs:"watchCount,omitempty"`
    IsWatching bool       `json:"isWatching,omitempty" structs:"isWatching,omitempty"`
    Watchers   []*Watcher `json:"watchers,omitempty" structs:"watchers,omitempty"`
}

This will represent a type of how many and which users are "observing" a Jira issue to track the status / updates.

Watcher, which will look something like this:

type Watcher struct {
    Self        string `json:"self,omitempty" structs:"self,omitempty"`
    Name        string `json:"name,omitempty" structs:"name,omitempty"`
    AccountID   string `json:"accountId,omitempty" structs:"accountId,omitempty"`
    DisplayName string `json:"displayName,omitempty" structs:"displayName,omitempty"`
    Active      bool   `json:"active,omitempty" structs:"active,omitempty"`
}

This will represent a common user that "observes" the issue. Do we need both of them or only one?

The function signature, according to me should be somewhat like:
func (s *IssueService) GetWatchers(issueID string) (*[]User, *Response, error)

The REST API docs here were also helpful (unfortunately, there is no ready code snippet in go). With this, I am still confused on how to go about the second bullet you mentioned and the array part. I think I have understood the job in bits and pieces and just want to integrate things and get it done!

@mickmister
Copy link
Contributor Author

mickmister commented Oct 10, 2020

@haardikdharma10 Thanks for the explanations of your strategy. I have some questions and suggestions:

The REST API docs here were also helpful (unfortunately, there is no ready code snippet in go).

In the description, I had mentioned IssueService, but I actually meant to say was the service at client.Jira.Issue when using the Jira client from go-jira. We have a name collision of internal and external library names for IssueService there. There is a GetWatchers function here that will return what we need. It actually has the exact same signature as the one you suggested

func (s *IssueService) GetWatchers(issueID string) (*[]User, *Response, error) {

I'm not sure why we need to add the Watches and Watcher datatypes. Can you please explain what the roles of these datatypes are? When/why are they accessed, etc. This is how I see the process going for handling the users watching the ticket:

  • Create a new user setting in the plugin here, which will be a boolean of "does the user want to receive MM notifications for tickets they are 'watching' in Jira." Let's call this setting WatchingNotifications. You can see how this can be configured by observing how the Notifications setting is currently handled in the project.
  • When we receive a webhook event, call the GetWatchers function to get the users watching
  • For every user that is watching the ticket, fetch their WatchingNotifications setting from our database.
  • For each one that has their setting true, append their user info to the array

In one of the code snippets in my previous comment, there is a variable wh that has a notifications field, that has been filled by ParseWebhook. This notifications field is the array I've been referring to:

type webhook struct {
*JiraWebhook
eventTypes StringSet
headline string
text string
fields []*model.SlackAttachmentField
notifications []webhookUserNotification
fieldInfo webhookField
}

At this point, it is filled with any users that were mentioned in a comment, or a separate notification in the array for the assignee of the ticket. We basically want to add any watchers to this array, but avoid adding any duplicates that are already in the array. Editing the wh.notifications array should be all we need to do.

Please let me know your thoughts @haardikdharma10 🙂

@mickmister
Copy link
Contributor Author

Hi @haardikdharma10, how are you doing? Do you have any thoughts or questions on my proposal above?

@mickmister
Copy link
Contributor Author

Hi @haardikdharma10, hope everything is well. Is it okay if I unassign you from this ticket, so another developer may work work on the ticket?

@haardikdharma10
Copy link
Contributor

Hey @mickmister, sure.

@mickmister mickmister added the Up For Grabs Ready for help from the community. Removed when someone volunteers label Nov 17, 2020
@jasonblais jasonblais added this to the v3.1.0 milestone Jul 21, 2021
@mickmister mickmister removed the Up For Grabs Ready for help from the community. Removed when someone volunteers label Jul 22, 2021
vickydk added a commit to demansoltech/mattermost-plugin-jira that referenced this issue Aug 1, 2021
…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
jupriano pushed a commit to jupriano/mattermost-plugin-jira that referenced this issue Oct 28, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-jira that referenced this issue Oct 28, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-jira that referenced this issue Oct 28, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-jira that referenced this issue Oct 28, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-jira that referenced this issue Oct 28, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-jira that referenced this issue Nov 16, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-jira that referenced this issue Nov 25, 2021
jupriano pushed a commit to jupriano/mattermost-plugin-jira that referenced this issue Nov 25, 2021
@hanzei hanzei modified the milestones: v3.2.0, v3.3.0 Mar 1, 2022
@hanzei hanzei modified the milestones: v3.3.0, v3.4.0 Feb 23, 2023
@wiersgallak
Copy link
Contributor

Closing issues due to inactivity. This issue can be re-opened with more interest from our community.

@mickmister
Copy link
Contributor Author

@wiersgallak Heads up that issues that are intended to be closed due to not being part of planned work, should be closed via the "Close as not planned" option in GitHub's UI. Otherwise it can be mistaken as "completed".

CleanShot 2023-07-06 at 14 35 49

Also, this issue in particular has an open PR from Brightscout #872, so maybe it shouldn't be closed. This feature is very high impact. It's currently just waiting on QA review, though currently not prioritized or testable due to #945

@wiersgallak
Copy link
Contributor

Thanks for catching it and letting me know the appropriate process. Noted for future updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment