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

test: add markdown tests #3301

Merged
merged 22 commits into from
Oct 23, 2024
Merged

Conversation

anshgoyalevil
Copy link
Member

@anshgoyalevil anshgoyalevil commented Oct 18, 2024

This PR tests the gray matter (front-matter) included in markdown files in the website repository.

Example Comment: anshgoyalevil#17 (comment)

fixes #3215

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced markdown checks in pull request workflows to ensure documentation quality.
    • Added a new script for validating markdown files, enhancing content accuracy.
    • Updated documentation to reflect breaking changes in AsyncAPI version 3, improving clarity and usability.
  • Bug Fixes

    • Automated commenting on pull requests for detected markdown issues, improving feedback for contributors.
  • Documentation

    • Updated package.json to include a script for running markdown checks, streamlining the testing process.
    • Added metadata fields to documents for better organization and prioritization.

Copy link

coderabbitai bot commented Oct 18, 2024

Walkthrough

The pull request introduces enhancements to the Node.js pull request testing workflow. Key changes include the addition of a step for markdown checks, which executes a new script to validate markdown files and their frontmatter. If issues are found, a comment is posted on the pull request. Conversely, if no issues are detected, any existing comment is deleted. Additionally, a new script for markdown validation is added to the package.json, and a new JavaScript file is created to implement the validation logic.

Changes

File Path Change Summary
.github/workflows/if-nodejs-pr-testing.yml Added steps for markdown checks, including running a new script, commenting on PR with issues, and deleting comments if no issues are found. Minor formatting changes made.
package.json Added new script entry "test:md": "node scripts/markdown/check-markdown.js" for markdown validation.
scripts/markdown/check-markdown.js Introduced a new script for validating markdown frontmatter, including functions for URL validation and specific checks for blog and documentation files.

Assessment against linked issues

Objective Addressed Explanation
Setup a workflow to notify when markdown files do not render (#3215)

Possibly related PRs

  • feat: add codecov to the project #3168: This PR modifies the same workflow file (.github/workflows/if-nodejs-pr-testing.yml) to enhance testing capabilities, which is directly related to the changes made in the main PR regarding markdown checks.

Suggested labels

ready-to-merge, gsoc

Suggested reviewers

  • derberg
  • magicmatatjahu
  • sambhavgupta0705
  • akshatnema

Poem

In the land of markdown, so bright and fair,
We check and we validate with utmost care.
If issues arise, a comment will show,
Keeping our documents polished, aglow!
With scripts in our pockets, we hop with glee,
Ensuring our markdown is flawless, you see! 🐇✨


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

netlify bot commented Oct 18, 2024

Deploy Preview for asyncapi-website ready!

Name Link
🔨 Latest commit a8e7404
🔍 Latest deploy log https://app.netlify.com/sites/asyncapi-website/deploys/6718a1bcb3afb800089beec0
😎 Deploy Preview https://deploy-preview-3301--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@asyncapi-bot
Copy link
Contributor

asyncapi-bot commented Oct 18, 2024

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 39
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-3301--asyncapi-website.netlify.app/

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

🧹 Outside diff range and nitpick comments (2)
.github/workflows/if-nodejs-pr-testing.yml (2)

87-101: Approve: PR comment for markdown issues with suggestion

This step effectively addresses the PR objective of alerting the team when markdown files have issues. The use of a sticky comment is a good choice for maintaining visibility without cluttering the PR.

Consider adding a brief explanation of what the markdown check does and how to resolve common issues. This could be added to the comment message like so:

  message: |
    ### Markdown Check Results

+   The markdown check validates the structure and front-matter of markdown files.
+   Common issues include incorrect YAML front-matter formatting or missing required fields.
+
    We found issues in the following markdown files:

    ```
    ${{ steps.markdown_check.outputs.markdown_output }}
    ```

+   Please review and correct these files before merging.

This additional context can help developers quickly understand and resolve the issues.


83-83: Minor: Remove trailing spaces

There are trailing spaces at the end of this line. While this doesn't affect functionality, it's generally good practice to remove them for cleaner code.

Please remove the trailing spaces from this line:

- OUTPUT=$(npm run test:md || true) 
+ OUTPUT=$(npm run test:md || true)
🧰 Tools
🪛 yamllint

[error] 83-83: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7abb5fd and 85f5fab.

📒 Files selected for processing (3)
  • .github/workflows/if-nodejs-pr-testing.yml (2 hunks)
  • package.json (1 hunks)
  • scripts/markdown/check-markdown.js (1 hunks)
🧰 Additional context used
🪛 actionlint
.github/workflows/if-nodejs-pr-testing.yml

82-82: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)

🪛 yamllint
.github/workflows/if-nodejs-pr-testing.yml

[error] 83-83: trailing spaces

(trailing-spaces)

🪛 Biome
scripts/markdown/check-markdown.js

[error] 31-31: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


[error] 37-37: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

🔇 Additional comments (4)
.github/workflows/if-nodejs-pr-testing.yml (3)

64-64: LGTM: Consistent quote usage

The change from double quotes to single quotes for the node-version input is a minor improvement in consistency. This doesn't affect functionality but contributes to better code style.


103-110: Approve: Cleanup step for markdown check comments

This step is a great addition that complements the previous comment step. By removing the comment when no issues are found, it keeps the PR clean and focused. This is an excellent practice for maintaining a tidy and informative PR thread.


Line range hint 1-111: Summary: Effective implementation of markdown checks with minor improvements needed

The changes to this workflow file successfully implement the markdown checking functionality as outlined in the PR objectives. The new steps for running markdown checks, commenting on issues, and cleaning up comments work together to provide a robust system for ensuring markdown file quality.

Key points:

  1. The markdown checks are now integrated into the PR testing process.
  2. The workflow will alert the team by commenting on the PR when markdown files have issues, addressing the concern raised in issue Automation testing for MD files #3215.
  3. The cleanup step ensures that the PR remains tidy when no issues are found.

These changes will significantly improve the reliability of markdown file rendering and help prevent instances where markdown files don't render properly without notification.

To further improve the implementation:

  1. Update the deprecated set-output command as suggested earlier.
  2. Consider adding more context to the PR comment to help developers quickly resolve issues.
  3. Remove the trailing spaces on line 83.

Once these minor issues are addressed, this implementation will provide a solid foundation for ongoing markdown file quality assurance.

🧰 Tools
🪛 actionlint

82-82: workflow command "set-output" was deprecated. use echo "{name}={value}" >> $GITHUB_OUTPUT instead: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions

(deprecated-commands)

🪛 yamllint

[error] 83-83: trailing spaces

(trailing-spaces)

package.json (1)

26-26: New script for markdown testing looks good.

The addition of the "test:md" script aligns well with the PR objectives of implementing tests for markdown files. This script will run the check-markdown.js file, which is likely responsible for validating the gray matter (front-matter) in markdown files as mentioned in the PR summary.

A few points to consider:

  1. Ensure that the scripts/markdown/check-markdown.js file exists and contains the necessary logic for markdown validation.
  2. Consider integrating this new script into your CI/CD pipeline to automate markdown checks on every pull request.
  3. You might want to update the main "test" script to include this new markdown test, ensuring it runs alongside other tests.

To verify the existence of the script file and its potential usage, let's run the following:

.github/workflows/if-nodejs-pr-testing.yml Outdated Show resolved Hide resolved
scripts/markdown/check-markdown.js Outdated Show resolved Hide resolved
scripts/markdown/check-markdown.js Outdated Show resolved Hide resolved
scripts/markdown/check-markdown.js Show resolved Hide resolved
scripts/markdown/check-markdown.js Outdated Show resolved Hide resolved
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

🧹 Outside diff range and nitpick comments (2)
.github/workflows/if-nodejs-pr-testing.yml (2)

78-85: Improve script robustness

The new step for running markdown checks is a great addition and aligns well with the PR objectives. However, there's a minor improvement we can make to ensure robustness:

Consider quoting the $ERRORS variable to prevent potential issues with word splitting or globbing:

- ERRORS=$(npm run test:md) 
- echo "markdown_output=$ERRORS" >> $GITHUB_OUTPUT
+ ERRORS=$(npm run test:md)
+ echo "markdown_output<<EOF" >> $GITHUB_OUTPUT
+ echo "$ERRORS" >> $GITHUB_OUTPUT
+ echo "EOF" >> $GITHUB_OUTPUT

This change will ensure that the entire output is captured correctly, even if it contains spaces or special characters.

🧰 Tools
🪛 actionlint

82-82: shellcheck reported issue in this script: SC2086:info:2:35: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint

[error] 83-83: trailing spaces

(trailing-spaces)


83-83: Remove trailing spaces

There are trailing spaces at the end of line 83. While this doesn't affect functionality, it's good practice to remove them for code cleanliness.

Please remove the trailing spaces from this line:

- ERRORS=$(npm run test:md) 
+ ERRORS=$(npm run test:md)
🧰 Tools
🪛 yamllint

[error] 83-83: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 85f5fab and 56eda46.

📒 Files selected for processing (2)
  • .github/workflows/if-nodejs-pr-testing.yml (2 hunks)
  • scripts/markdown/check-markdown.js (1 hunks)
🧰 Additional context used
🪛 actionlint
.github/workflows/if-nodejs-pr-testing.yml

82-82: shellcheck reported issue in this script: SC2086:info:2:35: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint
.github/workflows/if-nodejs-pr-testing.yml

[error] 83-83: trailing spaces

(trailing-spaces)

🪛 Biome
scripts/markdown/check-markdown.js

[error] 31-31: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


[error] 37-37: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.

(lint/suspicious/noGlobalIsNan)

🔇 Additional comments (3)
.github/workflows/if-nodejs-pr-testing.yml (3)

86-100: Excellent addition of PR commenting for markdown issues

This new step effectively addresses the PR objective of alerting the team when markdown files fail to render correctly. The use of a sticky comment ensures that the issues remain visible and prevents cluttering the PR with multiple comments.

The implementation is well-structured and provides clear, formatted output of any markdown issues found. This will greatly improve the team's ability to identify and address rendering problems quickly.


102-109: Approve: Efficient cleanup of markdown check comments

This step is a great complement to the previous one. It ensures that the PR remains clean and free of unnecessary comments when no markdown issues are found.

By removing outdated comments, this step helps prevent confusion and keeps the PR focused on current issues. The implementation is consistent with the previous step and uses the same action effectively.


Line range hint 1-110: Overall assessment: Excellent implementation of markdown checks

The changes made to this workflow file effectively address the PR objectives by implementing markdown checks and providing a clear mechanism for reporting issues. The use of sticky comments for both reporting issues and cleaning up resolved ones is a great approach.

While there are a few minor suggestions for improvement, the overall implementation is solid and will significantly enhance the team's ability to catch and address markdown rendering issues early in the development process.

🧰 Tools
🪛 actionlint

82-82: shellcheck reported issue in this script: SC2086:info:2:35: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 yamllint

[error] 83-83: trailing spaces

(trailing-spaces)

scripts/markdown/check-markdown.js Outdated Show resolved Hide resolved
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 (2)
.github/workflows/if-nodejs-pr-testing.yml (2)

78-86: Approve: New markdown check step with suggested improvements

The addition of this step aligns well with the PR objective of implementing tests for markdown files. It's great to see that the deprecated set-output command has been replaced with the new syntax as suggested in the previous review.

To further improve the script, consider addressing the following shellcheck suggestions:

  1. Use curly braces for command grouping:
- ERRORS=$(npm run test:md | sed -n '/Errors in file/,$p')
- echo "markdown_output<<EOF" >> $GITHUB_OUTPUT
- echo "$ERRORS" >> $GITHUB_OUTPUT
- echo "EOF" >> $GITHUB_OUTPUT
+ {
+   echo "markdown_output<<EOF"
+   npm run test:md | sed -n '/Errors in file/,$p'
+   echo "EOF"
+ } >> $GITHUB_OUTPUT
  1. Double quote variables to prevent globbing and word splitting:
- ERRORS=$(npm run test:md | sed -n '/Errors in file/,$p')
+ ERRORS="$(npm run test:md | sed -n '/Errors in file/,$p')"

These changes will make the script more robust and align with shell scripting best practices.

🧰 Tools
🪛 actionlint

82-82: shellcheck reported issue in this script: SC2129:style:2:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects

(shellcheck)


82-82: shellcheck reported issue in this script: SC2086:info:2:32: Double quote to prevent globbing and word splitting

(shellcheck)


82-82: shellcheck reported issue in this script: SC2086:info:3:19: Double quote to prevent globbing and word splitting

(shellcheck)


82-82: shellcheck reported issue in this script: SC2086:info:4:15: Double quote to prevent globbing and word splitting

(shellcheck)


78-111: Summary: Effective implementation of markdown checks with suggestions for next steps

The changes in this PR successfully implement the markdown checking process, which directly addresses the main objective of automating tests for markdown files. The addition of steps to run checks, comment on issues, and clean up comments when no issues are found creates a robust workflow for maintaining markdown quality.

However, the Lighthouse report mentioned in the PR comments indicates some performance concerns:

  • Performance: 41 (🔴)
  • PWA: 33 (🔴)

While these performance issues are not directly related to the markdown checking implementation, they are important to address for the overall quality of the project.

Suggestions for next steps:

  1. Consider adding a step in the workflow to run Lighthouse checks automatically, which could help catch performance regressions early.
  2. Investigate the specific causes of the low performance and PWA scores, and create separate issues to track and address these concerns.
  3. If applicable, add performance benchmarks to the CI process to ensure that changes don't negatively impact the site's performance.

By addressing these performance concerns alongside the markdown checks, you'll be improving both the content quality and the user experience of the website.

Would you like assistance in creating a workflow step for automated Lighthouse checks or in analyzing the performance issues?

🧰 Tools
🪛 actionlint

82-82: shellcheck reported issue in this script: SC2129:style:2:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects

(shellcheck)


82-82: shellcheck reported issue in this script: SC2086:info:2:32: Double quote to prevent globbing and word splitting

(shellcheck)


82-82: shellcheck reported issue in this script: SC2086:info:3:19: Double quote to prevent globbing and word splitting

(shellcheck)


82-82: shellcheck reported issue in this script: SC2086:info:4:15: Double quote to prevent globbing and word splitting

(shellcheck)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 56eda46 and 1fb8b0e.

📒 Files selected for processing (2)
  • .github/workflows/if-nodejs-pr-testing.yml (2 hunks)
  • scripts/markdown/check-markdown.js (1 hunks)
🧰 Additional context used
🪛 actionlint
.github/workflows/if-nodejs-pr-testing.yml

82-82: shellcheck reported issue in this script: SC2129:style:2:1: Consider using { cmd1; cmd2; } >> file instead of individual redirects

(shellcheck)


82-82: shellcheck reported issue in this script: SC2086:info:2:32: Double quote to prevent globbing and word splitting

(shellcheck)


82-82: shellcheck reported issue in this script: SC2086:info:3:19: Double quote to prevent globbing and word splitting

(shellcheck)


82-82: shellcheck reported issue in this script: SC2086:info:4:15: Double quote to prevent globbing and word splitting

(shellcheck)

🪛 Biome
scripts/markdown/check-markdown.js

[error] 31-31: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

🔇 Additional comments (6)
.github/workflows/if-nodejs-pr-testing.yml (2)

88-102: Approve: Well-implemented PR comment for markdown issues

This step effectively addresses the PR objective of alerting the team when markdown files have issues. The use of a sticky comment ensures that the information remains visible and up-to-date without cluttering the PR with multiple comments.

The formatting of the comment, including the header and code block for the markdown check results, provides clear and easily readable feedback to the PR author and reviewers.


104-111: Approve: Efficient cleanup of markdown check comments

This step is a great addition that complements the previous comment step. By deleting the comment when no markdown issues are found, it keeps the PR clean and focused. The implementation correctly uses the output from the markdown check step and the same header to ensure the right comment is managed.

This approach effectively prevents outdated information from lingering on the PR, which aligns well with maintaining a clear and accurate review process.

scripts/markdown/check-markdown.js (4)

10-17: Well-implemented URL validation function

The isValidURL function is concise, effective, and follows best practices. It properly uses a try-catch block to handle potential errors when creating a URL object, which is an efficient way to validate URLs.


101-135: Well-implemented recursive markdown file checker

The checkMarkdownFiles function is well-structured and effectively handles directory traversal and file validation. It appropriately uses asynchronous operations for directory listing and file stat checks, while using synchronous file reading for content, which aligns with the project's requirements. The error handling and CI/CD integration through process.exitCode are also well-implemented.


137-141: Effective main execution setup

The main execution part of the script is concise and well-structured. It correctly resolves the paths for documentation and blog folders, and appropriately calls the checkMarkdownFiles function with the corresponding validation function for each folder.


1-141: Overall, a well-implemented markdown frontmatter validation system

This script effectively addresses the PR objectives by implementing a comprehensive system for validating the frontmatter in markdown files. The implementation is well-structured, follows good practices, and provides a solid foundation for ensuring the reliability of markdown file rendering.

Key strengths:

  1. Thorough validation of blog and documentation frontmatter
  2. Effective recursive file traversal
  3. Proper error handling and reporting
  4. Integration with CI/CD through exit code management

The suggested minor improvements for consistency and robustness will further enhance the already strong implementation.

🧰 Tools
🪛 Biome

[error] 31-31: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

scripts/markdown/check-markdown.js Show resolved Hide resolved
scripts/markdown/check-markdown.js Show resolved Hide resolved
scripts/markdown/check-markdown.js Show resolved Hide resolved
@anshgoyalevil
Copy link
Member Author

This PR is failing because of 2 reasons:

  • A PR cannot access GH_TOKEN. It can only be accessed after merging it. Check PR description for a test comment in fork.
  • There are some markdown errors in the docs. We need to fix them. @akshatnema Can you please suggest what we should do for these files?

akshatnema
akshatnema previously approved these changes Oct 19, 2024
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 (5)
scripts/markdown/check-markdown.js (5)

10-17: LGTM with a minor suggestion

The isValidURL function provides a simple and effective way to validate URLs. However, for more robust validation, consider adding additional checks, such as ensuring the protocol is http or https, or using a regular expression for stricter validation.

For example, you could enhance the function like this:

function isValidURL(str) {
    try {
        const url = new URL(str);
        return url.protocol === "http:" || url.protocol === "https:";
    } catch (err) {
        return false;
    }
}

This ensures that only http and https URLs are considered valid.


25-71: LGTM with a suggestion for consistency

The validateBlogs function provides comprehensive validation for blog post frontmatter. The checks for required attributes, date format, tags, cover, and authors are thorough and well-implemented.

For consistency with error handling across the codebase, consider always returning an array, even when there are no errors:

- return errors.length ? errors : null;
+ return errors;

This change would simplify error checking in the calling code, as you'd always be working with an array.

🧰 Tools
🪛 Biome

[error] 31-31: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


79-93: LGTM with a suggestion for consistency

The validateDocs function effectively validates the essential attributes for documentation frontmatter. The checks for 'title' and 'weight' are appropriate and well-implemented.

For consistency with the suggested change in validateBlogs and to simplify error handling in the calling code, consider always returning an array:

- return errors.length ? errors : null;
+ return errors;

This change would maintain consistency across validation functions and simplify error checking in checkMarkdownFiles.


101-135: LGTM with a minor suggestion for error logging

The checkMarkdownFiles function effectively traverses directories and validates markdown files. The use of synchronous file reading within the asynchronous context is intentional and appropriate for handling large markdown files with recursion and loops.

Consider enhancing the error logging to include the file path for better traceability:

- console.error('Error reading file stats:', err);
+ console.error(`Error reading file stats for ${filePath}:`, err);

This change would make it easier to identify which specific file caused an error during the validation process.


137-141: LGTM with a suggestion for error handling

The main execution part of the script correctly sets up the folder paths and calls checkMarkdownFiles for both docs and blogs with their respective validation functions.

Consider adding error handling for cases where the folder paths might not exist:

const fs = require('fs');
const path = require('path');

const docsFolderPath = path.resolve(__dirname, '../../markdown/docs');
const blogsFolderPath = path.resolve(__dirname, '../../markdown/blog');

[docsFolderPath, blogsFolderPath].forEach(folderPath => {
  if (!fs.existsSync(folderPath)) {
    console.error(`Folder not found: ${folderPath}`);
    process.exitCode = 1;
    return;
  }
});

if (process.exitCode !== 1) {
  checkMarkdownFiles(docsFolderPath, validateDocs);
  checkMarkdownFiles(blogsFolderPath, validateBlogs);
}

This addition ensures that the script fails gracefully if either of the expected folders is missing.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 1fb8b0e and 2fcb7f9.

📒 Files selected for processing (1)
  • scripts/markdown/check-markdown.js (1 hunks)
🧰 Additional context used
📓 Learnings (1)
scripts/markdown/check-markdown.js (1)
Learnt from: anshgoyalevil
PR: asyncapi/website#3301
File: scripts/markdown/check-markdown.js:31-31
Timestamp: 2024-10-18T17:37:50.602Z
Learning: In `scripts/markdown/check-markdown.js`, the `frontmatter` object cannot have a property named `hasOwnProperty`, so using `frontmatter.hasOwnProperty(attr)` is acceptable.
🪛 Biome
scripts/markdown/check-markdown.js

[error] 31-31: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

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)
markdown/docs/migration/migrating-to-v3.md (4)

Line range hint 18-45: LGTM: Clear explanation of metadata changes

The "Moved metadata" section effectively explains the relocation of tags and externalDocs properties in v3. The YAML examples clearly illustrate the change.

Suggestion for enhancement:
Consider adding a brief explanation of why this change was made (e.g., improved consistency, better organization of metadata). This would help users understand the rationale behind the change.


Line range hint 75-129: LGTM: Comprehensive explanation of major structural changes

The "Operation, channel, and message decoupling" section effectively explains this significant breaking change in v3. It:

  1. Clearly states that this is the most significant breaking change.
  2. Explains the new possibilities this change enables (reusing channels, multiple operations per channel).
  3. Provides context for different messaging systems (Kafka, REST, WebSocket, Socket.IO).
  4. Includes clear YAML examples that illustrate the structural changes.

Suggestion for enhancement:
Consider adding a brief explanation of the benefits this change brings (e.g., increased flexibility, better representation of complex systems). This would help users understand why this significant change was made.


Line range hint 219-270: LGTM: Clear explanation of message definition changes

The "Messages instead of message" section effectively explains the changes to message definitions in v3. It:

  1. Clearly describes the shift from using oneOf for multiple messages to using key-value pairs in the Messages Object.
  2. Provides examples for both single and multiple message scenarios.
  3. Mentions the removal of the messageId property and explains how message IDs are now handled.

Suggestion for enhancement:
Consider adding a brief explanation of the benefits this change brings (e.g., improved clarity, easier parsing). This would help users understand why this change was made.


Line range hint 272-320: LGTM: Clear explanation of reference unification

The "Unifying explicit and implicit references" section effectively explains the changes to references in v3. It:

  1. Clearly states that all references must now be explicit.
  2. Explains the changes to the Server Object's security property.
  3. Mentions the relocation of OAuth and OpenID Connect scopes.
  4. Provides clear YAML examples that illustrate these changes.

Suggestion for enhancement:
Consider adding a brief explanation of why this change was made (e.g., improved consistency, easier parsing or validation). This would help users understand the rationale behind this breaking change.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2fcb7f9 and 4cd9cfa.

📒 Files selected for processing (3)
  • markdown/docs/migration/index.md (1 hunks)
  • markdown/docs/migration/migrating-to-v3.md (1 hunks)
  • scripts/markdown/check-markdown.js (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • markdown/docs/migration/index.md
🧰 Additional context used
📓 Learnings (1)
scripts/markdown/check-markdown.js (1)
Learnt from: anshgoyalevil
PR: asyncapi/website#3301
File: scripts/markdown/check-markdown.js:31-31
Timestamp: 2024-10-18T17:37:50.602Z
Learning: In `scripts/markdown/check-markdown.js`, the `frontmatter` object cannot have a property named `hasOwnProperty`, so using `frontmatter.hasOwnProperty(attr)` is acceptable.
🪛 Biome
scripts/markdown/check-markdown.js

[error] 31-31: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)

🔇 Additional comments (15)
scripts/markdown/check-markdown.js (7)

10-17: Well-implemented URL validation function

The isValidURL function is concise, efficient, and follows best practices for URL validation. The use of a try-catch block to handle potential errors is appropriate here.


25-71: Well-structured blog frontmatter validation

The validateBlogs function provides comprehensive validation for blog frontmatter. It checks all required attributes and performs specific validations for date, tags, cover, and authors.

🧰 Tools
🪛 Biome

[error] 31-31: Do not access Object.prototype method 'hasOwnProperty' from target object.

It's recommended using Object.hasOwn() instead of using Object.hasOwnProperty().
See MDN web docs for more details.

(lint/suspicious/noPrototypeBuiltins)


79-93: Concise documentation frontmatter validation

The validateDocs function provides focused validation for documentation frontmatter, checking for the presence and correct type of 'title' and 'weight' attributes.


101-140: Well-structured markdown file processing

The checkMarkdownFiles function provides a robust way to recursively process markdown files, apply validation, and report errors. The skipping of the 'docs/reference/specification' folder and setting of process.exitCode on errors are good practices.


142-146: Effective main execution setup

The script correctly sets up the paths for both documentation and blog folders, and applies the appropriate validation function to each. This ensures comprehensive checking of all relevant markdown files in the project.


70-71: 🛠️ Refactor suggestion

Consider returning an empty array instead of null

For consistency with other validation functions, consider returning an empty array instead of null when there are no errors. This would simplify error handling in the calling code.

Apply this diff to improve the return statement:

- return errors.length ? errors : null;
+ return errors;

92-93: 🛠️ Refactor suggestion

Consider returning an empty array instead of null

For consistency with other validation functions, consider returning an empty array instead of null when there are no errors. This would simplify error handling in the calling code.

Apply this diff to improve the return statement:

- return errors.length ? errors : null;
+ return errors;
markdown/docs/migration/migrating-to-v3.md (8)

1-4: LGTM: Frontmatter update

The addition of the weight: 2 property in the frontmatter is appropriate. This will help control the order of pages in the documentation, indicating that this is an important page in the migration guide.


Line range hint 6-16: LGTM: Clear and informative introduction

The introductory text effectively sets the context for the migration guide. It provides:

  1. A brief explanation of the migration challenge.
  2. Information about the AsyncAPI converter tool, including a command for usage.
  3. A reference to the v3 release notes for more detailed information.

This approach gives users both quick migration options and resources for deeper understanding.


Line range hint 47-73: LGTM: Clear explanation of server URL changes

The "Server URL splitting up" section effectively explains the changes to the Server Object in v3. It:

  1. Provides context for why the change was made (addressing confusion about URL contents).
  2. Clearly describes the shift from a single url property to separate host, pathname, and protocol properties.
  3. Includes clear YAML examples that illustrate the change.

This explanation and the examples will help users understand and implement this breaking change in their AsyncAPI documents.


Line range hint 131-159: LGTM: Clear explanation of channel key and address changes

The "Channel address and channel key" section effectively explains this breaking change in v3. It:

  1. Clearly describes the shift from using the channel key as the path to using it as an arbitrary unique ID.
  2. Explains the introduction of the address property for defining the channel path.
  3. Provides context for why this change was made (enhancing reusability and allowing for scenarios where the same address is used in different contexts).
  4. Includes clear YAML examples that illustrate the structural changes.

This explanation and the examples will help users understand and implement this breaking change in their AsyncAPI documents.


Line range hint 161-217: LGTM: Comprehensive explanation of operation keyword changes

The "Operation keywords" section effectively explains this important change in v3. It:

  1. Clearly describes the shift from publish and subscribe to send and receive.
  2. Explains why this change was made (addressing confusion in v2).
  3. Provides a clear explanation of how the new keywords relate to the application's behavior.
  4. Includes links to additional resources for users who want more information about the publish/subscribe confusion.
  5. Provides clear YAML examples that illustrate the changes.

The thorough explanation, examples, and additional resources make this section particularly helpful for users migrating from v2 to v3.


Line range hint 322-376: LGTM: Comprehensive explanation of trait behavior changes

The "New trait behavior" section effectively explains the changes to trait application in v3. It:

  1. Clearly describes the change in behavior, with properties in the primary objects now taking precedence over those in traits.
  2. Provides context for why this change was made (preventing unintended overrides).
  3. Includes clear YAML examples that illustrate the difference in behavior between v2 and v3.
  4. Mentions the JSON Merge Patch algorithm, providing useful technical context.
  5. Clearly states the new guideline: "A property on a trait MUST NOT override the same property on the target object".

This detailed explanation and the examples will help users understand and adapt to this breaking change in their AsyncAPI documents.


Line range hint 378-486: LGTM: Clear explanations of various v3 changes

The final sections of the document effectively explain several important changes in AsyncAPI v3:

  1. "Schema format and schemas":

    • Clearly explains the introduction of a multi-format schema object.
    • Provides context for why this change improves schema reusability.
    • Includes clear YAML examples illustrating the change.
  2. "Optional channels":

    • Succinctly explains that channels are now entirely optional in v3.
    • Provides simple YAML examples showing the difference.
  3. "Restricted parameters object":

    • Explains the simplification of the Parameters Object in v3.
    • Provides context for why this change was made (focusing on practical use cases).
    • Clearly lists the available properties in v3.
    • Includes YAML examples illustrating the changes.

These sections provide clear, concise explanations of important changes, helping users understand and implement these changes in their AsyncAPI v3 documents.


Line range hint 1-486: Excellent migration guide: Comprehensive, clear, and well-structured

This migration guide for AsyncAPI v3 is of high quality and will be extremely valuable for users upgrading from v2. Key strengths include:

  1. Comprehensive coverage of all major breaking changes.
  2. Clear explanations that provide context for why changes were made.
  3. Consistent use of YAML examples to illustrate changes.
  4. Well-structured format that addresses each change in a logical order.
  5. Use of custom components (e.g., <Asyncapi3MetaComparison>) that likely provide interactive comparisons in the rendered version.

Minor suggestions for enhancement:

  • Consider adding brief explanations of the benefits for some changes to help users understand the rationale.
  • Ensure that the custom comparison components render correctly and enhance the user experience as intended.

Overall, this document serves as an excellent resource for the AsyncAPI community in adopting v3.

scripts/markdown/check-markdown.js Show resolved Hide resolved
scripts/markdown/check-markdown.js Show resolved Hide resolved
scripts/markdown/check-markdown.js Show resolved Hide resolved
@asyncapi-bot asyncapi-bot added the bounty AsyncAPI Bounty program related label label Oct 21, 2024
@aeworxet
Copy link
Contributor

@asyncapi/bounty_team

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bounty AsyncAPI Bounty program related label
Projects
Status: Completed
Development

Successfully merging this pull request may close these issues.

Automation testing for MD files
4 participants