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

Retrieve mandatory email address from Github #129

Closed
wants to merge 2 commits into from

Conversation

Zoly
Copy link
Contributor

@Zoly Zoly commented Jul 22, 2024

The /user API returns only the data the user explicitly set as public and null for those he didn't.

If the user did not set the email address public (me for example), the email address being mandatory for the process, the authentication fails returning an error message.

By using the /user/emails API in conjunction, it is possible to retrieve all the email addresses the user set in Github, regardless if they are set public or not, and select one of those (ex: primary one), for the login process to complete successfully.

Summary by CodeRabbit

  • New Features

    • Enhanced functionality for retrieving user email addresses from the GitHub API, ensuring reliable integration of email information into user profiles.
    • Introduced a method to fetch user emails using an authentication token.
  • Improvements

    • Mandatory email requirement for user information retrieval, with fallback to the primary email from fetched addresses.

Zoly added 2 commits July 22, 2024 06:54
The /user API returns only the data the user explicitly set as public and null for those he didn't.

If the user did not set the email address public (me for example), the email address being mandatory for the process, the authentication fails returning an error message.

By using the /user/emails API in conjunction, it is possible to retrieve all the email addresses the user set in Github, regardless if they are set public or not, and select one of those (ex: primary one), for the login process to complete successfully.
…-Github

The /user API returns only the data the user explicitly set as public and null for those he didn't.

If the user did not set the email address public (me for example), the email address being mandatory for the process, the authentication fails returning an error message.

By using the /user/emails API in conjunction, it is possible to retrieve all the email addresses the user set in Github, regardless if they are set public or not, and select one of those (ex: primary one), for the login process to complete successfully.
Copy link

coderabbitai bot commented Jul 22, 2024

Walkthrough

The updates to the GithubOAuth class enhance the retrieval of user email information from the GitHub API. A new method for fetching user emails is introduced, ensuring that obtaining a user's primary email is now a standard part of user info retrieval. This change improves the reliability of user email data integration, allowing for better handling of user interactions with the GitHub API.

Changes

Files Change Summary
src/Libraries/GithubOAuth.php Introduced a new constant for the user emails API URL and implemented a method to fetch user emails. Updated user info method to ensure an email is mandatory, integrating the email retrieval process.

Poem

🐇 In the code where rabbits play,
New emails hop in every day!
From GitHub’s fields, they find their way,
To brighten up our user’s stay.
With every fetch, our joy does sway! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6d42536 and 9274810.

Files selected for processing (1)
  • src/Libraries/GithubOAuth.php (2 hunks)
Additional comments not posted (3)
src/Libraries/GithubOAuth.php (3)

107-124: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to fetchUserEmailsWithToken are correctly handled.

Verification successful

LGTM! But verify the function usage in the codebase.

The code changes are approved.

The function fetchUserEmailsWithToken is used correctly within the same file and is properly handled by the getUserPrimaryEmail method. No further issues were found.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `fetchUserEmailsWithToken` are correctly handled.

# Test: Search for the function usage. Expect: Proper handling of the function calls.
rg --type php -A 5 $'fetchUserEmailsWithToken'

Length of output: 773


Script:

#!/bin/bash
# Description: Verify all function calls to `getUserPrimaryEmail` are correctly handled.

# Test: Search for the function usage. Expect: Proper handling of the function calls.
rg --type php -A 5 $'getUserPrimaryEmail'

Length of output: 963


129-135: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to getUserPrimaryEmail are correctly handled.

Verification successful

Verify the implementation of $this->fetchUserEmailsWithToken() and the $userInfo object.

The function getUserPrimaryEmail is used to assign the primary email address to $userInfo->email. To ensure proper handling, verify the implementation of $this->fetchUserEmailsWithToken() and the $userInfo object.


Verification successful: Proper handling of getUserPrimaryEmail function usage.

The function getUserPrimaryEmail is correctly handled in the codebase. The implementation of fetchUserEmailsWithToken and the handling of the $userInfo object are appropriate and ensure the correct functionality.

  • The fetchUserEmailsWithToken function is implemented to retrieve user emails from an API.
  • The $userInfo object is properly utilized to handle user information, including setting the primary email.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `getUserPrimaryEmail` are correctly handled.

# Test: Search for the function usage. Expect: Proper handling of the function calls.
rg --type php -A 5 $'getUserPrimaryEmail'

Length of output: 963


Script:

#!/bin/bash
# Description: Verify the implementation of fetchUserEmailsWithToken and the userInfo object.

# Test: Search for the implementation of fetchUserEmailsWithToken. Expect: Proper implementation.
rg --type php -A 5 $'fetchUserEmailsWithToken'

# Test: Search for the definition and usage of $userInfo. Expect: Proper handling of the object.
rg --type php -A 5 $'userInfo'

Length of output: 9906


94-101: LGTM! But verify the function usage in the codebase.

The code changes are approved.

However, ensure that all function calls to fetchUserInfoWithToken are correctly handled.

Verification successful

To ensure that the function fetchUserInfoWithToken is correctly handled across the codebase, we need to verify its usage in the AbstractOAuth.php class and how it is overridden in GithubOAuth.php and GoogleOAuth.php.


To ensure the changes in GithubOAuth.php are correctly handled, we need to retrieve the full method in AbstractOAuth.php that calls fetchUserInfoWithToken.


To retrieve the full method in AbstractOAuth.php that calls fetchUserInfoWithToken, we will use rg to search for the method definition and its surrounding context.


To ensure that the changes in GithubOAuth.php are correctly integrated, we need to confirm that the getUserInfo method in AbstractOAuth.php is used correctly in the codebase.


Function usage is correctly handled.

The changes in GithubOAuth.php ensure that a valid email address is always retrieved, which is critical for the logic in OAuthController.php. This confirms that the changes are correctly integrated and handled in the codebase.

  • OAuthController.php: The getUserInfo method is used to retrieve user information, which includes the mandatory email address.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `fetchUserInfoWithToken` are correctly handled.

# Test: Search for the function usage. Expect: Proper handling of the function calls.
rg --type php -A 5 $'fetchUserInfoWithToken'

Length of output: 2158


Script:

#!/bin/bash
# Verify the context in AbstractOAuth.php where fetchUserInfoWithToken is called
rg --type php -A 10 $'fetchUserInfoWithToken' src/Libraries/Basic/AbstractOAuth.php

# Check how fetchUserInfoWithToken is overridden in GithubOAuth.php and GoogleOAuth.php
rg --type php -A 10 $'fetchUserInfoWithToken' src/Libraries/GithubOAuth.php
rg --type php -A 10 $'fetchUserInfoWithToken' src/Libraries/GoogleOAuth.php

Length of output: 1743


Script:

#!/bin/bash
# Retrieve the full method in AbstractOAuth.php that calls fetchUserInfoWithToken
ast-grep --lang php --pattern $'abstract class AbstractOAuth {
  $$$
  protected function $_($_) {
    $$$
    return $this->fetchUserInfoWithToken();
    $$$
  }
  $$$
}' src/Libraries/Basic/AbstractOAuth.php

Length of output: 317


Script:

#!/bin/bash
# Retrieve the full method in AbstractOAuth.php that calls fetchUserInfoWithToken
rg --type php -A 20 $'fetchUserInfoWithToken' src/Libraries/Basic/AbstractOAuth.php

Length of output: 760


Script:

#!/bin/bash
# Verify the usage of getUserInfo method in the codebase
rg --type php -A 10 $'getUserInfo' src/

Length of output: 1590

@Zoly Zoly closed this Jul 22, 2024
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.

1 participant