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

Lookup multiple args #186

Merged
merged 6 commits into from
Nov 23, 2024
Merged

Lookup multiple args #186

merged 6 commits into from
Nov 23, 2024

Conversation

rudeh1253
Copy link
Contributor

@rudeh1253 rudeh1253 commented Nov 23, 2024

Issue Number

Fixes #173

Description

lookup command now accepts multiple arguments

  • Success case
$ deno task run lookup @[email protected] @[email protected]
2024-11-23.161157.1.mp4

Exit code:
스크린샷 2024-11-23 161340

  • Failure case
$ deno task run lookup @[email protected] @[email protected]

There is a typo: @[email protected]

2024-11-23.161304.1.mp4

Exit code:
스크린샷 2024-11-23 161322

It is possible to specify the separator to separate objects output

  • Default
    스크린샷 2024-11-23 161440

  • Specifying separator
    스크린샷 2024-11-23 161411

Then:
스크린샷 2024-11-23 161418

Why?

  • It is more comfortable if it is possible to fetch multiple host information at once.

Summary by CodeRabbit

Release Notes for Fedify Version 1.3.0

  • New Features

    • Enhanced command-line interface to accept multiple URLs for lookups, improving user flexibility.
    • Added support for OpenTelemetry for better tracing capabilities.
    • Introduced user agent handling in HTTP requests for improved request identification.
  • Improvements

    • Improved key caching to reduce unnecessary fetch attempts.
    • Enhanced message queue configuration options for incoming and outgoing activities.
  • Deprecations

    • Deprecated the fetchDocumentLoader() function in favor of new document loading mechanisms.

These updates significantly enhance the functionality and configurability of Fedify.

Previously, for lookup cli command, it is possible to set only a single
argument for looking up. Now, it is possible to set multiple arguments.

Related to: dahlia#173
Copy link

coderabbitai bot commented Nov 23, 2024

Walkthrough

The changes in this pull request introduce several updates across multiple files. Notably, two new OpenTelemetry imports are added to cli/import_map.g.json. The cli/lookup.ts file is enhanced to support multiple URL lookups with improved error handling and user feedback. Additionally, the CHANGES.md file outlines significant updates in Fedify version 1.3.0, including enhancements to message queue configuration, user-agent handling, key caching, router functionality, and command-line interface improvements.

Changes

File Path Change Summary
cli/import_map.g.json Added imports for OpenTelemetry: "@opentelemetry/api": "npm:@opentelemetry/api@^1.9.0" and "@opentelemetry/semantic-conventions": "npm:@opentelemetry/semantic-conventions@^1.27.0".
cli/lookup.ts Updated method signature to accept multiple URLs. Added -s, --separator <separator:string> option for output. Refactored lookup handling with improved error management and user feedback.
CHANGES.md Documented updates for Fedify v1.3.0, including message queue configuration, user-agent header in HTTP requests, key caching improvements, router enhancements, OpenTelemetry support, CLI updates, and deprecations.
src/user_agent.ts Updated method signature: def getUserAgent()def getUserAgent(): string.
src/federation.ts Added interface: interface FederationQueueOptions.
src/document_loader.ts Added interface: interface GetAuthenticatedDocumentLoaderOptions and updated method signature for getAuthenticatedDocumentLoader().
src/actor.ts Added interface: interface GetActorHandleOptions.
src/webfinger.ts Added interface: interface LookupWebFingerOptions.
src/key_cache.ts Added interfaces: interface FetchKeyOptions, interface FetchKeyResult, and updated method signatures for KeyCache.get() and KeyCache.set().
src/router.ts Added interface: interface RouterRouteResult and updated method signature for Router.route().

Poem

🐇 In the meadow, changes bloom,
New imports chase away the gloom.
Lookups now can take their flight,
With multiple URLs in sight!
Fedify grows, a leap so grand,
A rabbit's cheer across the land! 🌼

Warning

Rate limit exceeded

@rudeh1253 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 7 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3146e71 and 015d137.


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

🧹 Outside diff range and nitpick comments (2)
cli/lookup.ts (2)

35-39: Fix typo in separator option description

There's a typo in the separator option description: "Speicfy" should be "Specify".

   .option(
     "-s, --separator <separator:string>",
-    "Speicfy the separator between adjacent output object.",
+    "Specify the separator between adjacent output objects.",
     { default: "~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~" },
   )

102-105: Enhance spinner text with current URL

The spinner text should indicate which URL is being processed to provide better feedback.

   const spinnerForEachLookup = ora({
-    text: "Looking up an object...",
+    text: `Looking up object (${i + 1}/${urls.length}): ${url}`,
     discardStdin: false,
   }).start();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between cf3769f and bedd385.

⛔ Files ignored due to path filters (1)
  • cli/npm/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • cli/import_map.g.json (1 hunks)
  • cli/lookup.ts (3 hunks)
  • cli/npm/package.json (1 hunks)
🔇 Additional comments (4)
cli/import_map.g.json (1)

19-20: Verify version compatibility with other dependencies.

The caret ranges (^) in the versions are good for allowing minor updates. However, ensure these versions are compatible with your Node.js/Deno environment and other dependencies.

✅ Verification successful

Dependencies are compatible and no version conflicts detected

The verification shows:

  • Both packages are used consistently with the same version ranges across the codebase (^1.9.0 for api and ^1.27.0 for semantic-conventions)
  • Neither package has any peer dependencies that could cause conflicts
  • The versions are aligned between src/deno.json and cli/import_map.g.json
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential version conflicts

# Search for other OpenTelemetry related dependencies
rg '"@opentelemetry/[^"]+": "npm:@opentelemetry/[^"]+"'

# Check if there are any peer dependencies
curl -s https://registry.npmjs.org/@opentelemetry/api/1.9.0 | jq '.peerDependencies'
curl -s https://registry.npmjs.org/@opentelemetry/semantic-conventions/1.27.0 | jq '.peerDependencies'

Length of output: 633

cli/lookup.ts (3)

96-97: LGTM! Improved user feedback

The spinner text update provides clearer feedback about the initialization status.


148-150: LGTM! Proper cleanup and exit handling

The implementation correctly cleans up resources and sets an appropriate exit code based on the operation's success.


18-18: Verify command behavior with test cases

The implementation appears to meet the PR objectives. Let's verify the behavior with the test cases mentioned in the PR description.

Also applies to: 40-40

✅ Verification successful

Implementation verified and meets requirements

The code analysis confirms that the implementation properly handles:

  • Multiple URL arguments through the ...urls:string spread operator
  • Error handling with proper feedback for failed lookups
  • Separator functionality with the -s/--separator option (default: ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~)
  • URL validation through the lookupObject function, which is thoroughly tested in src/vocab/lookup.test.ts
  • WebFinger resolution for actor handles, verified by tests in src/webfinger/lookup.test.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if the command properly handles the test cases mentioned in the PR

# Test 1: Check if the command accepts multiple arguments
deno task run lookup @[email protected] @[email protected]

# Test 2: Check if the command properly handles invalid input
deno task run lookup @[email protected] @[email protected]

# Test 3: Check if the separator option works
deno task run lookup -s "---" @[email protected] @[email protected]

Length of output: 489


Script:

#!/bin/bash
# Let's verify the implementation through code analysis instead of runtime behavior

# Check the command implementation
ast-grep --pattern 'command($$$).arguments("<...urls:string>")'

# Check for URL validation logic
rg -A 5 "validateUrl|isValidUrl|checkUrl" 

# Check for separator handling
rg -A 5 "separator|delimiter" 

# Look for test files
fd "test|spec" --extension ts

Length of output: 1607


Script:

#!/bin/bash
# Let's check the implementation details in lookup.ts and related test files

# Check the lookup command implementation
cat cli/lookup.ts

# Check the lookup-related test files
cat src/vocab/lookup.test.ts
cat src/webfinger/lookup.test.ts

Length of output: 12342

cli/npm/package.json Outdated Show resolved Hide resolved
cli/import_map.g.json Show resolved Hide resolved
cli/lookup.ts Show resolved Hide resolved
cli/lookup.ts Show resolved Hide resolved
By setting options of separator, it is possible to modify the value of
separator

Related to: dahlia#173
@rudeh1253 rudeh1253 force-pushed the lookup-multiple-args branch from bedd385 to 3146e71 Compare November 23, 2024 07:37
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 (2)
cli/lookup.ts (2)

35-39: Fix typo in separator option description

There's a typo in the description: "Speicfy" should be "Specify".

   .option(
     "-s, --separator <separator:string>",
-    "Speicfy the separator between adjacent output object.",
+    "Specify the separator between adjacent output objects.",
     { default: "~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~" },
   )

102-104: Make spinner text more specific

The current spinner text is generic. Consider including the URL being processed for better progress tracking.

   const spinnerForEachLookup = ora({
-    text: "Looking up an object...",
+    text: `Looking up object: ${url}`,
     discardStdin: false,
   }).start();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bedd385 and 3146e71.

📒 Files selected for processing (1)
  • cli/lookup.ts (3 hunks)
🔇 Additional comments (3)
cli/lookup.ts (3)

96-98: LGTM! Good improvement in user feedback

The added success message clearly indicates when initialization is complete, improving the user experience.


148-150: LGTM! Proper cleanup and exit handling

The code properly cleans up resources and sets an appropriate exit code based on the operation's success.


Line range hint 40-150: Verify handling of example cases from PR description

Let's verify that the implementation correctly handles the example cases mentioned in the PR description.

✅ Verification successful

Implementation correctly handles multiple URLs and separator functionality

The code analysis confirms proper implementation of the requirements:

  • Iterates through multiple URLs with proper error handling for each URL
  • Implements separator option with a default value
  • Handles error cases with appropriate user feedback
  • Only prints separator between objects (when i < urls.length - 1)

Note: There's a minor typo in the separator option description ("Speicfy" instead of "Specify"), but this doesn't affect functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the code handles the example cases correctly

# Test 1: Check if the command accepts multiple valid URLs
echo "Test 1: Multiple valid URLs"
deno task run lookup @[email protected] @[email protected]

# Test 2: Check if the command handles invalid URLs appropriately
echo "Test 2: Invalid URL"
deno task run lookup @[email protected] @[email protected]

# Test 3: Check if the separator option works
echo "Test 3: Custom separator"
deno task run lookup -s "---" @[email protected] @[email protected]

Length of output: 663


Script:

#!/bin/bash
# Let's verify the implementation by analyzing the code structure instead
# Check for URL handling and separator implementation

# Check how URLs are processed
ast-grep --pattern 'for (let i = 0; i < urls.length; i++) {
  $$$
}'

# Check separator implementation
rg "separator" -A 2 -B 2

# Check error handling for URLs
ast-grep --pattern 'catch (_) {
  $$$
}'

# Verify the command line options
rg "\.option.*separator" -A 2 -B 2

Length of output: 3061

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 (1)
CHANGES.md (1)

67-67: Fix bullet point indentation.

The indentation of this bullet point is inconsistent with other bullet points in the changelog.

Apply this diff to fix the indentation:

- -  Let the `fedify lookup` command take multiple arguments.
+  -  Let the `fedify lookup` command take multiple arguments.
🧰 Tools
🪛 Markdownlint (0.35.0)

67-67: Expected: 0; Actual: 1
Unordered list indentation

(MD007, ul-indent)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3146e71 and 015d137.

📒 Files selected for processing (1)
  • CHANGES.md (1 hunks)
🧰 Additional context used
🪛 Markdownlint (0.35.0)
CHANGES.md

67-67: Expected: 0; Actual: 1
Unordered list indentation

(MD007, ul-indent)

🔇 Additional comments (1)
CHANGES.md (1)

71-73: LGTM!

The PR reference links are properly formatted and correctly reference the PR #186 and issue #173 as mentioned in the PR objectives.

Copy link
Owner

@dahlia dahlia left a comment

Choose a reason for hiding this comment

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

Looks good to me. Thanks for your first contribution!

Copy link
Owner

@dahlia dahlia left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for your first contribution!

Copy link

codecov bot commented Nov 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.46%. Comparing base (6be10f1) to head (015d137).
Report is 33 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #186   +/-   ##
=======================================
  Coverage   84.46%   84.46%           
=======================================
  Files          42       42           
  Lines       11618    11618           
  Branches     1157     1157           
=======================================
  Hits         9813     9813           
  Misses       1784     1784           
  Partials       21       21           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@dahlia dahlia merged commit 05e7132 into dahlia:main Nov 23, 2024
14 checks passed
dahlia added a commit that referenced this pull request Nov 23, 2024
[ci skip]
dimsssss pushed a commit to dimsssss/fedify that referenced this pull request Nov 24, 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.

Let fedify lookup take multiple arguments
2 participants