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

Fix: Subscriptions --exclude functionality affects all channels #505

Closed
wants to merge 12 commits into from

Conversation

sanjaydemansol
Copy link
Contributor

Summary

Now, --exclude is channel specific.

Testing Notes

When using the exclude functionality the exclusion record that get's created owner/repo - notification : disabled is not channel specific. These exclusions appear in channels where no subscriptions have been created yet and no exclusion was specified. image

This affects event delivery in channel --exclude was never used and prevents events from being delivered for some of the repositories. Steps:

  • Create a subscription where an owner is passed in and exclude a repo /github subscriptions add DylanH20 --exclude DylanH20/Hello-World-1
  • Test and note that events are delivered to the channel for all repos under DylanH20 except for Hello-World-1 (as expected)
  • Create a new channel
  • Type /github subscribe list notice DylanH20/Hello-World-1 - notification : disabled is already showing
  • Type /github subscriptions add DylanH20 to subscribe to all repos underDylanH20
  • Type /github subscriptions list in current channel and other channels to confirm, excluded repo should be scoped to current channel.

Ticket Link

Fix #494

@mattermod
Copy link
Contributor

Hello @sanjaydemansol,

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.

Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

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

I'm wondering if the data model makes sense for the use case. See below for more details.

server/plugin/command.go Outdated Show resolved Hide resolved
server/plugin/subscriptions.go Outdated Show resolved Hide resolved
@hanzei hanzei added 2: Dev Review Requires review by a core committer 3: QA Review Requires review by a QA tester labels Oct 27, 2021
@hanzei hanzei added this to the v2.1.0 milestone Oct 27, 2021
@sanjaydemansol sanjaydemansol marked this pull request as draft October 28, 2021 05:38
@dipak-demansol
Copy link

dipak-demansol commented Nov 1, 2021

@sanjaydemansol @hanzei This PR LGTM As Per the Description.
but i found some other issue,its related to exclude but not related to this PR so i reported 2 different issue, here it is, pls check this #507 #508

@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 Nov 1, 2021
Copy link

@dipak-demansol dipak-demansol left a comment

Choose a reason for hiding this comment

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

LGTM As Per the Current PR Description.
but i found some other issue,its related to exclude but not related to this PR so i reported 2 different issue, here it is, pls check this #507 #508

Copy link
Contributor

@hanzei hanzei left a comment

Choose a reason for hiding this comment

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

Discussed offline: The exclude information should be part of the subscription

@sanjaydemansol
Copy link
Contributor Author

Discussed offline: The exclude information should be part of the subscription

Hi, I got it. How should I handle this #505 (comment)?

We still have issues like when user receives direct message, earlier we used to check for exclusion prior to processing webhook

@emilyacook
Copy link

Thanks for participating in Hacktoberfest! You can claim your sticker set here: https://get.printfection.com/hacktober21/4144583267 @sanjaydemansol

@mickmister
Copy link
Contributor

We may already be doing this, but we should make sure to LogDebug when we are avoiding a post creation due to the exclude feature

@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!

/cc @jasonblais @jfrerich @emilyacook

Copy link
Contributor

@sibasankarnayak sibasankarnayak left a comment

Choose a reason for hiding this comment

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

@sanjaydemansol have added few suggestions from my side.

@hanzei hanzei added 2: Dev Review Requires review by a core committer and removed Awaiting Submitter Action Blocked on the author labels Jan 31, 2022
Copy link
Contributor

@mickmister mickmister 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 addressing the feedback @sanjaydemansol 👍

I have a few just more requests on the PR

Comment on lines 280 to 281
func GetExcludedNotificationRepos(s Subscription) []string {
return s.Flags.ExcludedRepos
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like it's still here 🙂

Comment on lines 804 to 816
var repoMatch []string
if len(subs) != 0 {
for _, sub := range subs {
if len(sub.Flags.ExcludedRepos) > 0 {
repoMatch = strings.Split(strings.Trim(strings.Join(sub.Flags.ExcludedRepos, ", "), "/"), "/")
}
}
if len(repoMatch) == 0 {
return "", nil
}
return repoMatch[1], nil
}
return "", nil
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a bit off. Should we add a break after the repoMatch = line?

Or or it could be written this way:

Suggested change
var repoMatch []string
if len(subs) != 0 {
for _, sub := range subs {
if len(sub.Flags.ExcludedRepos) > 0 {
repoMatch = strings.Split(strings.Trim(strings.Join(sub.Flags.ExcludedRepos, ", "), "/"), "/")
}
}
if len(repoMatch) == 0 {
return "", nil
}
return repoMatch[1], nil
}
return "", nil
for _, sub := range subs {
if len(sub.Flags.ExcludedRepos) > 0 {
repoMatch = strings.Split(strings.Trim(strings.Join(sub.Flags.ExcludedRepos, ", "), "/"), "/")
if len(repoMatch) > 1 {
return repoMatch[1], nil
}
}
}
return "", nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, i updated as suggest

Comment on lines 655 to 668
// if config.GitHubOrg != "" {
subscriptionsAdd.AddNamedStaticListArgument("", "Currently supports --exclude and --exclude-org-member", true, []model.AutocompleteListItem{
{
HelpText: "notifications for these repos will be turned off",
Hint: "(optional)",
Item: "--exclude",
},
{
HelpText: "Events triggered by organization members will not be delivered (the organization config should be set, otherwise this flag has no effect)",
Hint: "(optional)",
Item: "--exclude-org-member",
},
})
// }
Copy link
Contributor

@mickmister mickmister Feb 1, 2022

Choose a reason for hiding this comment

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

This won't produce the right autocomplete because we are supposed to have two different field types here. One is text-based, and one is boolean-based.

In order to support boolean-based arguments in our flag argument system, we will need to treat that field as a separate select element:

commandArgumentExcludeHint := "Notifications for these repos will be turned off"
commandArgumentExcludeOrgMemberHint := "Events triggered by organization members will not be delivered (default false)"

cmd.AddNamedTextArgument("exclude", commandArgumentExcludeHint, "", false)

if config.GitHubOrg != "" {
    cmd.AddNamedStaticListArgument("exclude-org-member", commandArgumentExcludeOrgMemberHint, false, []model.AutocompleteListItem{
        {
            Item:     "true",
            HelpText: "Exclude posts from members of the configured organization",
        }, {
            Item:     "false",
            HelpText: "Include posts from members of the configured organization",
        },
    })
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

feedback point 1, remove GithubOrg, #505 (comment)
point 3 exclude and exclude-org-member is positional arguments. fixed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i will check and update as feedback

@@ -353,7 +362,16 @@ func (p *Plugin) handleSubscribesAdd(_ *plugin.Context, args *model.CommandArgs,
return "--exclude feature currently support on organization level."
}

if err := p.Subscribe(ctx, githubClient, args.UserId, owner, repo, args.ChannelId, features, flags); err != nil {
repoMatch, err := p.getExcludedRepo(args)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we support more than one excluded repo 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.

@mickmister 1/5 we may add support for the same in next release. User may call the command multiple times if needed. Do you want me to add it in this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

@sanjaydemansol Most of the code related to the exclude feature seems to imply it works with multiple repos. I need to review the original PR to understand the code better as I wasn't a reviewer on the PR.

Shouldn't we support more than one repo here?

I said this with the assumption that the feature already supports it in general, and that I genuinely don't know if we need to support that in this piece of code as well

for _, excludedRepo := range flags.ExcludedRepos {
var subscribedRepo = strings.Trim(sub.Repository, "/")
if subscribedRepo == excludedRepo {
msg := fmt.Sprintf("Failed to add subscription to %s organization with --exclude. The repository %s cannot be excluded as a subscription already exists. Please remove the existing subscription first.", owner, excludedRepo)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
msg := fmt.Sprintf("Failed to add subscription to %s organization with --exclude. The repository %s cannot be excluded as a subscription already exists. Please remove the existing subscription first.", owner, excludedRepo)
msg := fmt.Sprintf("Failed to add subscription to %s organization with --exclude. The repository %s cannot be excluded as a subscription already exists in another subscription for this channel. Please remove the existing subscription first.", owner, excludedRepo)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update message as per feedback

@hanzei hanzei modified the milestones: v2.1.0, v2.2.0 Feb 3, 2022
@hanzei hanzei removed the Triage label Feb 3, 2022
@hanzei
Copy link
Contributor

hanzei commented Feb 9, 2022

There as conflicts to resolve as #457 has been reverted

@hanzei hanzei added the Awaiting Submitter Action Blocked on the author label Feb 9, 2022
@hanzei hanzei removed their request for review February 9, 2022 08:41
@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!

/cc @aspleenic

@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!

@maisnamrajusingh
Copy link
Contributor

@mickmister please ignore as I clicked on re-request by mistake

@mickmister
Copy link
Contributor

Note: The original feature was reverted here #529, so master is currently not affected by this

@mickmister mickmister removed their request for review August 4, 2022 15:22
@hanzei hanzei removed this from the v2.2.0 milestone Sep 20, 2022
@hanzei hanzei closed this Feb 20, 2023
@mattermost-build mattermost-build removed the Awaiting Submitter Action Blocked on the author label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subscriptions --exclude functionality affects all channels