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

Eslint fixes, dotenv and growthbook #95

Merged
merged 6 commits into from
Aug 27, 2024

Conversation

rohankeskarwednesday
Copy link
Collaborator

@rohankeskarwednesday rohankeskarwednesday commented Aug 23, 2024

Ticket Link


Related Links


Description


Steps to Reproduce / Test


GIF's


Summary by CodeRabbit

  • New Features
    • Introduced environment variables for external APIs, enhancing data retrieval capabilities (JSON_PLACEHOLDER_API and SIMPSONS_API).
    • Integrated Sentry for improved error tracking and performance monitoring.
  • Improvements
    • Enhanced configuration management by using environment variables for API URLs, promoting flexibility across different environments.

Copy link

coderabbitai bot commented Aug 23, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes involve the addition of environment variables for two external APIs in the .env file, the integration of Sentry for error tracking in App.js, and updates to various configuration files to manage API URLs dynamically. These modifications enhance the application's ability to interact with external services and improve error monitoring capabilities.

Changes

Files Change Summary
.env Added environment variables JSON_PLACEHOLDER_API and SIMPSONS_API with respective URLs.
App.js Integrated Sentry for error tracking.
.eslintrc.js Removed trailing commas and spaces; updated complexity rule from 10 to 2.
app/config/index.dev.js, app/config/index.js, app/config/index.production.js
app/utils/growthbook.js Introduced functions for managing GrowthBook feature flags.
babel.config.js Added plugin configuration for handling environment variables using react-native-dotenv.
package.json Added dependencies: @growthbook/growthbook and react-native-dotenv.
.gitignore Introduced entries for ignoring coverage and .env.local.
android/app/build.gradle, ios/reactnativetemplatews.xcodeproj/project.pbxproj, metro.config.js
android/sentry.properties, ios/sentry.properties

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant Config
    participant Sentry

    App->>Config: Initialize configuration
    Config->>App: Load environment variables
    App->>Sentry: Initialize error tracking
Loading

🐰 In the code we hop and play,
New APIs come out to stay.
With Sentry's watchful gaze,
Errors fade in joyful rays!
Environment variables lead the way,
Making coding a brighter day! 🌼


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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3769d60 and 2855013.

Files ignored due to path filters (2)
  • ios/Podfile.lock is excluded by !**/*.lock
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (8)
  • .env (1 hunks)
  • .eslintrc.js (4 hunks)
  • app/config/index.dev.js (1 hunks)
  • app/config/index.js (1 hunks)
  • app/config/index.production.js (1 hunks)
  • app/utils/growthbook.js (1 hunks)
  • babel.config.js (1 hunks)
  • package.json (2 hunks)
Files skipped from review due to trivial changes (1)
  • .env
Additional comments not posted (9)
app/config/index.js (1)

1-4: LGTM! Verify the environment variable usage.

The change to use the SIMPSONS_API environment variable for API_URL enhances configuration flexibility.

Ensure that the SIMPSONS_API variable is correctly set in the environment and used throughout the codebase.

Run the following script to verify the usage of the SIMPSONS_API variable:

Verification successful

Environment Variable Usage Verified

The SIMPSONS_API environment variable is correctly set and utilized in the codebase through Config.API_URL, specifically in the app/utils/apiUtils.js file for API client creation.

  • app/utils/apiUtils.js: Utilizes Config.API_URL in createApiClientWithTransForm.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `SIMPSONS_API` environment variable.

# Test: Search for the usage of `SIMPSONS_API`. Expect: Occurrences in configuration and usage files.
rg --type js 'SIMPSONS_API'

Length of output: 128


Script:

#!/bin/bash
# Description: Verify the usage of the `Config.API_URL` to ensure `SIMPSONS_API` is utilized in the codebase.

# Test: Search for the usage of `Config.API_URL`. Expect: Occurrences in files where API calls are made.
rg --type js 'Config\.API_URL'

Length of output: 199

app/config/index.dev.js (1)

1-4: LGTM! Verify the environment variable usage.

The change to use the JSON_PLACEHOLDER_API environment variable for API_URL enhances configuration flexibility.

Ensure that the JSON_PLACEHOLDER_API variable is correctly set in the environment and used throughout the codebase.

Run the following script to verify the usage of the JSON_PLACEHOLDER_API variable:

Verification successful

Environment Variable Usage Verified

The JSON_PLACEHOLDER_API environment variable is correctly set in the .env file and is used in both development and production configuration files. No further issues are found.

  • .env: JSON_PLACEHOLDER_API="https://jsonplaceholder.typicode.com"
  • app/config/index.dev.js: Utilizes JSON_PLACEHOLDER_API.
  • app/config/index.production.js: Utilizes JSON_PLACEHOLDER_API.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `JSON_PLACEHOLDER_API` environment variable.

# Test: Search for the usage of `JSON_PLACEHOLDER_API`. Expect: Occurrences in configuration and usage files.
rg --type js 'JSON_PLACEHOLDER_API'

Length of output: 323


Script:

#!/bin/bash
# Description: Search for the definition or assignment of `JSON_PLACEHOLDER_API` in environment configuration files.

# Test: Look for occurrences of `JSON_PLACEHOLDER_API` in common environment configuration files.
rg 'JSON_PLACEHOLDER_API' --glob '*.env' --glob '*.sh' --glob '*.bash' --glob '*.zsh'

Length of output: 150

app/config/index.production.js (1)

1-4: LGTM! Verify the environment variable usage.

The change to use the JSON_PLACEHOLDER_API environment variable for API_URL enhances configuration flexibility.

Ensure that the JSON_PLACEHOLDER_API variable is correctly set in the environment and used throughout the codebase.

Run the following script to verify the usage of the JSON_PLACEHOLDER_API variable:

babel.config.js (2)

36-45: Verify handling of undefined environment variables.

The configuration allows undefined environment variables (allowUndefined: true). Ensure that your codebase handles cases where these variables might be undefined to prevent potential runtime errors.


36-45: LGTM!

The addition of the react-native-dotenv plugin is correctly configured for managing environment variables.

app/utils/growthbook.js (1)

1-64: LGTM!

The utility functions for GrowthBook integration are well-structured and make good use of environment variables.

.eslintrc.js (1)

122-122: Stricter complexity rule applied.

The complexity threshold has been reduced from 10 to 2, which will enforce simpler code structures. Be prepared to refactor existing code to comply with this stricter rule.

package.json (2)

41-41: Verify the integration of @growthbook/growthbook.

The addition of @growthbook/growthbook aligns with the PR objectives for feature flagging and experimentation.

Ensure that the package is correctly configured and used within the project to leverage its capabilities effectively.


141-141: Verify the integration of react-native-dotenv.

The addition of react-native-dotenv aligns with the PR objectives for environment variable management.

Ensure that the package is correctly configured and used within the project to manage environment variables effectively.

Comment on lines +41 to +48
export async function getGrowthBookFeaturesData(name, email) {
try {
const growthBook = getGrowthBookClient(email);
await growthBook.loadFeatures();
return growthBook.getFeatureValue(name);
} catch (error) {
return new Error(error);
}
Copy link

@coderabbitai coderabbitai bot Aug 23, 2024

Choose a reason for hiding this comment

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

Improve error handling in getGrowthBookFeaturesData.

Instead of returning an Error object, consider throwing the error to maintain consistency in error handling practices.

Apply this diff to improve error handling:

-    return new Error(error);
+    throw error;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function getGrowthBookFeaturesData(name, email) {
try {
const growthBook = getGrowthBookClient(email);
await growthBook.loadFeatures();
return growthBook.getFeatureValue(name);
} catch (error) {
return new Error(error);
}
export async function getGrowthBookFeaturesData(name, email) {
try {
const growthBook = getGrowthBookClient(email);
await growthBook.loadFeatures();
return growthBook.getFeatureValue(name);
} catch (error) {
throw error;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

can you please check this once

Copy link

Choose a reason for hiding this comment

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

@shamoilattaar-wednesday, I've reviewed the suggestion to throw the error instead of returning a new Error object in the getGrowthBookFeaturesData function. This change aligns with standard error handling practices in JavaScript, allowing errors to propagate up the call stack for proper handling. It looks like a valid improvement. Let me know if you need further assistance!

Comment on lines +56 to +63
export async function getGrowthBookFeatureFlag(name, email) {
try {
const growthBook = getGrowthBookClient(email);
await growthBook.loadFeatures();
return growthBook.isOn(name);
} catch (error) {
return new Error(error);
}
Copy link

Choose a reason for hiding this comment

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

Improve error handling in getGrowthBookFeatureFlag.

Instead of returning an Error object, consider throwing the error to maintain consistency in error handling practices.

Apply this diff to improve error handling:

-    return new Error(error);
+    throw error;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function getGrowthBookFeatureFlag(name, email) {
try {
const growthBook = getGrowthBookClient(email);
await growthBook.loadFeatures();
return growthBook.isOn(name);
} catch (error) {
return new Error(error);
}
export async function getGrowthBookFeatureFlag(name, email) {
try {
const growthBook = getGrowthBookClient(email);
await growthBook.loadFeatures();
return growthBook.isOn(name);
} catch (error) {
throw error;
}

@rohankeskarwednesday rohankeskarwednesday changed the base branch from master to dev August 23, 2024 09:52
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 2855013 and e451c07.

Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (1)
  • package.json (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package.json

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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e451c07 and ec00ffb.

Files selected for processing (8)
  • .gitignore (1 hunks)
  • App.js (1 hunks)
  • android/app/build.gradle (2 hunks)
  • android/sentry.properties (1 hunks)
  • app.json (1 hunks)
  • ios/reactnativetemplatews.xcodeproj/project.pbxproj (3 hunks)
  • ios/sentry.properties (1 hunks)
  • metro.config.js (1 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Additional comments not posted (8)
metro.config.js (2)

2-2: LGTM!

The import statement correctly imports the required function from the specified package.

The code changes are approved.


5-5: LGTM!

The export statement correctly uses the new function to configure the Metro bundler.

The code changes are approved.

App.js (2)

7-7: LGTM!

The import statement for Sentry is correct.

The code changes are approved.


Line range hint 14-23: LGTM!

The control flow is correct and ensures that the root component is registered correctly.

The code changes are approved.

app.json (1)

25-35: LGTM!

The integration of the @sentry/react-native/expo plugin is correct and aligns with the Sentry documentation for React Native with Expo.

The code changes are approved.

android/app/build.gradle (1)

80-80: LGTM!

The integration of the Sentry Gradle script is correct and aligns with the Sentry documentation for React Native with Android.

The code changes are approved.

ios/reactnativetemplatews.xcodeproj/project.pbxproj (2)

223-223: Verify the correctness of the script paths and integration.

Ensure that the paths to the Sentry upload script and the React Native Xcode script are correct and that the integration does not introduce any issues.

Run the following script to verify the existence of the scripts:


310-323: Verify the correctness of the script path and integration.

Ensure that the path to the Sentry upload script is correct and that the integration does not introduce any issues.

Run the following script to verify the existence of the Sentry upload script:

Comment on lines +1 to +7

auth.token=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

defaults.org=wednesday-solutions-5p
defaults.project=react-native

defaults.url=https://sentry.io/
Copy link

Choose a reason for hiding this comment

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

Avoid hardcoding sensitive information.

The auth token is hardcoded, which may pose a security risk. Consider using environment variables to manage sensitive information securely.

Apply this diff to replace the hardcoded auth token with an environment variable:

-auth.token=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
+auth.token=${SENTRY_AUTH_TOKEN}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
auth.token=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
defaults.org=wednesday-solutions-5p
defaults.project=react-native
defaults.url=https://sentry.io/
auth.token=${SENTRY_AUTH_TOKEN}
defaults.org=wednesday-solutions-5p
defaults.project=react-native
defaults.url=https://sentry.io/

Comment on lines +1 to +7

auth.token=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

defaults.org=wednesday-solutions-5p
defaults.project=react-native

defaults.url=https://sentry.io/
Copy link

Choose a reason for hiding this comment

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

Avoid hardcoding sensitive information.

The auth token is hardcoded, which may pose a security risk. Consider using environment variables to manage sensitive information securely.

Apply this diff to replace the hardcoded auth token with an environment variable:

-auth.token=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
+auth.token=${SENTRY_AUTH_TOKEN}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
auth.token=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
defaults.org=wednesday-solutions-5p
defaults.project=react-native
defaults.url=https://sentry.io/
auth.token=${SENTRY_AUTH_TOKEN}
defaults.org=wednesday-solutions-5p
defaults.project=react-native
defaults.url=https://sentry.io/

App.js Outdated
Comment on lines 9 to 12
Sentry.init({
dsn:
'https://0fbf25b4bfb443b7ae58aa4baf34460e@o4505374929584128.ingest.us.sentry.io/4505374931812352'
});
Copy link

Choose a reason for hiding this comment

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

Use environment variables for DSN.

Hardcoding the DSN is not a best practice. It should be stored in environment variables for better security and maintainability.

Apply this diff to use environment variables for the DSN:

-Sentry.init({
-  dsn:
-    'https://0fbf25b4bfb443b7ae58aa4baf34460e@o4505374929584128.ingest.us.sentry.io/4505374931812352'
-});
+import { SENTRY_DSN } from '@env';
+
+Sentry.init({
+  dsn: SENTRY_DSN
+});
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Sentry.init({
dsn:
'https://0fbf25b4bfb443b7ae58aa4baf34460e@o4505374929584128.ingest.us.sentry.io/4505374931812352'
});
import { SENTRY_DSN } from '@env';
Sentry.init({
dsn: SENTRY_DSN
});

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.

2 participants