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

fix: case-insensitive language comparison #204

Conversation

gauravnadkarni
Copy link
Contributor

@gauravnadkarni gauravnadkarni commented Dec 1, 2024

Made a fix to make language comparisons case-insensitive for excluded language
Added few test cases
#203

Summary by CodeRabbit

Release Notes

  • New Features

    • Improved input validation for query parameters in SVG card generation.
    • Enhanced case-insensitivity for language exclusion across various functionalities.
  • Bug Fixes

    • Resolved issues with inconsistent formatting of excluded languages.
  • Tests

    • Added new test cases for case-insensitive language exclusion in both commit and repository language functions.
    • Updated mock data to include contributions for new languages.

Made a fix to make language comparisons case-insenstitive for excluded language
Added few test cases
Copy link

coderabbitai bot commented Dec 1, 2024

Walkthrough

The pull request introduces modifications to several files related to the handling of language exclusions in API responses. Key changes include enhanced validation for query parameters, improved error handling, and consistent formatting of excluded languages by converting them to lowercase. The updates affect both the logic for generating SVG cards and the underlying data processing functions, ensuring that exclusions are case-insensitive. Additionally, test cases have been updated and expanded to verify these changes, particularly focusing on the new case-insensitive exclusion logic.

Changes

File Path Change Summary
api/cards/most-commit-language.ts Enhanced error handling and validation for exclude parameter; added lowercase conversion for excluded languages.
api/cards/repos-per-language.ts Improved validation for theme, username, and exclude parameters; updated exclusion logic to convert languages to lowercase before processing.
src/app.ts Modified how the exclude array is populated, ensuring all entries are in lowercase; minor formatting fix in comments.
src/github-api/commits-per-language.ts Updated exclusion check in getCommitLanguage function to be case-insensitive by converting language names to lowercase.
src/github-api/repos-per-language.ts Altered exclusion logic in getRepoLanguages function to use lowercase comparison for language names.
tests/github-api/commits-per-language.test.ts Added test case for "Jupyter Notebook" and verified case-insensitive exclusion logic.
tests/github-api/repos-per-language.test.ts Introduced a test case for case-insensitive language exclusion with whitespace handling.

Possibly related PRs

🐰 In the land of code, where languages play,
Exclusions now dance in a case-insensitive way.
With lowercase magic, they’re all set to go,
Cards and commits, in a beautiful flow.
So hop along, dear coder, with joy in your heart,
For clarity and order, we've made a fresh start! 🐇✨


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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

🧹 Outside diff range and nitpick comments (4)
api/cards/most-commit-language.ts (1)

24-25: Consider extracting common language exclusion logic.

The language exclusion logic is duplicated across multiple files. Consider extracting this into a shared utility function to maintain consistency and reduce duplication.

Example implementation:

// src/utils/language-utils.ts
export const processExcludedLanguage = (language: string): string => {
  const translatedLanguage = translateLanguage(language);
  return translatedLanguage.toLowerCase();
};

Then use it in both files:

excludeArr.push(processExcludedLanguage(val));
tests/github-api/commits-per-language.test.ts (1)

44-54: Consider consistent indentation in mock data

The indentation of the new mock data entry appears to be slightly inconsistent with the surrounding code.

-                    {
-                        repository: {
-                            primaryLanguage: {
-                                name: 'Jupyter Notebook',
-                                color: '#f18e33'
-                            }
-                        },
-                        contributions: {
-                            totalCount: 75
-                        }
-                    },
+                {
+                    repository: {
+                        primaryLanguage: {
+                            name: 'Jupyter Notebook',
+                            color: '#f18e33'
+                        }
+                    },
+                    contributions: {
+                        totalCount: 75
+                    }
+                },
tests/github-api/repos-per-language.test.ts (1)

138-138: Add space after comma in array for better readability

Minor style improvement suggestion.

-const repoData = await getRepoLanguages('vn7n24fzkq', ['rust','jupyter notebook']);
+const repoData = await getRepoLanguages('vn7n24fzkq', ['rust', 'jupyter notebook']);
src/app.ts (1)

Line range hint 42-45: Consider applying case-insensitive handling to the action entry point.

For consistency, consider applying the same case-insensitive handling to the exclude array in the GitHub Action entry point. Currently, only the CLI entry point handles case sensitivity.

    const exclude = core.getInput('EXCLUDE', {required: false}).split(',');
+   const normalizedExclude = exclude.map(lang => 
+     translateLanguage(lang).toLowerCase()
+   );
    core.info(`Excluded languages: ${exclude}`);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2eac6ef and eadf9b3.

📒 Files selected for processing (7)
  • api/cards/most-commit-language.ts (1 hunks)
  • api/cards/repos-per-language.ts (1 hunks)
  • src/app.ts (2 hunks)
  • src/github-api/commits-per-language.ts (1 hunks)
  • src/github-api/repos-per-language.ts (1 hunks)
  • tests/github-api/commits-per-language.test.ts (3 hunks)
  • tests/github-api/repos-per-language.test.ts (2 hunks)
🔇 Additional comments (6)
api/cards/repos-per-language.ts (1)

24-25: LGTM! Verify empty string handling.

The implementation correctly implements case-insensitive language comparison by translating first and then converting to lowercase. This order is important as some translations might involve case-sensitive mappings.

Let's verify the handling of empty strings:

✅ Verification successful

Empty strings are handled safely

The implementation of translateLanguage safely handles empty strings by falling back to the default case which capitalizes the first character. For empty strings, this will simply return an empty string since charAt(0) and slice(1) on empty strings return empty strings.

The code is robust and handles all edge cases appropriately:

  • If language exists in dictionary -> returns mapped value
  • If language doesn't exist (including empty string) -> capitalizes first letter and returns
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how translateLanguage handles empty strings
ast-grep --pattern 'translateLanguage($empty)' | rg -A 5 'translateLanguage'

Length of output: 76


Script:

#!/bin/bash
# Let's first find the translateLanguage function definition
ast-grep --pattern 'function translateLanguage($_) {
  $$$
}'

# Also search for any direct usage of translateLanguage
rg "translateLanguage" -A 3 -B 3

Length of output: 69898


Script:

#!/bin/bash
# Let's find the translateLanguage function implementation
fd "translator.ts" --exec cat {} \;

Length of output: 7844

src/github-api/repos-per-language.ts (1)

88-88: LGTM! Verify consistency across similar functions.

The implementation correctly performs case-insensitive comparison using toLowerCase().

Let's verify the consistency of this approach across similar functions:

✅ Verification successful

Let me try a more focused search to find language comparison patterns in the codebase.


Let me try another search to find language exclusion patterns more effectively:


Case-insensitive language comparison is consistently implemented across the codebase

The search results confirm that case-insensitive language comparison using toLowerCase() is consistently implemented throughout the codebase:

  • In API endpoints (api/cards/), language names are converted to lowercase when building the exclude array
  • In GitHub API handlers (src/github-api/), language comparisons use toLowerCase() when checking against exclude list
  • In the main app (src/app.ts), languages are also converted to lowercase when processing exclusions

The implementation in repos-per-language.ts follows this established pattern correctly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for similar language comparison patterns
# Look for other language comparison implementations
ast-grep --pattern 'includes($lang)' | rg -B 5 -A 5 'includes'

# Look for other toLowerCase usage with language comparisons
rg -B 5 -A 5 'toLowerCase.*language'

Length of output: 65638


Script:

#!/bin/bash
# Look for language name comparisons specifically
rg -B 3 -A 3 "\.toLowerCase.*lang|lang.*\.toLowerCase"

# Look for language exclusion patterns
rg -B 3 -A 3 "exclude.*lang|lang.*exclude"

Length of output: 66837


Script:

#!/bin/bash
# Search for language exclusion patterns in source files
rg -g '*.ts' -B 3 -A 3 'exclude.*language|language.*exclude'

# Search for toLowerCase usage with excludes
rg -g '*.ts' -B 3 -A 3 'exclude.*toLowerCase|toLowerCase.*exclude'

Length of output: 3072

src/github-api/commits-per-language.ts (1)

86-86: LGTM: Case-insensitive language comparison implemented correctly

The conversion of language name to lowercase before checking exclusions ensures consistent case-insensitive matching, which aligns with the PR objectives.

tests/github-api/commits-per-language.test.ts (1)

102-112: LGTM: Comprehensive test coverage for case-insensitive exclusion

The test case effectively validates the case-insensitive language comparison functionality by checking the exclusion of "jupyter notebook" against "Jupyter Notebook".

tests/github-api/repos-per-language.test.ts (1)

135-145: LGTM: Well-structured test for case-insensitive language exclusion

The test case effectively validates both case-insensitive comparison and proper handling of language names containing whitespace.

src/app.ts (1)

147-148: LGTM! Case-insensitive language comparison implemented correctly.

The changes effectively implement case-insensitive language comparison by converting translated languages to lowercase before adding them to the exclude array. This ensures consistent language matching regardless of the input case.

@vn7n24fzkq
Copy link
Owner

Awesome!
Everything looks good.
Thanks for your effort.

@vn7n24fzkq vn7n24fzkq merged commit 88bc12b into vn7n24fzkq:main Dec 3, 2024
3 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.

2 participants