This repository was archived by the owner on Aug 16, 2025. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork69
added yaml editor#74
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletionsdocs/configure-coderabbit.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -10,6 +10,7 @@ sidebar_position: 3 | ||
| ```mdx-code-block | ||
| import SchemaViewer from "@site/src/components/SchemaViewer"; | ||
| import YamlEditor from "/src/components/YamlEditor/YamlEditor"; | ||
Spikatrix marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| ``` | ||
| CodeRabbit offers various configuration options to tailor the reviews to your | ||
| @@ -56,6 +57,12 @@ chat: | ||
| auto_reply: true | ||
| ``` | ||
| Write your configuration file in the below editor to validate: | ||
| ```mdx-code-block | ||
| <YamlEditor /> | ||
| ``` | ||
| The configuration file can be used to set the following options: | ||
| ```mdx-code-block | ||
42 changes: 42 additions & 0 deletionspackage-lock.json
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
1 change: 1 addition & 0 deletionspackage.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletionssrc/components/YamlEditor/YamlEditor.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| import { React, useState } from "react"; | ||
| import AceEditor from "react-ace"; | ||
| import "ace-builds/src-noconflict/theme-github"; | ||
| import "ace-builds/src-noconflict/ext-language_tools"; | ||
| import "ace-builds/webpack-resolver"; | ||
| import "ace-builds/src-noconflict/mode-yaml"; | ||
| import jsYaml from "js-yaml"; | ||
| import Ajv from "ajv"; | ||
| const ajv = new Ajv({ allErrors: true }); | ||
| import Schema from "../../../static/schema/schema.v2.json"; | ||
| export default function YamlEditor() { | ||
| const [annotations, setAnnotations] = useState([]); | ||
| const [value, setValue] = useState( | ||
| "# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json\n" | ||
| ); | ||
| const validate = ajv.compile(Schema.definitions.schema); | ||
| function getRowFromPath(path) { | ||
| // Convert path to row number (0-based) | ||
| return path.split("/").length - 1; | ||
| } | ||
| function getLineNumber(yaml, path) { | ||
| const lines = yaml.split("\n"); | ||
| const pathParts = path.split("/").filter(Boolean); | ||
| let currentObj = jsYaml.load(yaml); | ||
| let lineNumber = 0; | ||
| for (const part of pathParts) { | ||
| for (let i = lineNumber; i < lines.length; i++) { | ||
| if (lines[i].trim().startsWith(part + ":")) { | ||
| lineNumber = i; | ||
| break; | ||
| } | ||
| } | ||
| currentObj = currentObj[part]; | ||
| } | ||
| return lineNumber; | ||
| } | ||
| function onChange(newValue) { | ||
| setValue(newValue); | ||
| try { | ||
| const doc = jsYaml.load(newValue, { strict: true }); | ||
| const valid = validate(doc); | ||
| if (!valid && validate.errors) { | ||
| setAnnotations( | ||
| validate.errors.map((err) => ({ | ||
| row: err.instancePath | ||
| ? getLineNumber(newValue, err.instancePath) | ||
| : 0, | ||
| column: 0, | ||
| text: `${err.keyword}: ${err.message} ${ | ||
| err?.params?.allowedValues | ||
| ? `Allowed values: ${err.params.allowedValues.join(", ")}` | ||
| : "" | ||
| }`, | ||
| type: "error", | ||
| })) | ||
| ); | ||
| } else { | ||
| setAnnotations([]); | ||
| } | ||
| } catch (err) { | ||
| setAnnotations([ | ||
| { | ||
| row: err.instancePath ? getLineNumber(newValue, err.instancePath) : 0, | ||
| column: 0, | ||
| text: | ||
| `${err.keyword}: ${err.message} ${ | ||
| err?.params?.allowedValues | ||
| ? `Allowed values: ${err.params.allowedValues.join(", ")}` | ||
| : "" | ||
| }` || "YAML parsing error", | ||
| type: "error", | ||
| }, | ||
| ]); | ||
| } | ||
| } | ||
| return ( | ||
| <AceEditor | ||
| mode="yaml" | ||
| theme="github" | ||
| onChange={onChange} | ||
| value={value} | ||
| name="yaml-editor" | ||
| editorProps={{ $blockScrolling: true }} | ||
| setOptions={{ | ||
| useWorker: false, | ||
| showPrintMargin: false, | ||
| showGutter: true, | ||
| }} | ||
| annotations={annotations} | ||
| width="100%" | ||
| height="400px" | ||
| /> | ||
| ); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.