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

feat(cli): add flag ai removal command #151

Merged
merged 1 commit into from
Aug 2, 2024

Conversation

cstrnt
Copy link
Member

@cstrnt cstrnt commented Jul 29, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new command for removing feature flags, enhancing the management of feature rollouts and A/B testing.
    • Added a sub-command in the CLI to facilitate the removal of flags from the user's codebase.
  • Improvements

    • Implemented a utility function to generate regex patterns for feature flag usage, streamlining the management process.
    • Enhanced CLI functionality with the addition of the globby library for improved file path matching.
  • Bug Fixes

    • New method added to the HTTP service for better handling of feature flag removal requests.

Copy link

vercel bot commented Jul 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
abby-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 30, 2024 10:42am
abby-opensource ❌ Failed (Inspect) Jul 30, 2024 10:42am

Copy link
Contributor

coderabbitai bot commented Jul 29, 2024

Walkthrough

This update enhances feature flag management within the application by introducing a new command for removing feature flags. Users can efficiently clean up unused flags, improving codebase maintenance. The addition includes a utility for generating regex patterns and a new dependency, globby, to streamline file handling. Overall, these changes aim to refine the user experience and simplify feature management processes.

Changes

File Change Summary
.changeset/ninety-countries-jam.md Introduced a command for removing feature flags and a utility function for regex pattern generation.
packages/cli/package.json Added globby dependency to enhance file path matching functionality and updated version.
packages/cli/src/ai.ts Implemented removeFlagInstance to remove feature flags from specified files using globby.
packages/cli/src/http.ts Added getFilesWithFlagsRemoved method to HttpService for server interaction to remove flags.
packages/cli/src/index.ts Implemented a new CLI command remove for flag removal, requiring directory and flag name as arguments.
apps/angular-example/package.json Updated version from 0.0.18 to 0.0.19.
apps/web/package.json Updated version from 0.2.36 to 0.2.37.
packages/angular/package.json Updated version from 2.0.8 to 2.0.9.
packages/core/package.json Updated version from 5.3.0 to 5.3.1.
packages/next/package.json Updated version from 5.1.1 to 5.1.2.
packages/node/package.json Updated version from 5.1.6 to 5.1.7.
packages/react/package.json Updated version from 5.2.0 to 5.2.1.
packages/remix/package.json Updated version from 1.0.2 to 1.0.3.
packages/svelte/package.json Updated version from 2.2.0 to 2.2.1.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant AI
    participant HttpService

    User->>CLI: Executes remove command
    CLI->>AI: removeFlagInstance({flagName, options})
    AI->>AI: Locate files using globby
    AI->>AI: Construct regex for flag
    AI->>HttpService: getFilesWithFlagsRemoved(data)
    HttpService-->>AI: Response
    AI-->>CLI: Result
    CLI-->>User: Display result
Loading

Poem

In the fields where features play,
A rabbit hops the flags away.
With globby paths and regex bright,
We tidy up, all feels just right!
Old flags gone, the code now gleams,
A happy hop, fulfilling dreams! 🐇✨


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
Member Author

cstrnt commented Jul 29, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @cstrnt and the rest of your teammates on Graphite Graphite

Copy link
Contributor

@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

Outside diff range, codebase verification and nitpick comments (4)
packages/core/src/shared/helpers.ts (1)

71-72: Consider adding a comment to explain the purpose of the function.

Adding a comment will help other developers understand the purpose and usage of this function.

+ // Generates a regex pattern to match the usage of a feature flag.
export const getUseFeatureFlagRegex = (flagName: string) =>
  new RegExp(`useFeatureFlag\\s*\\(\\s*['"\`]${flagName}['"\`]\\s*\\)`);
packages/cli/src/http.ts (1)

74-84: Consider adding type annotations for the parameters.

Adding type annotations will improve code readability and maintainability.

static async getFilesWithFlagsRemoved({
  apiKey,
  files,
  flagName,
  apiUrl,
}: {
  apiKey: string;
  files: Array<{ filePath: string; fileContent: string }>;
  flagName: string;
  apiUrl?: string;
}) {
packages/cli/src/index.ts (2)

193-194: Consider adding a description for the arguments.

Adding a description will help users understand the purpose of the arguments.

.argument("<dir>", "The directory to scan for flags")
.argument("<flag>", "The flag name to remove")

205-205: Log the result in a more user-friendly format.

Logging the result in a more user-friendly format will improve the user experience.

console.log("Files updated:", files);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 40055b1 and 5e950f9.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (6)
  • .changeset/ninety-countries-jam.md (1 hunks)
  • packages/cli/package.json (1 hunks)
  • packages/cli/src/ai.ts (1 hunks)
  • packages/cli/src/http.ts (2 hunks)
  • packages/cli/src/index.ts (2 hunks)
  • packages/core/src/shared/helpers.ts (1 hunks)
Additional comments not posted (7)
.changeset/ninety-countries-jam.md (1)

1-6: LGTM!

The changeset metadata is correctly formatted and indicates patch updates for @tryabby/core and @tryabby/cli.

packages/cli/package.json (1)

30-30: LGTM!

The addition of globby with version ^14.0.2 is appropriate for enhancing file handling capabilities.

packages/cli/src/ai.ts (5)

1-6: LGTM!

The import statements are correctly structured and bring in the necessary modules for the removeFlagInstance function.


15-20: LGTM!

The usage of globby to find files with the specified options is appropriate and correctly implemented.


22-22: LGTM!

The regex pattern generation using getUseFeatureFlagRegex is correctly implemented.


41-46: LGTM!

The HTTP service call to getFilesWithFlagsRemoved is correctly implemented.


57-57: LGTM!

The success message logging is correctly implemented.

Comment on lines 111 to 116
throw new Error("Internal server error trying to update files");
} else if (status === 401) {
throw new Error("Invalid API Key");
} else {
console.log(response);
throw new Error("Push failed");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve error handling by providing more specific error messages.

Providing more specific error messages will help in debugging and understanding the cause of the error.

} else if (status === 500) {
  throw new Error("Internal server error trying to update files");
} else if (status === 401) {
  throw new Error("Invalid API Key");
} else {
  console.log(response);
  throw new Error(`Push failed with status ${status}: ${response.statusText}`);
}
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
throw new Error("Internal server error trying to update files");
} else if (status === 401) {
throw new Error("Invalid API Key");
} else {
console.log(response);
throw new Error("Push failed");
}
} else if (status === 500) {
throw new Error("Internal server error trying to update files");
} else if (status === 401) {
throw new Error("Invalid API Key");
} else {
console.log(response);
throw new Error(`Push failed with status ${status}: ${response.statusText}`);
}

Comment on lines +48 to +56
try {
const { mutableConfig, saveMutableConfig } = await loadLocalConfig(
options.configPath
);
mutableConfig.flags = mutableConfig.flags.filter((flag: string) => flag !== options.flagName);
await saveMutableConfig();
} catch (e) {
// fail silently
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle specific exceptions for configuration update.

The local configuration update is correctly implemented, but consider handling specific exceptions to provide more informative error messages.

-  } catch (e) {
-    // fail silently
+  } catch (error) {
+    console.error(`Error updating configuration:`, 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
try {
const { mutableConfig, saveMutableConfig } = await loadLocalConfig(
options.configPath
);
mutableConfig.flags = mutableConfig.flags.filter((flag: string) => flag !== options.flagName);
await saveMutableConfig();
} catch (e) {
// fail silently
}
try {
const { mutableConfig, saveMutableConfig } = await loadLocalConfig(
options.configPath
);
mutableConfig.flags = mutableConfig.flags.filter((flag: string) => flag !== options.flagName);
await saveMutableConfig();
} catch (error) {
console.error(`Error updating configuration:`, error);
}

Comment on lines +24 to +39
const filesToUse = (
await Promise.all(
files.flatMap(async (filePath) => {
const content = await readFile(filePath, "utf-8").then((content) => {
const matches = content.match(regex);
return matches ? content : null;
});
if (!content) return [];

return {
filePath,
fileContent: content,
};
})
)
).flat();
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error handling for file reading.

The file reading and regex matching are correctly implemented, but consider adding error handling for potential file read errors.

-      files.flatMap(async (filePath) => {
+      files.flatMap(async (filePath) => {
+        try {
           const content = await readFile(filePath, "utf-8").then((content) => {
             const matches = content.match(regex);
             return matches ? content : null;
           });
           if (!content) return [];
           return {
             filePath,
             fileContent: content,
           };
+        } catch (error) {
+          console.error(`Error reading file ${filePath}:`, error);
+          return [];
+        }
       })
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
const filesToUse = (
await Promise.all(
files.flatMap(async (filePath) => {
const content = await readFile(filePath, "utf-8").then((content) => {
const matches = content.match(regex);
return matches ? content : null;
});
if (!content) return [];
return {
filePath,
fileContent: content,
};
})
)
).flat();
const filesToUse = (
await Promise.all(
files.flatMap(async (filePath) => {
try {
const content = await readFile(filePath, "utf-8").then((content) => {
const matches = content.match(regex);
return matches ? content : null;
});
if (!content) return [];
return {
filePath,
fileContent: content,
};
} catch (error) {
console.error(`Error reading file ${filePath}:`, error);
return [];
}
})
)
).flat();

@cstrnt cstrnt force-pushed the tim07-29-feat_cli_add_flag_ai_removal_command branch from 5e950f9 to d05cb9a Compare July 30, 2024 10:37
Copy link
Contributor

@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 5e950f9 and 974324c.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (24)
  • apps/angular-example/CHANGELOG.md (1 hunks)
  • apps/angular-example/package.json (1 hunks)
  • apps/web/CHANGELOG.md (1 hunks)
  • apps/web/package.json (1 hunks)
  • packages/angular/CHANGELOG.md (1 hunks)
  • packages/angular/package.json (1 hunks)
  • packages/cli/CHANGELOG.md (1 hunks)
  • packages/cli/package.json (2 hunks)
  • packages/cli/src/ai.ts (1 hunks)
  • packages/cli/src/http.ts (2 hunks)
  • packages/cli/src/index.ts (2 hunks)
  • packages/core/CHANGELOG.md (1 hunks)
  • packages/core/package.json (1 hunks)
  • packages/core/src/shared/helpers.ts (1 hunks)
  • packages/next/CHANGELOG.md (1 hunks)
  • packages/next/package.json (1 hunks)
  • packages/node/CHANGELOG.md (1 hunks)
  • packages/node/package.json (1 hunks)
  • packages/react/CHANGELOG.md (1 hunks)
  • packages/react/package.json (1 hunks)
  • packages/remix/CHANGELOG.md (1 hunks)
  • packages/remix/package.json (1 hunks)
  • packages/svelte/CHANGELOG.md (1 hunks)
  • packages/svelte/package.json (1 hunks)
Files skipped from review due to trivial changes (17)
  • apps/angular-example/CHANGELOG.md
  • apps/angular-example/package.json
  • apps/web/CHANGELOG.md
  • apps/web/package.json
  • packages/angular/CHANGELOG.md
  • packages/angular/package.json
  • packages/core/package.json
  • packages/next/CHANGELOG.md
  • packages/next/package.json
  • packages/node/CHANGELOG.md
  • packages/node/package.json
  • packages/react/CHANGELOG.md
  • packages/react/package.json
  • packages/remix/CHANGELOG.md
  • packages/remix/package.json
  • packages/svelte/CHANGELOG.md
  • packages/svelte/package.json
Files skipped from review as they are similar to previous changes (5)
  • packages/cli/package.json
  • packages/cli/src/ai.ts
  • packages/cli/src/http.ts
  • packages/cli/src/index.ts
  • packages/core/src/shared/helpers.ts
Additional comments not posted (2)
packages/cli/CHANGELOG.md (1)

3-8: Changelog entry looks good.

The new version 1.1.1 and the patch change for adding the feature flag removal command are correctly documented.

packages/core/CHANGELOG.md (1)

3-8: Changelog entry looks good.

The new version 5.3.1 and the patch change for adding the feature flag removal command are correctly documented.

@cstrnt cstrnt merged commit 18e5f96 into main Aug 2, 2024
5 of 6 checks passed
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