Skip to content

fix metadata #1440

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

Merged
merged 2 commits into from
Mar 4, 2025
Merged

fix metadata #1440

merged 2 commits into from
Mar 4, 2025

Conversation

cpengilly
Copy link
Contributor

No description provided.

@cpengilly cpengilly requested review from 0xmariniere and a team as code owners March 4, 2025 08:42
Copy link

netlify bot commented Mar 4, 2025

Deploy Preview for docs-optimism ready!

Name Link
🔨 Latest commit d4e4029
🔍 Latest deploy log https://app.netlify.com/sites/docs-optimism/deploys/67c6be5baec8e800086d8fbe
😎 Deploy Preview https://deploy-preview-1440--docs-optimism.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.

Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

📝 Walkthrough

Walkthrough

This pull request updates multiple aspects of the metadata handling and validation workflow. In the package.json, the "validate-metadata" script is modified to call pnpm metadata-batch-cli:dry instead of directly executing a TypeScript file with ts-node. Several MDX pages have metadata adjustments, including changes in category names, capitalization, and content type classifications. In utils/metadata-batch-cli.ts, the file processing logic is enhanced: it now checks for the CHANGED_FILES environment variable, falls back to using globby when necessary, and iterates over files to generate and update metadata with improved error handling. Additionally, in utils/metadata-manager.ts, the generateMetadata function is updated to ensure that the personas property is always an array, preventing potential type issues.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer/CLI
    participant npm as Package Manager
    participant CLI as metadata-batch-cli Main
    participant MM as metadata-manager.generateMetadata
    participant UMD as updateMetadataFile Function

    Dev->>npm: Run "validate-metadata"
    npm->>CLI: Execute pnpm metadata-batch-cli:dry
    CLI->>CLI: Check for CHANGED_FILES environment variable
    CLI->>CLI: Retrieve file list via globby if necessary
    loop For each file in mdxFiles
      CLI->>MM: Generate metadata for file
      MM-->>CLI: Return metadata object
      CLI->>UMD: Update metadata file using metadata and options
    end
    CLI->>Dev: Output processing summary with stats
Loading
sequenceDiagram
    participant GM as generateMetadata
    participant EM as existingMetadata

    GM->>EM: Read metadata properties
    alt personas is a string
       GM->>GM: Convert personas into an array
    else personas is already an array
       GM->>GM: Use personas as-is
    end
    GM-->>Caller: Return metadata with consistent personas format
Loading

Possibly related PRs

  • metadata-keyword-generator #1408: The changes in the main PR, which modify the validate-metadata script in package.json and introduce new metadata management scripts, are related to the changes in the retrieved PR that enhance the metadata validation process in the CircleCI configuration, specifically through the use of the CHANGED_FILES environment variable. Both PRs focus on improving metadata handling and validation workflows.

Suggested reviewers

  • krofax
  • bradleycamacho
  • jvmi7

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7c17c0a and d4e4029.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (1)
  • package.json (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - docs-optimism
  • GitHub Check: Header rules - docs-optimism
  • GitHub Check: Pages changed - docs-optimism
🔇 Additional comments (3)
package.json (3)

19-19: Refined Metadata Validation Command

The change on line 19 updates the "validate-metadata" command to use pnpm metadata-batch-cli:dry, which leverages the new CLI script for a dry-run validation. This streamlines the metadata validation process by removing the direct execution via ts-node and avoiding the use of NODE_NO_WARNINGS. Ensure that the environment variable CHANGED_FILES is properly set in all relevant environments (CI and local) to avoid missing changes during validation.


37-37: New Dependency: glob

The addition of "glob": "^11.0.1" provides enhanced file pattern matching capabilities that are likely required by the updated metadata handling logic. Verify that the version specified aligns with other parts of the project where similar functionality might be used.


54-54: Improved Type Safety with @types/glob

Adding "@types/glob": "^8.1.0" as a dev dependency fortifies type safety when using the glob package in TypeScript code. This change should help maintain consistency and prevent typographical errors in file matching functionality.


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 generate docstrings to generate docstrings for this 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.

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
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
utils/metadata-manager.ts (1)

109-112: Good enhancement to ensure consistent type handling.

This change ensures the personas property is always an array, addressing a potential type inconsistency that could occur if existingMetadata.personas was a string.

The implementation is good. For even more robustness, you could also handle the case when personas is a non-array, non-string value:

let personas = existingMetadata.personas || []
if (typeof personas === 'string') {
  personas = [personas]
+} else if (!Array.isArray(personas)) {
+  personas = []
}
pages/app-developers/tutorials/supersim.mdx (1)

16-16: Note: Description inconsistency between frontmatter and page content.

The page content still contains the longer description that was removed from the frontmatter. Consider updating the page content to match the simplified description in the frontmatter for consistency.

-This is a collection of guides and tutorials to understanding and working with Supersim, including getting started, CLI reference, and chain environment.
+This is a collection of guides and tutorials to understanding and working with Supersim.
utils/metadata-batch-cli.ts (1)

236-238: Simple CLI argument parsing implemented.

The argument parsing approach is straightforward and effective for the current needs. If the CLI grows in complexity, consider using a dedicated argument parsing library like yargs or commander for more robust handling.

- const isDryRun = process.argv.includes('--dry-run')
- const isVerbose = process.argv.includes('--verbose')
+ import yargs from 'yargs'
+ const argv = yargs
+   .option('dry-run', {
+     alias: 'd',
+     description: 'Run without making changes',
+     type: 'boolean'
+   })
+   .option('verbose', {
+     alias: 'v',
+     description: 'Show detailed output',
+     type: 'boolean'
+   })
+   .help()
+   .argv
+ 
+ const isDryRun = argv['dry-run']
+ const isVerbose = argv.verbose
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c78b1f and 7c17c0a.

📒 Files selected for processing (7)
  • package.json (1 hunks)
  • pages/app-developers/interop.mdx (0 hunks)
  • pages/app-developers/tools/build/account-abstraction.mdx (1 hunks)
  • pages/app-developers/tutorials.mdx (1 hunks)
  • pages/app-developers/tutorials/supersim.mdx (1 hunks)
  • utils/metadata-batch-cli.ts (4 hunks)
  • utils/metadata-manager.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • pages/app-developers/interop.mdx
✅ Files skipped from review due to trivial changes (1)
  • pages/app-developers/tools/build/account-abstraction.mdx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.mdx`: "ALWAYS review Markdown content THOROUGHLY with ...

**/*.mdx: "ALWAYS review Markdown content THOROUGHLY with the following criteria:

  • First, check the frontmatter section at the top of the file:
    1. For regular pages, ensure ALL these fields are present and not empty:
    ---
    title: [non-empty]
    lang: [non-empty]
    description: [non-empty]
    topic: [non-empty]
    personas: [non-empty array]
    categories: [non-empty array]
    content_type: [valid type]
    ---
    1. For landing pages (index.mdx or files with ), only these fields are required:
    ---
    title: [non-empty]
    lang: [non-empty]
    description: [non-empty]
    topic: [non-empty]
    ---
    1. If any required fields are missing or empty, comment:
      'This file appears to be missing required metadata. You can fix this by running:
    pnpm metadata-batch-cli:dry "path/to/this/file.mdx"
    Review the changes, then run without :dry to apply them.'
  • Use proper nouns in place of personal pronouns like 'We' and 'Our' to maintain consistency in communal documentation.
  • Avoid gender-specific language and use the imperative form.
  • Monitor capitalization for emphasis. Avoid using all caps, italics, or bold for emphasis.
  • Ensure proper nouns are capitalized in sentences.
  • Apply the Oxford comma.
  • Use proper title case for buttons, tab names, page names, and links. Sentence case should be used for body content and short phrases, even in links.
  • Use correct spelling and grammar at all times (IMPORTANT).
  • For H1, H2, and H3 headers:
    1. Use sentence case, capitalizing only the first word.
    2. Preserve the capitalization of proper nouns, technical terms, and acronyms as defined in the 'nouns.txt' file located in the root directory of the project.
    3. Do not automatically lowercase words that appear in the 'nouns.txt' file, regardless of their position in the header.
  • Flag any headers that seem to inconsistently apply these rules for manual review.
  • When reviewing capitalization, always refer to the 'nouns.txt' file for the correct capitalization of proper nouns and technical terms specific to the project.
    "
  • pages/app-developers/tutorials.mdx
  • pages/app-developers/tutorials/supersim.mdx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - docs-optimism
  • GitHub Check: Header rules - docs-optimism
  • GitHub Check: Pages changed - docs-optimism
🔇 Additional comments (12)
utils/metadata-manager.ts (1)

121-121: Correctly implemented type-safe assignment.

This line now uses the properly processed personas variable, ensuring consistent array handling.

package.json (1)

19-19:

✅ Verification successful

Improved metadata validation process.

The script now uses the git diff command to identify changed files and passes them to the metadata batch CLI. This approach is more efficient as it only validates files that have changed.


🏁 Script executed:

#!/bin/bash
# Description: Check that metadata-batch-cli:dry exists and works as expected

# Verify that the metadata-batch-cli:dry script exists
grep "metadata-batch-cli:dry" package.json
echo "✅ metadata-batch-cli:dry script exists in package.json"

# Verify that metadata-batch-cli.ts can handle the CHANGED_FILES environment variable
grep "CHANGED_FILES" utils/metadata-batch-cli.ts || echo "⚠️ metadata-batch-cli.ts might not handle CHANGED_FILES environment variable"

Length of output: 557


Metadata Validation Process Verified

  • The updated validate-metadata script in package.json correctly uses git diff --name-only HEAD to generate a list of changed files, passing them via the CHANGED_FILES environment variable to metadata-batch-cli:dry.
  • Verification confirms that the metadata-batch-cli:dry script is defined in package.json and that utils/metadata-batch-cli.ts properly splits and filters the CHANGED_FILES environment variable.
pages/app-developers/tutorials.mdx (1)

1-16: Corrected content type classification.

The change from guide to landing-page correctly reflects the actual content type of this file, which features a collection of card links rather than a single tutorial.

The removal of the reference category is appropriate as this page primarily serves as a landing page for tutorials.

pages/app-developers/tutorials/supersim.mdx (2)

3-3: Simplified description for better clarity.

The description has been streamlined by removing redundant details, as these are already visible in the page content.


7-8:

✅ Verification successful

Standardized metadata format for personas and categories.

The metadata has been reformatted to use consistent syntax. The personas field now uses a single string instead of a YAML list, and the categories field uses an array notation.

The categories have been updated to better reflect the content focus, adding "cli" and removing "testing" and "protocol" categories.


🏁 Script executed:

#!/bin/bash
# Description: Check metadata schema validation rules for personas and categories

# Check if there's a config file defining metadata rules
fd -t f "keywords.config.yaml" || fd -t f "metadata.config.yaml" || fd -t f "*config*.yaml"

# Look for specific rules about personas and categories formats
if [ -f "keywords.config.yaml" ]; then
  echo "Checking keywords.config.yaml for metadata rules:"
  grep -A 10 "persona:" keywords.config.yaml
  grep -A 10 "categories:" keywords.config.yaml
fi

Length of output: 862


Metadata Standards for MDX File Verified

The metadata in pages/app-developers/tutorials/supersim.mdx has been updated to follow our standardized format. The change now uses a single string for the personas field (with the value "app-developer") and expresses the categories as an array. These updates align with the schema rules defined in keywords.config.yaml (which confirms "app-developer" is a valid persona and that the category constraints are met). Additionally, the updated categories—adding "cli" while removing "testing" and "protocol"—more accurately reflect the content focus.

utils/metadata-batch-cli.ts (7)

10-11: Good addition of necessary imports.

These new imports support the enhanced functionality of the CLI tool. The generateMetadata function is used in the updated main function, and globby is used for file pattern matching which is more powerful than the native glob.


179-185: Improved configuration handling with better options management.

The previous implementation likely used hardcoded values, while this update properly passes along the CLI options to the updateMetadataFile function. The change from validateOnly: true and prMode: true to false is significant as it changes behavior from validation-only mode to actual metadata updating.


240-249: Good implementation of flexible file source handling.

The code now properly handles files from multiple sources:

  1. From the CHANGED_FILES environment variable (useful for CI/CD contexts)
  2. From glob patterns passed as command line arguments

This makes the tool more versatile and integration-friendly.


251-259: Input validation and early exit look good.

The code appropriately filters for MDX files and provides a clean exit path when no files need processing. This prevents unnecessary work and provides clear feedback to the user.


263-288: Robust file processing implementation with proper error handling.

The new implementation processes each file individually with:

  1. Proper metadata generation using the imported generateMetadata function
  2. Appropriate update handling with configurable options
  3. Clear output reporting
  4. Isolated error handling that prevents a single file failure from stopping the entire process

This is a significant improvement in robustness.


290-296: Clear summary reporting with visual indicators.

The summary output uses color coding and clear statistics to help users quickly understand the results of the operation. The conditional messaging based on needsReviewCount provides appropriate feedback for different scenarios.


297-300: Improved error handling and exit code.

The top-level error handler now includes proper console formatting and sets a non-zero exit code on failure, which is important for script integration and CI/CD pipelines.

@cpengilly cpengilly merged commit 931cf9d into main Mar 4, 2025
8 checks passed
@cpengilly cpengilly deleted the app-dev-meta-fix branch March 4, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant