ref(integration): Extract base class for identity linking
Extract common code for the "link identity" and "unlink identity" operations on messaging integrations.
This PR builds on https://github.com/getsentry/sentry/pull/74743. I'm keeping it in a draft state as I continue to pull more code into the base class.
- The present state of the PR (as I write this comment) is a basic proof of concept showing how the linking and unlinking views for MS Teams and Discord can be unified.
- Slack's view classes are structured differently, and also have more logging and such. I'll be working on unifying Slack with the other two, hopefully imposing some consistency along the way.
- Once Slack's identity-linking business logic is unified, I hope it will serve as a template for how to extract an abstract base view for the team-linking views. That can then "specify" the implementation of the team-linking feature for MS Teams and Discord (at which point we'll hopefully learn if it's suitable for handing off to a developer as a self-contained task, or if the abstraction process makes the remaining steps trivial).
Visual representation:
| Slack | MS Teams | Discord | |
|---|---|---|---|
| Link Identity | ⌛ (1) | ✅ | ✅ |
| Unlink Identity | ⌛ (1) | ✅ | ✅ |
| Link Team | ⌛ (2) | ❓ (3) | ❓ (3) |
| Link Team | ⌛ (2) | ❓ (3) | ❓ (3) |
- ✅ = has been extracted into abstract base classes
- ⌛ = to be extracted into abstract base classes (numbers show intended order)
- ❓ = not yet implemented at all; abstract base class will hopefully show the way
[Update 2024-08-08: "(1)" implemented in https://github.com/getsentry/sentry/pull/75899 ]
Codecov Report
Attention: Patch coverage is 92.83820% with 27 lines in your changes missing coverage. Please review.
:white_check_mark: All tests successful. No failed tests found.
Additional details and impacted files
@@ Coverage Diff @@
## master #74744 +/- ##
==========================================
+ Coverage 78.14% 78.30% +0.15%
==========================================
Files 6896 6829 -67
Lines 306933 304364 -2569
Branches 52823 52420 -403
==========================================
- Hits 239861 238328 -1533
+ Misses 60653 59634 -1019
+ Partials 6419 6402 -17
I'm setting this as ready for review. Only the "✅" items as described in my previous comment are in scope right now. The next steps will entail a level of complexity that seem to be worth handling separately.
imo inheritance makes this way harder to reason about and debug -- would prefer free functions which are also much easier to test
imo inheritance makes this way harder to reason about and debug -- would prefer free functions which are also much easier to test
@asottile-sentry Could you elaborate/give examples? I think the OO approach is good here. For one thing, the end product needs to be View objects anyway. For another, I think it's a pretty natural way to express the set of inter-provider differences and inter-operation differences. The abstract properties document the values that would need to be filled in when support is added for an operation with a new provider, which goes along with Ecosystem dev goals.
My gut says that, if I tried to refactor the operations into free functions, they would need a number of parameters proportional to the current number of abstract properties -- so, a lot. I picked the somewhat complex class structure over functions with obnoxiously long arg lists. Happy to hear other perspectives, though -- thanks.
A sub-branch that replaced the ABC's implementation with Slack's was reviewed in https://github.com/getsentry/sentry/pull/75899 and is now merged into here. This branch should be ready to ship.
Updated table:
| Slack | MSTeams | Discord | |
|---|---|---|---|
| Link identity | ✅ | ✅ | ✅ |
| Unlink identity | ✅ | ✅ | ✅ |
| Link team | ⌛ | ❓ | ❓ |
| Link team | ⌛ | ❓ | ❓ |
✅ = in the scope of this PR ⌛ = in progress at https://github.com/getsentry/sentry/pull/76214 ❓ = targeted for future hand-off