Skip to content

Follow the Deno 2#81

Merged
5ouma merged 7 commits intomainfrom
refactor-deno-2
Oct 11, 2024
Merged

Follow the Deno 2#81
5ouma merged 7 commits intomainfrom
refactor-deno-2

Conversation

@5ouma
Copy link
Owner

@5ouma 5ouma commented Oct 11, 2024

⚠️ Issue

close #


🔄 Type of the Change

  • 🎉 New Feature
  • 🧰 Bug
  • 🛡️ Security
  • 📖 Documentation
  • 🏎️ Performance
  • 🧹 Refactoring
  • 🧪 Testing
  • 🔧 Maintenance
  • 🎽 CI
  • ⛓️ Dependencies
  • 🧠 Meta

✏️ Description

Get the benefits of the Deno 2.


5ouma added 3 commits October 11, 2024 15:14
Use the short flags for the ease of reading.
Check doc options for test and lint.
Also changed the error type for the Octokit one.
@prlabeler prlabeler bot added the 🧹 Refactoring A code change that neither fixes a bug nor adds a feature label Oct 11, 2024
@coderabbitai
Copy link

coderabbitai bot commented Oct 11, 2024

Walkthrough

The pull request includes updates to the deno.json file, modifying task commands and adding a new import for @octokit/request-error. Enhancements to error handling are made in src/libs/content.ts, where the RequestError class is utilized. The GitHub Actions workflow configuration is updated to a newer Deno setup version, and the CI workflow is adjusted to include documentation checks in the type-check job. Documentation improvements are also made across several source files, enhancing clarity and examples.

Changes

File Change Summary
.github/actions/setup-deno-with-cache/action.yml Updated Deno setup action from v1.5.1 to v2.0.0.
.github/workflows/ci.yml Modified type-check job command from deno check ./src to deno check --doc ./src.
deno.json Updated run, start, dev, and test task commands, added new import for @octokit/request-error.
src/libs/content.ts Enhanced error handling in getContent, updated import for RequestError.
src/libs/redirect.ts Improved documentation and examples for checkRedirect.
src/libs/test_utils.ts Enhanced documentation for exportRepo, added example for repository constant.
src/libs/utils.ts Updated documentation comment for getGitHubUrl with usage example.
src/server.ts Minor documentation updates, added import statement for UserAgent.

Possibly related PRs

Suggested labels

🎉 New Feature, 🧰 Bug, 🎽 CI


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4e3a3c9 and eded21c.

📒 Files selected for processing (2)
  • deno.json (1 hunks)
  • src/server.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • deno.json
  • src/server.ts

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

🧹 Outside diff range and nitpick comments (4)
.github/actions/setup-deno-with-cache/action.yml (1)

9-9: Approve the Deno setup action update with a minor suggestion.

The update to Deno setup action v2.0.0 aligns well with the PR objective of following Deno 2. Using a specific commit hash (4606d5cc6fb3f673efd4f594850e3f4b3e9d29cd) instead of a version tag provides better reproducibility and security for your workflow.

Consider adding a comment with the version number for better readability:

uses: denoland/setup-deno@4606d5cc6fb3f673efd4f594850e3f4b3e9d29cd # v2.0.0

This way, you maintain the security of using a specific commit while also providing a quick reference to the version number.

deno.json (1)

11-14: LGTM! Task commands updated to follow Deno 2 practices.

The changes to the "run" and "test" tasks align well with newer Deno practices:

  1. Using --env-file instead of --env is more explicit.
  2. The -EN shorthand for network permissions is a nice improvement.
  3. Adding --doc to the test command ensures documentation is also tested.

One minor suggestion:

Consider using the -A (allow all) flag for the "run" task instead of specifying individual permissions, as it's common for development environments. This would simplify the command to:

-    "run": "deno run --env-file='.env' -EN='0.0.0.0,api.github.com'",
+    "run": "deno run --env-file='.env' -A",

This change would allow for easier local development without constantly updating permissions.

src/libs/test_utils.ts (1)

60-66: LGTM! Documentation improvement with a minor suggestion.

The added example in the exportRepo function's documentation is a great improvement. It clearly demonstrates how to create a Repository object before using it with the function, which enhances the overall usability of the code.

Consider adding a comment explaining that this is just an example and the actual Repository object might vary based on the user's needs. This could prevent confusion for developers who might think this specific repository is required. For instance:

/**
 * @example
 * ```ts
 * import type { Repository } from "./types.ts";
 *
 * // Example Repository object - replace with your actual repository details
 * const repository: Repository = {
 *   owner: "denoland",
 *   name: "deno",
 *   path: "README.md",
 * };
 * exportRepo(repository);
 * ```
 */
.github/workflows/ci.yml (1)

Line range hint 1-91: Suggestion: Add a job to check for unused exports

While the current workflow is comprehensive, consider adding a new job to check for unused exports. This aligns with the PR's objective of following Deno 2 practices and can help improve code quality by identifying and removing dead code.

Here's a suggested implementation:

  check-unused-exports:
    name: 🔍 Check Unused Exports
    runs-on: Ubuntu-Latest

    steps:
      - name: 🚚 Checkout Repository
        uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1

      - name: 🦕 Setup Deno with Cache
        uses: ./.github/actions/setup-deno-with-cache

      - name: 🔍 Check Unused Exports
        run: deno check --all --unstable-check-unused-exports ./src

This job uses the new --unstable-check-unused-exports flag introduced in Deno 2 to identify any exports that are not being used in the project.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 98d4eaf and 1abb83d.

⛔ Files ignored due to path filters (1)
  • deno.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • .github/actions/setup-deno-with-cache/action.yml (1 hunks)
  • .github/workflows/ci.yml (1 hunks)
  • deno.json (1 hunks)
  • src/libs/content.ts (6 hunks)
  • src/libs/redirect.ts (4 hunks)
  • src/libs/test_utils.ts (1 hunks)
  • src/libs/utils.ts (1 hunks)
  • src/server.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/libs/redirect.ts
  • src/server.ts
🧰 Additional context used
🔇 Additional comments (6)
.github/actions/setup-deno-with-cache/action.yml (1)

Line range hint 1-18: Approve the overall structure and configuration of the workflow.

The entire workflow file is well-structured and follows good practices:

  1. It uses composite actions, enhancing reusability across workflows.
  2. Specific commit hashes are used for actions, improving security and reproducibility.
  3. The caching configuration appropriately covers Deno-related directories.

These practices contribute to a robust and maintainable CI/CD pipeline.

src/libs/utils.ts (1)

Line range hint 14-23: LGTM: Documentation improvement

The added example in the function's documentation is a valuable addition. It clearly demonstrates how to use the getGitHubUrl function, including the creation of a Repository object and the function invocation. This enhancement improves the overall quality of the documentation and will be helpful for developers using this function.

deno.json (2)

Line range hint 1-24: Overall, changes align well with PR objectives.

The modifications to deno.json successfully update the project configuration to align with Deno 2 practices:

  1. Task commands have been updated to use newer Deno flags and syntax.
  2. The addition of the "@octokit/request-error" import suggests improved error handling for GitHub API interactions.

These changes contribute to the refactoring goal mentioned in the PR objectives, potentially improving code structure and robustness without altering external behavior.


19-20: LGTM! New import added for improved error handling.

The addition of "@octokit/request-error" is a good improvement for more specific error handling with GitHub API requests.

To ensure this new import is being utilized effectively, please run the following script to check its usage across the codebase:

This will help confirm that the new import is being used appropriately throughout the project.

.github/workflows/ci.yml (1)

61-61: LGTM: Enhanced type checking with documentation

The addition of the --doc flag to the deno check command is a positive change. This modification enhances the type-checking process by including documentation checks, which aligns well with the PR's objective of following Deno 2 practices.

This change will help ensure that both the code and its documentation are type-safe, potentially catching more issues during the CI process and improving overall code quality.

src/libs/content.ts (1)

81-89: ⚠️ Potential issue

Improve error handling in the catch block

Using error instanceof RequestError may not always be reliable due to potential module instance differences. It's safer to check the name property or leverage a type guard to identify RequestError.

Consider updating the error handling logic to enhance reliability and security:

      } catch (error) {
-       return error instanceof RequestError
-         ? [
-           `⚠️ ${error.status}: ${error.message}`,
-           error.status as StatusCode,
-         ]
-         : [
-           `⚠️ ${STATUS_CODE.InternalServerError}: unknown error has occurred`,
-           STATUS_CODE.InternalServerError,
-         ];
+       if (error instanceof RequestError) {
+         return [
+           `⚠️ ${error.status}: ${error.message}`,
+           error.status as StatusCode,
+         ];
+       } else {
+         // Log the unexpected error for debugging purposes
+         console.error('An unexpected error occurred:', error);
+         return [
+           `⚠️ ${STATUS_CODE.InternalServerError}: An unexpected error occurred.`,
+           STATUS_CODE.InternalServerError,
+         ];
+       }
      }

This change:

  • Replaces the ternary operator with an if-else block for better readability.
  • Adds logging for unexpected errors without exposing internal details to the end user.
  • Provides a more user-friendly generic error message.

Ensure that the instanceof check works as expected in your environment. Run the following script to search for instanceof usage and verify consistency:

✅ Verification successful

Verified 'instanceof RequestError' Usage

The error instanceof RequestError check is consistently used and correctly imported in src/libs/content.ts. No issues found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for 'instanceof' usage to ensure consistent error handling practices.

rg --type ts 'instanceof'

Length of output: 319


Script:

#!/bin/bash
# Description: Search for 'instanceof' usage in TypeScript files.

rg --type ts 'instanceof'

Length of output: 86


Script:

#!/bin/bash
# Description: Search for imports of 'RequestError' in TypeScript files.

rg --type ts 'import.*RequestError'

Length of output: 112

5ouma added 2 commits October 11, 2024 15:40
It's better to have if type is only imported.
To use the `Deno.serve()`, it's needed also on the test.
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1abb83d and 4e3a3c9.

📒 Files selected for processing (2)
  • deno.json (1 hunks)
  • src/libs/content.ts (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • deno.json
🧰 Additional context used
📓 Learnings (1)
src/libs/content.ts (1)
Learnt from: 5ouma
PR: 5ouma/reproxy#81
File: src/libs/content.ts:2-3
Timestamp: 2024-10-11T06:38:16.548Z
Learning: In this project, `deno.json` includes the import map for resolving external modules like `@octokit/request-error` and `@std/http`.
🔇 Additional comments (2)
src/libs/content.ts (2)

2-3: Imports are correctly configured

The imports for RequestError and STATUS_CODE are properly included, aligning with the project's configuration and import map.


16-17: Documentation examples consistently use type-only imports

The import statements in the documentation examples now consistently use import type { Repository }, enhancing clarity and adhering to TypeScript best practices.

Also applies to: 27-28, 39-40, 51-52

Signed-off-by: Souma <101255979+5ouma@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Oct 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (1bbd450) to head (bc0a6c3).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #81   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines          109       113    +4     
  Branches         6         6           
=========================================
+ Hits           109       113    +4     

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

@5ouma 5ouma merged commit 66773fb into main Oct 11, 2024
@5ouma 5ouma deleted the refactor-deno-2 branch October 11, 2024 07:11
5ouma added a commit that referenced this pull request Oct 11, 2024
Get the benefits of the Deno 2.
@coderabbitai coderabbitai bot mentioned this pull request Oct 11, 2024
12 tasks
@coderabbitai coderabbitai bot mentioned this pull request Dec 8, 2024
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🧹 Refactoring A code change that neither fixes a bug nor adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant