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 implementation for Members, Sources and Invitations endpoints #131

Merged
merged 20 commits into from
Dec 20, 2024

Conversation

GG-Yanne
Copy link
Contributor

@GG-Yanne GG-Yanne commented Dec 6, 2024

Add support for managing users

This PR implements all endpoints required for managing users on an account as well as adding support for invitations and sources handling

@GG-Yanne GG-Yanne requested a review from Alustrat-gg December 6, 2024 14:51
@GG-Yanne GG-Yanne self-assigned this Dec 6, 2024
@GG-Yanne GG-Yanne requested a review from a team as a code owner December 6, 2024 14:51
@codecov-commenter
Copy link

codecov-commenter commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 93.38677% with 33 lines in your changes missing coverage. Please review.

Project coverage is 93.99%. Comparing base (391408f) to head (5133106).

Files with missing lines Patch % Lines
pygitguardian/client.py 82.55% 26 Missing ⚠️
pygitguardian/models.py 98.26% 5 Missing ⚠️
pygitguardian/models_utils.py 96.72% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #131      +/-   ##
==========================================
- Coverage   94.55%   93.99%   -0.56%     
==========================================
  Files           6        7       +1     
  Lines         918     1382     +464     
==========================================
+ Hits          868     1299     +431     
- Misses         50       83      +33     
Flag Coverage Δ
unittests 93.99% <93.38%> (-0.56%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@GG-Yanne GG-Yanne force-pushed the ybensafia/members-teams-endpoints branch 3 times, most recently from f8f01c3 to 03648d2 Compare December 6, 2024 15:37
@GG-Yanne GG-Yanne force-pushed the ybensafia/members-teams-endpoints branch from 03648d2 to b5f7f6b Compare December 6, 2024 15:57
pygitguardian/client.py Outdated Show resolved Hide resolved
pygitguardian/client.py Outdated Show resolved Hide resolved
pygitguardian/models.py Show resolved Hide resolved
tests/test_client.py Show resolved Hide resolved
tests/test_client.py Outdated Show resolved Hide resolved
pygitguardian/models.py Outdated Show resolved Hide resolved
pygitguardian/client.py Outdated Show resolved Hide resolved
pygitguardian/models.py Outdated Show resolved Hide resolved
pygitguardian/models.py Outdated Show resolved Hide resolved
@GG-Yanne GG-Yanne force-pushed the ybensafia/members-teams-endpoints branch from 51ea4cc to 3e17f92 Compare December 11, 2024 16:05
@GG-Yanne GG-Yanne requested a review from agateau-gg December 11, 2024 16:27
Copy link

@Alustrat-gg Alustrat-gg left a comment

Choose a reason for hiding this comment

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

Good Job Yanne 👍

I just think that we sometime have incoherences in the way we pass parameters/queries/bodies but it's a detail

pygitguardian/models.py Outdated Show resolved Hide resolved
pygitguardian/models.py Outdated Show resolved Hide resolved
pygitguardian/models.py Outdated Show resolved Hide resolved
pygitguardian/client.py Show resolved Hide resolved
pygitguardian/client.py Outdated Show resolved Hide resolved
pygitguardian/client.py Outdated Show resolved Hide resolved
@GG-Yanne GG-Yanne force-pushed the ybensafia/members-teams-endpoints branch from 050bf67 to 463062c Compare December 13, 2024 13:21
Copy link
Collaborator

@agateau-gg agateau-gg left a comment

Choose a reason for hiding this comment

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

I usually do inline reviews, but that PR is too big to make this practical.

Regarding VCR cassettes

If it's not possible to write a script to automatically setup the account, then can you create a Markdown document in doc/dev/ (We have a similar directory in ggshield, but you would have to create it there) to list all the requirements for the account in one place? This would be more efficient than having to look for comments in different tests to gather them all.

client.py

update_*() methods

  • either make them all return Optional[Detail] or Union[Detail, <ModelClass>] (update_team_source() returns Union[Detail, int]).
  • be consistent with argument names because people are going to use keyword arguments for them and changing them after a release is an API breakage. So either we call them all payload or w call theom all <name_of_the_model>. I prefer payload because what they take is not an instance of the model, it's an instance of Update<Model>.

Misc

Rename list_teams_sources() to list_team_sources() for consistency.

Remove the "obj.status_code" useless lines (grep -n "^ *obj\.status_code$" client.py to find them)

models.py

@post_load methods

  • Type-hint for **kwargs must be Any.

  • All existing @post_load methods are called make_<something>. Can you use the same naming convention for yours?

conftest.py

get_member() is never used, can we remove it?

Instead of creating fixtures, you can create a test.utils module with plain functions and import them in the tests.

@GG-Yanne
Copy link
Contributor Author

GG-Yanne commented Dec 18, 2024

Regarding VCR cassettes

If it's not possible to write a script to automatically setup the account, then can you create a Markdown document in doc/dev/ (We have a similar directory in ggshield, but you would have to create it there) to list all the requirements for the account in one place? This would be more efficient than having to look for comments in different tests to gather them all.

I added doc/dev/tests.md akin to what is done for GG Shield and listed all hard requirements for the workplace to be able to run the test suite without issues

update_*() methods

  • either make them all return Optional[Detail] or Union[Detail, <ModelClass>] (update_team_source() returns Union[Detail, int]).

update_team_source works in a particular way, it does not return a ModelClass since we are adding and removing sources and the endpoint does not return them, see : https://api.gitguardian.com/docs#tag/Team-Sources/operation/update-team-sources

In any case, I applied the same logic as for delete endpoints and optionally returning a Detail object if the status code is not the one we expect for a successful call 👍

  • be consistent with argument names because people are going to use keyword arguments for them and changing them after a release is an API breakage. So either we call them all payload or w call theom all <name_of_the_model>. I prefer payload because what they take is not an instance of the model, it's an instance of Update<Model>.

I changed all updates to payload so they are all aligned 👍

Misc

Rename list_teams_sources() to list_team_sources() for consistency.

This was already taken care of in a later commit 🙌

Remove the "obj.status_code" useless lines (grep -n "^ *obj\.status_code$" client.py to find them)

grep -n "^ *obj\.status_code$" client.py does not return anything anymore 👍

models.py

@post_load methods

  • Type-hint for **kwargs must be Any.

I changed kwargs typing to be Any 👍

  • All existing @post_load methods are called make_<something>. Can you use the same naming convention for yours?

I changed all @post_load method to be respect this convention

conftest.py

get_member() is never used, can we remove it?

Indeed, I removed it 👍

Instead of creating fixtures, you can create a test.utils module with plain functions and import them in the tests.

I create the corresponding utils file and updated references for these functions

@GG-Yanne GG-Yanne requested a review from agateau-gg December 18, 2024 15:37
Copy link
Collaborator

@agateau-gg agateau-gg left a comment

Choose a reason for hiding this comment

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

Looks good now! Thanks for this significant addition to the API and for documenting the test setup requirements 👍🏻.

@agateau-gg agateau-gg merged commit a33326f into master Dec 20, 2024
19 checks passed
@agateau-gg agateau-gg deleted the ybensafia/members-teams-endpoints branch December 20, 2024 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants