-
Notifications
You must be signed in to change notification settings - Fork 169
[MM-870]: Fixed issue of deletion of non-existent subscription #886
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
Changes from all commits
a4e2ba3
1623485
61def0e
c625d87
4a996bf
355b968
adda7fa
305a73f
810fdea
2cef73b
62a87ce
6173c17
ee669b1
3bab1b5
664e74c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,11 @@ import ( | |
| const ( | ||
| SubscriptionsKey = "subscriptions" | ||
| flagExcludeOrgMember = "exclude-org-member" | ||
| flagIncludeOnlyOrgMembers = "include-only-org-members" | ||
| flagRenderStyle = "render-style" | ||
| flagFeatures = "features" | ||
| flagExcludeRepository = "exclude" | ||
| SubscriptionUnavailable = "no subscription exists for `%s` in the channel" | ||
| flagIncludeOnlyOrgMembers = "include-only-org-members" | ||
| ) | ||
|
|
||
| type SubscriptionFlags struct { | ||
|
|
@@ -399,17 +400,32 @@ func (p *Plugin) GetSubscribedChannelsForRepository(repo *github.Repository) []* | |
| return subsToReturn | ||
| } | ||
|
|
||
| func (p *Plugin) Unsubscribe(channelID, repo, owner string) error { | ||
| type SubscriptionError struct { | ||
| Code int | ||
| Error error | ||
| } | ||
|
|
||
| const ( | ||
| SubscriptionNotFound = iota | ||
| SubscriptionAlreadyExists | ||
| InternalServerError | ||
| ) | ||
|
|
||
| func NewSubscriptionError(code int, err error) *SubscriptionError { | ||
| return &SubscriptionError{Code: code, Error: err} | ||
| } | ||
|
Comment on lines
+408
to
+416
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2/5 I prefer using customer error variables and then checking them using
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Go devs think typed errors are better than sentinel errors. The reason they are not changed in the std lib are for compatibility. Also sentinel errors are much slower. One thing I aways disliked about sentinel errors is that code could replace the error var with something else. MM server is a mix of sentinel and typed errors. |
||
|
|
||
| func (p *Plugin) Unsubscribe(channelID, repo, owner string) *SubscriptionError { | ||
| repoWithOwner := fmt.Sprintf("%s/%s", owner, repo) | ||
|
|
||
| subs, err := p.GetSubscriptions() | ||
| if err != nil { | ||
| return errors.Wrap(err, "could not get subscriptions") | ||
| return NewSubscriptionError(InternalServerError, errors.Wrap(err, "could not get subscriptions")) | ||
| } | ||
|
|
||
| repoSubs := subs.Repositories[repoWithOwner] | ||
| if repoSubs == nil { | ||
| return nil | ||
| return NewSubscriptionError(SubscriptionNotFound, errors.Errorf(SubscriptionUnavailable, strings.TrimSuffix(repoWithOwner, "/"))) | ||
| } | ||
|
|
||
| removed := false | ||
|
|
@@ -421,11 +437,13 @@ func (p *Plugin) Unsubscribe(channelID, repo, owner string) error { | |
| } | ||
| } | ||
|
|
||
| if removed { | ||
| subs.Repositories[repoWithOwner] = repoSubs | ||
| if err := p.StoreSubscriptions(subs); err != nil { | ||
| return errors.Wrap(err, "could not store subscriptions") | ||
| } | ||
| if !removed { | ||
| return NewSubscriptionError(SubscriptionNotFound, errors.Errorf(SubscriptionUnavailable, strings.TrimSuffix(repoWithOwner, "/"))) | ||
| } | ||
|
|
||
| subs.Repositories[repoWithOwner] = repoSubs | ||
| if err := p.StoreSubscriptions(subs); err != nil { | ||
| return NewSubscriptionError(InternalServerError, errors.Wrap(err, "could not store subscriptions")) | ||
| } | ||
|
Kshitij-Katiyar marked this conversation as resolved.
|
||
|
|
||
| return nil | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.