Feat/repository card#74
Conversation
|
Warning Review limit reached
More reviews will be available in 15 minutes and 8 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (20)
📝 WalkthroughWalkthroughA new ChangesGitHub Repository Card Preprocessor
Sequence Diagram(s)sequenceDiagram
rect rgba(173, 216, 230, 0.5)
Note over mdBook,stdout: Build-time preprocessing
mdBook->>GithubRepositoryCard: spawn (cargo run)
mdBook->>stdin: write JSON(context, book)
GithubRepositoryCard->>GithubRepositoryCard: extract username/repository from config
GithubRepositoryCard->>GithubRepositoryCard: render HTML and regex-replace --- markers
GithubRepositoryCard->>stdout: write processed book JSON
end
rect rgba(144, 238, 144, 0.5)
Note over Browser,GitHubAPI: Runtime card population
Browser->>github-card.js: page load
github-card.js->>github-card.js: querySelectorAll(.github-repo-box)
github-card.js->>GitHubAPI: GET /repos/{data-repo}
GitHubAPI-->>github-card.js: name, description, stars, forks, issues, language
github-card.js->>GitHubAPI: GET /repos/{data-repo}/commits?per_page=1
GitHubAPI-->>github-card.js: commits + Link header
github-card.js->>Browser: populate card DOM fields and apply language color
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@mdbook-repository-card/src/main.rs`:
- Around line 103-121: Replace the generic regex pattern `r"---"` in the
Regex::new call with a dedicated placeholder token that is unlikely to appear in
normal markdown content, such as a unique marker like `r"<!--
REPOSITORY_CARD_PLACEHOLDER -->"` or similar. Then ensure that the HTML card
injection only happens when this specific placeholder is encountered, rather
than replacing all markdown separators. This prevents unintended card insertion
on normal `---` separators that may already exist in chapter content.
In `@theme/github-box.css`:
- Around line 40-41: In the dark-mode block of the github-box.css file,
Stylelint requires an empty line between custom property declarations and
regular CSS properties. Add a blank line between the --gh-btn-hover custom
property declaration and the box-shadow property to comply with the spacing
rules. This separation helps maintain consistent formatting between custom
properties and standard properties.
In `@theme/github-card.js`:
- Around line 6-8: The fetch call to the GitHub API endpoint does not validate
the HTTP response status before processing the response body. Add a status check
in the first .then() handler after fetching from the GitHub API to verify that
res.ok is true, and if not, throw an error or reject the promise so that error
responses (like 403 or 404) are caught before attempting to parse the JSON and
access data properties. This prevents partial or broken card states when the API
returns error responses.
- Line 44: The commits link in the querySelector for ".link-commits" hardcodes
the branch name as "main", which will fail for repositories with different
default branches. Instead of hardcoding the string "main" in the href
assignment, access the default branch from the data object (which should contain
`default_branch` property from the GitHub API) and use that value dynamically in
the URL to ensure the link works for any repository regardless of its default
branch name.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: cd6616ed-6b06-4ab4-be32-fe12ca90266a
📒 Files selected for processing (9)
LearnixOSbook.tomlmdbook-gh-issue-previewmdbook-repository-card/Cargo.tomlmdbook-repository-card/rustfmt.tomlmdbook-repository-card/src/main.rssrc/ch02-03-implementing-the-bitfields-proc-macro.mdtheme/github-box.csstheme/github-card.js
| --gh-btn-hover: #30363d; | ||
| box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5); |
There was a problem hiding this comment.
Fix the Stylelint spacing violation in the dark-mode block.
Stylelint expects an empty line before Line 41 (box-shadow) after the custom property declarations.
💡 Proposed fix
html.coal .github-repo-box,
html.navy .github-repo-box,
html.ayu .github-repo-box {
@@
--gh-btn-border: rgba(240, 246, 252, 0.1);
--gh-btn-hover: `#30363d`;
+
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5);
}📝 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.
| --gh-btn-hover: #30363d; | |
| box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5); | |
| html.coal .github-repo-box, | |
| html.navy .github-repo-box, | |
| html.ayu .github-repo-box { | |
| --gh-btn-border: rgba(240, 246, 252, 0.1); | |
| --gh-btn-hover: `#30363d`; | |
| box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5); | |
| } |
🧰 Tools
🪛 Stylelint (17.13.0)
[error] 41-41: Expected empty line before declaration (declaration-empty-line-before)
(declaration-empty-line-before)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@theme/github-box.css` around lines 40 - 41, In the dark-mode block of the
github-box.css file, Stylelint requires an empty line between custom property
declarations and regular CSS properties. Add a blank line between the
--gh-btn-hover custom property declaration and the box-shadow property to comply
with the spacing rules. This separation helps maintain consistent formatting
between custom properties and standard properties.
Source: Linters/SAST tools
| fetch(`https://api.github.com/repos/${repoPath}`) | ||
| .then((res) => res.json()) | ||
| .then((data) => { |
There was a problem hiding this comment.
Guard the repo metadata fetch with an HTTP status check.
Without checking res.ok, API error responses (e.g., 403/404) enter the success path and then fail on property access, leaving partial/broken card state.
💡 Proposed fix
- fetch(`https://api.github.com/repos/${repoPath}`)
- .then((res) => res.json())
+ fetch(`https://api.github.com/repos/${repoPath}`)
+ .then((res) => {
+ if (!res.ok) throw new Error(`Repository fetch failed: ${res.status}`);
+ return res.json();
+ })
.then((data) => {📝 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.
| fetch(`https://api.github.com/repos/${repoPath}`) | |
| .then((res) => res.json()) | |
| .then((data) => { | |
| fetch(`https://api.github.com/repos/${repoPath}`) | |
| .then((res) => { | |
| if (!res.ok) throw new Error(`Repository fetch failed: ${res.status}`); | |
| return res.json(); | |
| }) | |
| .then((data) => { |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@theme/github-card.js` around lines 6 - 8, The fetch call to the GitHub API
endpoint does not validate the HTTP response status before processing the
response body. Add a status check in the first .then() handler after fetching
from the GitHub API to verify that res.ok is true, and if not, throw an error or
reject the promise so that error responses (like 403 or 404) are caught before
attempting to parse the JSON and access data properties. This prevents partial
or broken card states when the API returns error responses.
| box.querySelector(".link-stars").href = `${data.html_url}/stargazers`; | ||
| box.querySelector(".link-forks").href = | ||
| `${data.html_url}/network/members`; | ||
| box.querySelector(".link-commits").href = `${data.html_url}/commits/main`; |
There was a problem hiding this comment.
Do not hardcode main in the commits link.
Line 44 will produce a wrong/broken link for repositories whose default branch is not main.
💡 Proposed fix
- box.querySelector(".link-commits").href = `${data.html_url}/commits/main`;
+ box.querySelector(".link-commits").href = `${data.html_url}/commits`;🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@theme/github-card.js` at line 44, The commits link in the querySelector for
".link-commits" hardcodes the branch name as "main", which will fail for
repositories with different default branches. Instead of hardcoding the string
"main" in the href assignment, access the default branch from the data object
(which should contain `default_branch` property from the GitHub API) and use
that value dynamically in the URL to ensure the link works for any repository
regardless of its default branch name.
Summary by CodeRabbit