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
Feature yaml editor#76
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
9 commits Select commitHold shift + click to select a range
e2aa43e added yaml editor
cr-ruhanmuzaffar88a5b71 name fix
cr-ruhanmuzaffar6540733 moved component to one code block
cr-ruhanmuzaffar8e2c75c removed logs
cr-ruhanmuzaffar05f12c2 fix: yaml editor
cr-ruhanmuzaffardc6eb70 Merge branch 'main' into feature-yaml-editor
cr-ruhanmuzaffarf916e2e fix: reviews
cr-ruhanmuzaffarf15190a new line
cr-ruhanmuzaffar1321e40 fix: merge fix
cr-ruhanmuzaffarFile 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
18 changes: 0 additions & 18 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 |
|---|---|---|
| @@ -39,24 +39,6 @@ You can add a `.coderabbit.yaml` configuration file to the root of your | ||
| repositories. Below is a sample YAML file that can be used as a starting point | ||
| and changed as needed: | ||
| Write your configuration file in the below editor to validate: | ||
Spikatrix marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| ```mdx-code-block | ||
103 changes: 0 additions & 103 deletionssrc/components/YamlEditor/YamlEditor.jsx
This file was deleted.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
160 changes: 160 additions & 0 deletionssrc/components/YamlEditor/YamlEditor.tsx
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,160 @@ | ||
| import React, { useState, useEffect } 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"; | ||
| const validate = ajv.compile(Schema.definitions.schema); | ||
| const initialValue = `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json | ||
| language: "en-US" | ||
| early_access: false | ||
| reviews: | ||
| profile: "chill" | ||
| request_changes_workflow: false | ||
| high_level_summary: true | ||
| poem: true | ||
| review_status: true | ||
| collapse_walkthrough: false | ||
| auto_review: | ||
| enabled: true | ||
| drafts: false | ||
| chat: | ||
| auto_reply: true | ||
| `; | ||
| export default function YamlEditor() { | ||
| const [value, setValue] = useState(initialValue); | ||
| const [annotations, setAnnotations] = useState([]); | ||
| useEffect(() => { | ||
| setValue(initialValue); | ||
| validateAndSetAnnotations(initialValue); | ||
| }, []); | ||
| function validateAndSetAnnotations(yaml) { | ||
| try { | ||
| const doc = jsYaml.load(yaml, { strict: true }); | ||
| const isValid = validate(doc); | ||
| if (!isValid && validate.errors) { | ||
| setAnnotations( | ||
| validate.errors.map((err) => { | ||
| const instancePathArr = err?.instancePath?.split("/"); | ||
| const key = | ||
| instancePathArr && instancePathArr[instancePathArr.length - 1]; | ||
| return { | ||
| row: err.instancePath ? getLineNumber(yaml, err.instancePath) : 0, | ||
| column: 0, | ||
| text: `${key}: ${err.message} ${ | ||
| err?.params?.allowedValues | ||
| ? `Allowed values: ${err.params.allowedValues.join(", ")}` | ||
| : "" | ||
| }`, | ||
| type: "error", | ||
| }; | ||
| }) | ||
| ); | ||
| } else { | ||
| setAnnotations([]); | ||
| } | ||
| } catch (err) { | ||
| const instancePathArr = err?.instancePath?.split("/"); | ||
| const key = | ||
| instancePathArr && instancePathArr[instancePathArr.length - 1]; | ||
| setAnnotations([ | ||
| { | ||
| row: err.instancePath ? getLineNumber(yaml, err.instancePath) : 0, | ||
| column: 0, | ||
| text: | ||
| `${key}: ${err.message} ${ | ||
| err?.params?.allowedValues | ||
| ? `Allowed values: ${err.params.allowedValues.join(", ")}` | ||
| : "" | ||
| }` || "YAML parsing error", | ||
| type: "error", | ||
| }, | ||
| ]); | ||
| } | ||
| } | ||
| function getLineNumber(yaml, instancePath) { | ||
| const lines = yaml.split("\n"); | ||
| const pathParts = instancePath.split("/").filter(Boolean); | ||
| let currentObj = jsYaml.load(yaml); | ||
| let lineNumber = 0; | ||
| const lastPathPart = pathParts[pathParts.length - 1]; | ||
| const lastPathPartIndex = pathParts.length - 1; | ||
| for (let i = 0; i < lines.length; i++) { | ||
| if (lines[i].trim().startsWith(pathParts[0] + ":")) { | ||
| // Found the top-level field | ||
| lineNumber = i; | ||
| currentObj = currentObj[pathParts[0]]; | ||
| for (let j = 1; j < lastPathPartIndex; j++) { | ||
| // Go through the nested fields | ||
| for (let k = lineNumber + 1; k < lines.length; k++) { | ||
| if (lines[k].trim().startsWith(pathParts[j] + ":")) { | ||
| lineNumber = k; | ||
| currentObj = currentObj[pathParts[j]]; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| // look for the last path part with array syntax as well as object syntax | ||
| for (let l = lineNumber + 1; l < lines.length; l++) { | ||
| if (lines[l].trim().startsWith(`- ${lastPathPart}:`)) { | ||
| lineNumber = l; | ||
| break; | ||
| } else if (lines[l].trim().startsWith(lastPathPart + ":")) { | ||
| lineNumber = l; | ||
| break; | ||
| } | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| return lineNumber; | ||
| } | ||
| function onChange(newValue) { | ||
| setValue(newValue); | ||
| validateAndSetAnnotations(newValue); | ||
| } | ||
| return ( | ||
| <div className="m4"> | ||
| <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" | ||
| /> | ||
| <br /> | ||
| </div> | ||
| ); | ||
| } |
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.