-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Automating the docs generation using husky (for develop-postgres), follow up to PR #2851 #3111
Automating the docs generation using husky (for develop-postgres), follow up to PR #2851 #3111
Conversation
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including You can disable this status message by setting the WalkthroughThis pull request updates documentation and ignore configurations. It modifies the ignore arrays in both the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant P as Package Scripts
participant T as Typedoc
participant F as fix-readme-links.js
U->>P: Run "generate-docs" script
P->>T: Execute Typedoc to generate docs
T-->>P: Return generated documentation
P->>P: Run "postgenerate-docs" to remove README.md files
P->>F: Execute fix-readme-links.js script
F-->>P: Process and update Markdown links
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop-postgres #3111 +/- ##
====================================================
- Coverage 39.88% 39.85% -0.03%
====================================================
Files 453 454 +1
Lines 33273 33293 +20
Branches 397 397
====================================================
Hits 13270 13270
- Misses 20003 20023 +20 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
biome.jsonc
(1 hunks)docs/.gitignore
(1 hunks)docs/sidebars.ts
(1 hunks)fix-readme-links.js
(1 hunks)package.json
(3 hunks)tsconfig.docs.json
(1 hunks)typedoc.json
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Run tests for talawa api
- GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (6)
docs/sidebars.ts (1)
33-34
: LGTM! Changes align with documentation automation objectives.The category label and directory path updates correctly reflect the new schema documentation structure.
biome.jsonc (1)
19-20
: LGTM! Ignore paths correctly updated.The addition of
"./docs/docs/docs/schema"
to the ignore list is appropriate for the documentation automation workflow.docs/.gitignore (1)
17-17
: LGTM! GitIgnore pattern correctly added.The addition of
docs/docs/schema/*
aligns with the documentation automation changes and matches the biome.jsonc configuration.tsconfig.docs.json (1)
1-25
: TypeScript Docs Configuration Looks SolidThe new
tsconfig.docs.json
file properly extends the base configuration and tweaks compiler options for documentation generation. Key options like"noEmit": true
and relaxed strictness ensure that the source code is correctly processed by TypeDoc without emitting build artifacts, while theinclude
andexclude
arrays are well-tailored to focus on the source files and omit tests and non-code files.typedoc.json (1)
1-27
: TypeDoc Configuration Effectively Set for Schema DocumentationThe configuration directs TypeDoc to output the generated documentation to
docs/docs/docs/schema
and leveragestypedoc-plugin-markdown
with the Markdown theme. Excluding private, protected, and external members, along with cleaning the output directory before generation, aligns well with generating concise and focused schema documentation. Ensure that the chosen directory hierarchy is intentional and fits within your project’s documentation structure.package.json (1)
49-50
: New TypeDoc Dependencies AddedThe addition of
"typedoc": "^0.27.6"
and"typedoc-plugin-markdown": "^4.4.1"
intodevDependencies
appears correct. These dependencies support the documentation generation setup defined in your new configuration files. It might be worth periodically verifying these versions for updates or known issues.
fix-readme-links.js
Outdated
import fs from "node:fs"; | ||
import path from "node:path"; | ||
|
||
const docsDir = path.resolve("./docs/docs/docs/schema"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Consider making the docs directory path configurable.
The hardcoded path "./docs/docs/docs/schema"
should be made configurable through environment variables or command-line arguments for better flexibility and reusability.
-const docsDir = path.resolve("./docs/docs/docs/schema");
+const docsDir = path.resolve(process.env.DOCS_DIR || "./docs/docs/docs/schema");
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const docsDir = path.resolve("./docs/docs/docs/schema"); | |
const docsDir = path.resolve(process.env.DOCS_DIR || "./docs/docs/docs/schema"); |
fix-readme-links.js
Outdated
function replaceLinks(dir) { | ||
const files = fs.readdirSync(dir); | ||
for (const file of files) { | ||
const filePath = path.join(dir, file); | ||
if (fs.lstatSync(filePath).isDirectory()) { | ||
replaceLinks(filePath); | ||
} else if (file.endsWith(".md")) { | ||
let content = fs.readFileSync(filePath, "utf8"); | ||
|
||
// Replace any README.md links with root directory ("/") | ||
content = content.replace(/\[.*?\]\((.*?)README\.md\)/g, (match) => { | ||
return "[Admin Docs](/)"; // Redirect broken links to the root | ||
}); | ||
|
||
fs.writeFileSync(filePath, content, "utf8"); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling and logging for file operations.
The function lacks error handling for file system operations and logging for tracking progress. This could make debugging issues difficult in production.
function replaceLinks(dir) {
+ try {
const files = fs.readdirSync(dir);
+ console.log(`Processing directory: ${dir}`);
for (const file of files) {
const filePath = path.join(dir, file);
if (fs.lstatSync(filePath).isDirectory()) {
replaceLinks(filePath);
} else if (file.endsWith(".md")) {
+ console.log(`Processing file: ${filePath}`);
let content = fs.readFileSync(filePath, "utf8");
// Replace any README.md links with root directory ("/")
content = content.replace(/\[.*?\]\((.*?)README\.md\)/g, (match) => {
+ console.log(`Replacing README.md link in ${filePath}`);
return "[Admin Docs](/)"; // Redirect broken links to the root
});
fs.writeFileSync(filePath, content, "utf8");
}
}
+ } catch (error) {
+ console.error(`Error processing directory ${dir}:`, error);
+ process.exit(1);
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
function replaceLinks(dir) { | |
const files = fs.readdirSync(dir); | |
for (const file of files) { | |
const filePath = path.join(dir, file); | |
if (fs.lstatSync(filePath).isDirectory()) { | |
replaceLinks(filePath); | |
} else if (file.endsWith(".md")) { | |
let content = fs.readFileSync(filePath, "utf8"); | |
// Replace any README.md links with root directory ("/") | |
content = content.replace(/\[.*?\]\((.*?)README\.md\)/g, (match) => { | |
return "[Admin Docs](/)"; // Redirect broken links to the root | |
}); | |
fs.writeFileSync(filePath, content, "utf8"); | |
} | |
} | |
} | |
function replaceLinks(dir) { | |
try { | |
const files = fs.readdirSync(dir); | |
console.log(`Processing directory: ${dir}`); | |
for (const file of files) { | |
const filePath = path.join(dir, file); | |
if (fs.lstatSync(filePath).isDirectory()) { | |
replaceLinks(filePath); | |
} else if (file.endsWith(".md")) { | |
console.log(`Processing file: ${filePath}`); | |
let content = fs.readFileSync(filePath, "utf8"); | |
// Replace any README.md links with root directory ("/") | |
content = content.replace(/\[.*?\]\((.*?)README\.md\)/g, (match) => { | |
console.log(`Replacing README.md link in ${filePath}`); | |
return "[Admin Docs](/)"; // Redirect broken links to the root | |
}); | |
fs.writeFileSync(filePath, content, "utf8"); | |
} | |
} | |
} catch (error) { | |
console.error(`Error processing directory ${dir}:`, error); | |
process.exit(1); | |
} | |
} |
fix-readme-links.js
Outdated
content = content.replace(/\[.*?\]\((.*?)README\.md\)/g, (match) => { | ||
return "[Admin Docs](/)"; // Redirect broken links to the root | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Improve link replacement regex pattern.
The current regex pattern might be too broad and could potentially match unwanted patterns. Consider making it more specific to avoid false positives.
-content = content.replace(/\[.*?\]\((.*?)README\.md\)/g, (match) => {
- return "[Admin Docs](/)"; // Redirect broken links to the root
+content = content.replace(/\[([^\]]+)\]\((?:\.\.\/)*README\.md\)/g, (match, linkText) => {
+ return `[Admin Docs](/)`; // Preserve original link text if needed
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
content = content.replace(/\[.*?\]\((.*?)README\.md\)/g, (match) => { | |
return "[Admin Docs](/)"; // Redirect broken links to the root | |
}); | |
content = content.replace(/\[([^\]]+)\]\((?:\.\.\/)*README\.md\)/g, (match, linkText) => { | |
return `[Admin Docs](/)`; // Preserve original link text if needed | |
}); |
package.json
Outdated
"postgenerate-docs": "find docs/docs/docs/schema -name 'README.md' -delete", | ||
"generate-docs" : "typedoc && npm run postgenerate-docs && node fix-readme-links.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Doc Generation Scripts Integration
The new scripts "postgenerate-docs"
and "generate-docs"
streamline the automated docs generation workflow. However, note that using the Unix find
command (as in "postgenerate-docs": "find docs/docs/docs/schema -name 'README.md' -delete"
) can create cross-platform compatibility issues on Windows environments. If cross-platform support is a goal, consider alternative solutions such as a Node.js script or utilities like rimraf
.
Now, Shall I add the |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Rename the schema directory
auto-schema
to make it very clear that the files there are automatically generated. - Make coderabbit.ai approve your changes
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
There was a problem hiding this 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
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
docs/.gitignore
(1 hunks)fix-readme-links.js
(1 hunks)package.json
(3 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
fix-readme-links.js
[error] 21-21: Do not use template literals if interpolation and special-character handling are not needed.
Unsafe fix: Replace with string literal
(lint/style/noUnusedTemplateLiteral)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Analyse Code With CodeQL (typescript)
🔇 Additional comments (2)
package.json (1)
51-52
: Verify TypeDoc version compatibility.The TypeDoc version
^0.27.6
is quite old compared to the current stable version. Consider updating to the latest version for better compatibility and features.✅ Verification successful
TypeDoc Version is Up-to-Date Stable Release
- The output confirms that version
0.27.6
is still the latest stable release.- The versions labeled
1.0.0-dev.*
are development builds and not considered the stable release.- No update is necessary unless you require features from the development versions.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check latest TypeDoc version and compatibility npm show typedoc versions --json | jq -r '.[-5:]' npm show typedoc@latest dependenciesLength of output: 299
docs/.gitignore (1)
17-17
: Ensure Auto-Generated Schema Docs are Properly IgnoredThe addition of the ignore pattern
docs/docs/auto-schema/*
will prevent auto-generated schema documents from being tracked. Please verify that your documentation generation scripts (and Husky hook configuration) output files to this directory. Also, double-check consistency with other documentation paths (e.g., those referenced in your sidebar configuration or intypedoc.json
) to ensure there is no unintended discrepancy.
function replaceLinks(dir) { | ||
try | ||
{ | ||
const files = fs.readdirSync(dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add file system error handling for individual operations.
The code only has a top-level try-catch but doesn't handle individual file operation errors that could occur during readdirSync
or writeFileSync
.
-const files = fs.readdirSync(dir);
+let files;
+try {
+ files = fs.readdirSync(dir);
+} catch (err) {
+ console.error(`Failed to read directory ${dir}:`, err);
+ throw err;
+}
-fs.writeFileSync(filePath, content, "utf8");
+try {
+ fs.writeFileSync(filePath, content, "utf8");
+} catch (err) {
+ console.error(`Failed to write file ${filePath}:`, err);
+ throw err;
+}
Also applies to: 24-24
content = content.replace(/\[([^\]]+)\]\((?:\.\.\/)*README\.md\)/g, (match, linkText) => { | ||
console.log(`Replacing README.md link in ${filePath}`); | ||
return `[Admin Docs](/)`; // Preserve original link text if needed | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Consider preserving the original link text.
The link replacement discards the original link text, which might contain useful context. Consider preserving it instead of using a static "Admin Docs" text.
-return `[Admin Docs](/)`; // Preserve original link text if needed
+return `[${linkText}](/)`; // Preserve the original link text
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
content = content.replace(/\[([^\]]+)\]\((?:\.\.\/)*README\.md\)/g, (match, linkText) => { | |
console.log(`Replacing README.md link in ${filePath}`); | |
return `[Admin Docs](/)`; // Preserve original link text if needed | |
}); | |
content = content.replace(/\[([^\]]+)\]\((?:\.\.\/)*README\.md\)/g, (match, linkText) => { | |
console.log(`Replacing README.md link in ${filePath}`); | |
return `[${linkText}](/)`; // Preserve the original link text | |
}); |
🧰 Tools
🪛 Biome (1.9.4)
[error] 21-21: Do not use template literals if interpolation and special-character handling are not needed.
Unsafe fix: Replace with string literal
(lint/style/noUnusedTemplateLiteral)
} | ||
catch(err) | ||
{ | ||
console.error(`Error processing directory ${dir}:`, error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the undefined variable reference.
There's a reference to an undefined variable error
in the error logging. The caught error is named err
.
-console.error(`Error processing directory ${dir}:`, error);
+console.error(`Error processing directory ${dir}:`, err);
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
console.error(`Error processing directory ${dir}:`, error); | |
try { | |
// ... (other code) | |
} catch (err) { | |
- console.error(`Error processing directory ${dir}:`, error); | |
+ console.error(`Error processing directory ${dir}:`, err); | |
} |
"postgenerate-docs": "rimraf docs/docs/docs/schema/README.md", | ||
"generate-docs" : "typedoc && npm run postgenerate-docs && node fix-readme-links.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
💡 Codebase verification
Integrate Documentation Generation into Pre-Commit Hook
The husky pre-commit hook is currently missing, confirming that the docs generation isn’t automated on commit. To align with the PR's objectives and ensure up-to-date documentation, consider creating and configuring the pre-commit hook accordingly.
- Create a
.husky/pre-commit
file. - Add the
npm run generate-docs
command (or an equivalent script) to automate documentation updates. - Ensure the new hook integrates smoothly with existing workflows and maintains cross-platform compatibility.
🔗 Analysis chain
Consider adding documentation generation to the pre-commit hook.
Based on the PR objectives mentioning husky integration, the docs generation scripts should be integrated with the pre-commit hook to automate documentation updates.
Let's verify the current pre-commit configuration:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if husky pre-commit hook exists and its current configuration
if [ -f .husky/pre-commit ]; then
cat .husky/pre-commit
else
echo "No pre-commit hook found"
fi
Length of output: 89
🛠️ Refactor suggestion
Ensure script order is correct.
The postgenerate-docs
script is named to run automatically after generate-docs
, but it's explicitly called in the generate-docs
script. This could lead to the script running twice.
-"postgenerate-docs": "rimraf docs/docs/docs/schema/README.md",
-"generate-docs" : "typedoc && npm run postgenerate-docs && node fix-readme-links.js",
+"clean-docs": "rimraf docs/docs/docs/schema/README.md",
+"generate-docs" : "typedoc && npm run clean-docs && node fix-readme-links.js",
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"postgenerate-docs": "rimraf docs/docs/docs/schema/README.md", | |
"generate-docs" : "typedoc && npm run postgenerate-docs && node fix-readme-links.js", | |
"clean-docs": "rimraf docs/docs/docs/schema/README.md", | |
"generate-docs" : "typedoc && npm run clean-docs && node fix-readme-links.js", |
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
Our Pull Request Approval ProcessThanks for contributing! Testing Your CodeRemember, your PRs won't be reviewed until these criteria are met:
Our policies make our code better. ReviewersDo not assign reviewers. Our Queue Monitors will review your PR and assign them.
Reviewing Your CodeYour reviewer(s) will have the following roles:
CONTRIBUTING.mdRead our CONTRIBUTING.md file. Most importantly:
Other
|
I tried reinstalling pnpm packages still these tests are failing. |
|
What kind of change does this PR introduce?
Feature
Issue Number:
Fixes #2818
Snapshots/Videos:
If relevant, did you update the documentation?
Not sure.
Summary
Auto-generating the schema docs in
/docs/docs/docs/schema
.Does this PR introduce a breaking change?
NA
Checklist
CodeRabbit AI Review
Test Coverage
Other information
NA
Have you read the contributing guide?
Yes
Summary by CodeRabbit
Release Notes
Chores
Documentation
Build
New Features
These changes enhance project development processes and documentation, providing better clarity and workflow management.
Summary by CodeRabbit