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

Issue 178 healy: Upsert user email to database #336

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

BigOleHealz
Copy link
Collaborator

@BigOleHealz BigOleHealz commented Oct 22, 2024

What does this PR do?

Makes API request to github API based on username to get email. If email is received, it upserts to users table on installation and updates on create_user_request

PR checklist

Test Cases

Here is the list of test cases:

  • under line 87 in gitauto_handler.py, set the email equal to something else. Then run create create_user_request. Your email address should be updated in the Users table of supabase
  • under line 42 in webhook_handler.py, set the email equal to something else. Then run create create_installation. Your email address should be updated in the Users table of supabase

Evidence

Here is the list of Loom video URL(s):

Environment Variables Setting

Here is the list of configurations and screenshots where we have changes other than code:

  • GitHub Actions
  • OpenAI Console
  • Stripe Admin Console
  • Stripe Webhook
  • Supabase Admin Console
  • Supabase Database
  • AWS Lambda Console
  • Vercel Hosting Console
  • Sentry Console

Summary by Sourcery

Fetch user email from GitHub API and update the users table in the database during installation and user request creation. Add tests to ensure correct email handling.

New Features:

  • Implement fetching of user email from GitHub API based on username.

Enhancements:

  • Update user email in the database during installation and user request creation if it differs from the stored email.

Tests:

  • Add tests to verify email handling during user request creation and installation processes.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @BigOleHealz - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider the privacy implications of storing user emails. It may be worth implementing an opt-in mechanism for email storage, even for public emails.
  • Enhance error handling throughout the new code, particularly in network requests and API interactions. This will improve the robustness of the feature.
  • Consider a general code review for optimization opportunities, especially in database operations and function structure. This could improve performance and maintainability.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟡 Testing: 3 issues found
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

services/supabase/gitauto_manager.py Outdated Show resolved Hide resolved
services/github/github_manager.py Outdated Show resolved Hide resolved
@@ -47,12 +48,14 @@ def test_create_and_update_user_request_works() -> None:
owner_id=OWNER_ID,
user_id=USER_ID,
user_name=USER_NAME,
email=EMAIL,
Copy link

Choose a reason for hiding this comment

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

suggestion (testing): Insufficient test coverage for email handling in create_user

The create_user function now includes an email parameter, but the test doesn't verify if the email is correctly stored in the users table. Consider adding assertions to check this new functionality.

        email=EMAIL,

    # Assert email is correctly stored
    assert created_user["email"] == EMAIL

Copy link
Collaborator

Choose a reason for hiding this comment

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

@BigOleHealz Can you do this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need to talk with you about this. I understand the idea, but there is no created_user variable in this function, file, or in the entire repo

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I need to talk with you about this one... i'm not sure exactly what its asking. I understand the idea, there is no created_user variable

tests/services/supabase/test_users_manager.py Show resolved Hide resolved
services/supabase/gitauto_manager.py Show resolved Hide resolved
services/supabase/gitauto_manager.py Outdated Show resolved Hide resolved
services/gitauto_handler.py Outdated Show resolved Hide resolved
Comment on lines 158 to 165
if not str(email).lower().endswith("@users.noreply.github.com"):
response: APIResponse = self.client.table("users").select("email").eq("user_id", user_id).execute()

if response.data and len(response.data[0]) > 0:
if email != response.data[0].get('email'):
self.client.table("users").update(
json={"email": email}
).eq("user_id", user_id).execute()
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Remove unnecessary casts to int, str, float or bool (remove-unnecessary-cast)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it isnt unnecessary. if email is None, casting it to lowercase will through an error

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not good because if an error happen, users can not get the output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok so do you want me to remove the cast to string or surround it with a try-catch block?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok let's talk about this. it's using the @handle_exceptions(default_return_value=None, raise_on_error=True) decorator

@gitauto-ai gitauto-ai bot added the gitauto label Oct 23, 2024
@hiroshinishio hiroshinishio changed the title Issue 178 healy Issue 178 healy: Upsert user email to database Oct 24, 2024
@gitautoai gitautoai deleted a comment from sourcery-ai bot Oct 24, 2024
services/github/github_manager.py Outdated Show resolved Hide resolved
services/github/github_manager.py Outdated Show resolved Hide resolved
services/github/github_manager.py Outdated Show resolved Hide resolved
services/github/github_manager.py Outdated Show resolved Hide resolved
services/github/github_manager.py Outdated Show resolved Hide resolved
services/supabase/users_manager.py Show resolved Hide resolved
tests/services/supabase/test_gitauto_manager.py Outdated Show resolved Hide resolved
@@ -47,12 +48,14 @@ def test_create_and_update_user_request_works() -> None:
owner_id=OWNER_ID,
user_id=USER_ID,
user_name=USER_NAME,
email=EMAIL,
Copy link
Collaborator

Choose a reason for hiding this comment

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

@BigOleHealz Can you do this?

@@ -14,6 +14,7 @@
INSTALLATION_ID,
UNIQUE_ISSUE_ID,
NEW_INSTALLATION_ID,
EMAIL,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think EMAIL should cover all patterns we discussed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure what you mean. you want me to create and test multiple emails?

Copy link
Collaborator

@hiroshinishio hiroshinishio left a comment

Choose a reason for hiding this comment

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

Also update the branch too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants