sentry icon indicating copy to clipboard operation
sentry copied to clipboard

ref(integration): Extract base class for identity linking

Open RyanSkonnord opened this issue 1 year ago • 4 comments

Extract common code for the "link identity" and "unlink identity" operations on messaging integrations.

RyanSkonnord avatar Jul 23 '24 17:07 RyanSkonnord

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 ]

RyanSkonnord avatar Jul 23 '24 18:07 RyanSkonnord

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.

Files Patch % Lines
src/sentry/integrations/messaging.py 89.72% 15 Missing and 4 partials :warning:
src/sentry/integrations/slack/views/linkage.py 91.42% 2 Missing and 1 partial :warning:
src/sentry/integrations/msteams/link_identity.py 87.50% 1 Missing and 1 partial :warning:
...sentry/integrations/slack/views/unlink_identity.py 87.50% 1 Missing and 1 partial :warning:
src/sentry/integrations/msteams/linkage.py 95.83% 1 Missing :warning:
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     

codecov[bot] avatar Aug 03 '24 10:08 codecov[bot]

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.

RyanSkonnord avatar Aug 06 '24 03:08 RyanSkonnord

imo inheritance makes this way harder to reason about and debug -- would prefer free functions which are also much easier to test

asottile-sentry avatar Aug 06 '24 12:08 asottile-sentry

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.

RyanSkonnord avatar Aug 15 '24 08:08 RyanSkonnord

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

RyanSkonnord avatar Aug 15 '24 08:08 RyanSkonnord