feat: add --comments flag to include Google Docs comments#4
Conversation
… output Fetches comments via the Google Drive Comments API and appends them as a ## Comments section at the end of the markdown output. Includes quoted text, author, date, resolved status, and replies. - Add internal/gdocs/comments.go for fetching comments via Drive API - Add internal/markdown/comments.go for rendering comments as markdown - Add --comments CLI flag - Add drive.readonly OAuth scope - Add tests for comment rendering and time formatting - Update README with usage docs and scope requirements Closes #2 Amp-Thread-ID: https://ampcode.com/threads/T-019c54ce-f0ae-76e3-87fe-06b9a3e2c02f Co-authored-by: Amp <amp@ampcode.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughAdds optional Google Drive comment inclusion to the CLI conversion flow: new Changes
Sequence DiagramsequenceDiagram
participant User as User/CLI
participant Main as Main (cmd/gdocs-cli)
participant Docs as Docs Service
participant Drive as Drive API
participant Converter as Converter
participant Renderer as Comment Renderer
User->>Main: Run CLI with --comments
Main->>Docs: Fetch document content
Docs-->>Main: Document
alt includeComments == true
Main->>Drive: FetchComments(docID) (Drive API, paginated)
Drive-->>Main: []Comment (with Replies)
Main->>Converter: SetComments(comments)
end
Main->>Converter: Convert(document body)
Converter->>Renderer: ConvertComments(comments)
Renderer-->>Converter: Markdown comments section
Converter-->>Main: Final Markdown (body + comments)
Main-->>User: Output markdown
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 2❌ Failed checks (2 warnings)
✅ 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: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
README.md (1)
296-313:⚠️ Potential issue | 🟡 MinorProject structure is missing new files.
The tree listing doesn't include the new
comments.gofiles underinternal/gdocs/andinternal/markdown/, norcomments_test.go. Consider updating it to reflect the current structure.
🤖 Fix all issues with AI agents
In `@internal/gdocs/comments.go`:
- Around line 39-43: In FetchComments, the API call created via
srv.Comments.List is executed with call.Do() but doesn't propagate the
function's ctx; update the code to attach the context to the request (use
call.Context(ctx) on the existing call variable before calling call.Do()) while
preserving the PageSize/PageToken logic so cancellations and deadlines are
honored.
In `@internal/markdown/comments.go`:
- Around line 17-18: The "## Comments" heading is being appended directly to the
body without a preceding blank line, so update the logic in ConvertComments (the
builder using the strings.Builder variable named builder) to prepend a newline
before the heading (i.e., ensure the heading is written as "\n## Comments\n\n"
or otherwise guarantees a blank line separator) so the comments section is
separated from the preceding content.
In `@README.md`:
- Line 242: Update the stale README note that currently reads "Author and dates
require Google Drive API (not implemented in this version)" to reflect that the
Drive API is now integrated for comments: change the line to indicate that
Google Drive API is used for comments but that document-level metadata (author
and dates/frontmatter) is still not implemented; ensure the updated sentence
explicitly mentions "comments via Drive API are supported" and "author/dates in
frontmatter are not yet extracted" so readers know the exact current capability.
🧹 Nitpick comments (2)
internal/auth/oauth.go (1)
23-24:drive.readonlyscope is always requested, even without--comments.The new scope is unconditionally included in the OAuth config. This means all users (including those who never use
--comments) will be asked to grant Drive read-only access. Consider whether this broad permission request is intentional, or if you'd prefer to conditionally add the scope only when--commentsis used — though that would complicate auth and token management.As-is, this is a reasonable trade-off for simplicity, but worth a conscious decision.
Also applies to: 42-42
internal/markdown/comments.go (1)
27-39: Author names containing**would break bold markdown formatting.If a Google account display name contains
**or other markdown syntax, the output would be malformed. This is low-risk since Google display names rarely contain such characters, but a simple escape (replacing*with\*) would make this robust.
| var builder strings.Builder | ||
| builder.WriteString("## Comments\n\n") |
There was a problem hiding this comment.
Missing newline separator before the ## Comments heading.
ConvertComments is appended directly after the body content in converter.go. If the body doesn't end with a blank line, the heading will run into the last paragraph. Prepend a newline to ensure clean separation.
Proposed fix
var builder strings.Builder
+builder.WriteString("\n")
builder.WriteString("## Comments\n\n")📝 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.
| var builder strings.Builder | |
| builder.WriteString("## Comments\n\n") | |
| var builder strings.Builder | |
| builder.WriteString("\n") | |
| builder.WriteString("## Comments\n\n") |
🤖 Prompt for AI Agents
In `@internal/markdown/comments.go` around lines 17 - 18, The "## Comments"
heading is being appended directly to the body without a preceding blank line,
so update the logic in ConvertComments (the builder using the strings.Builder
variable named builder) to prepend a newline before the heading (i.e., ensure
the heading is written as "\n## Comments\n\n" or otherwise guarantees a blank
line separator) so the comments section is separated from the preceding content.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In @.agents/skills/gh-cli/SKILL.md:
- Around line 70-265: The fenced ASCII CLI structure block starting with the
line "gh # Root command" uses a bare code fence; update
the opening fence from ``` to ```text to provide a language hint (leave the
block contents unchanged and keep the closing fence as ```), which will satisfy
markdownlint MD040.
.agents/skills/gh-cli/SKILL.md
Outdated
| ``` | ||
| gh # Root command | ||
| ├── auth # Authentication | ||
| │ ├── login | ||
| │ ├── logout | ||
| │ ├── refresh | ||
| │ ├── setup-git | ||
| │ ├── status | ||
| │ ├── switch | ||
| │ └── token | ||
| ├── browse # Open in browser | ||
| ├── codespace # GitHub Codespaces | ||
| │ ├── code | ||
| │ ├── cp | ||
| │ ├── create | ||
| │ ├── delete | ||
| │ ├── edit | ||
| │ ├── jupyter | ||
| │ ├── list | ||
| │ ├── logs | ||
| │ ├── ports | ||
| │ ├── rebuild | ||
| │ ├── ssh | ||
| │ ├── stop | ||
| │ └── view | ||
| ├── gist # Gists | ||
| │ ├── clone | ||
| │ ├── create | ||
| │ ├── delete | ||
| │ ├── edit | ||
| │ ├── list | ||
| │ ├── rename | ||
| │ └── view | ||
| ├── issue # Issues | ||
| │ ├── create | ||
| │ ├── list | ||
| │ ├── status | ||
| │ ├── close | ||
| │ ├── comment | ||
| │ ├── delete | ||
| │ ├── develop | ||
| │ ├── edit | ||
| │ ├── lock | ||
| │ ├── pin | ||
| │ ├── reopen | ||
| │ ├── transfer | ||
| │ ├── unlock | ||
| │ └── view | ||
| ├── org # Organizations | ||
| │ └── list | ||
| ├── pr # Pull Requests | ||
| │ ├── create | ||
| │ ├── list | ||
| │ ├── status | ||
| │ ├── checkout | ||
| │ ├── checks | ||
| │ ├── close | ||
| │ ├── comment | ||
| │ ├── diff | ||
| │ ├── edit | ||
| │ ├── lock | ||
| │ ├── merge | ||
| │ ├── ready | ||
| │ ├── reopen | ||
| │ ├── revert | ||
| │ ├── review | ||
| │ ├── unlock | ||
| │ ├── update-branch | ||
| │ └── view | ||
| ├── project # Projects | ||
| │ ├── close | ||
| │ ├── copy | ||
| │ ├── create | ||
| │ ├── delete | ||
| │ ├── edit | ||
| │ ├── field-create | ||
| │ ├── field-delete | ||
| │ ├── field-list | ||
| │ ├── item-add | ||
| │ ├── item-archive | ||
| │ ├── item-create | ||
| │ ├── item-delete | ||
| │ ├── item-edit | ||
| │ ├── item-list | ||
| │ ├── link | ||
| │ ├── list | ||
| │ ├── mark-template | ||
| │ ├── unlink | ||
| │ └── view | ||
| ├── release # Releases | ||
| │ ├── create | ||
| │ ├── list | ||
| │ ├── delete | ||
| │ ├── delete-asset | ||
| │ ├── download | ||
| │ ├── edit | ||
| │ ├── upload | ||
| │ ├── verify | ||
| │ ├── verify-asset | ||
| │ └── view | ||
| ├── repo # Repositories | ||
| │ ├── create | ||
| │ ├── list | ||
| │ ├── archive | ||
| │ ├── autolink | ||
| │ ├── clone | ||
| │ ├── delete | ||
| │ ├── deploy-key | ||
| │ ├── edit | ||
| │ ├── fork | ||
| │ ├── gitignore | ||
| │ ├── license | ||
| │ ├── rename | ||
| │ ├── set-default | ||
| │ ├── sync | ||
| │ ├── unarchive | ||
| │ └── view | ||
| ├── cache # Actions caches | ||
| │ ├── delete | ||
| │ └── list | ||
| ├── run # Workflow runs | ||
| │ ├── cancel | ||
| │ ├── delete | ||
| │ ├── download | ||
| │ ├── list | ||
| │ ├── rerun | ||
| │ ├── view | ||
| │ └── watch | ||
| ├── workflow # Workflows | ||
| │ ├── disable | ||
| │ ├── enable | ||
| │ ├── list | ||
| │ ├── run | ||
| │ └── view | ||
| ├── agent-task # Agent tasks | ||
| ├── alias # Command aliases | ||
| │ ├── delete | ||
| │ ├── import | ||
| │ ├── list | ||
| │ └── set | ||
| ├── api # API requests | ||
| ├── attestation # Artifact attestations | ||
| │ ├── download | ||
| │ ├── trusted-root | ||
| │ └── verify | ||
| ├── completion # Shell completion | ||
| ├── config # Configuration | ||
| │ ├── clear-cache | ||
| │ ├── get | ||
| │ ├── list | ||
| │ └── set | ||
| ├── extension # Extensions | ||
| │ ├── browse | ||
| │ ├── create | ||
| │ ├── exec | ||
| │ ├── install | ||
| │ ├── list | ||
| │ ├── remove | ||
| │ ├── search | ||
| │ └── upgrade | ||
| ├── gpg-key # GPG keys | ||
| │ ├── add | ||
| │ ├── delete | ||
| │ └── list | ||
| ├── label # Labels | ||
| │ ├── clone | ||
| │ ├── create | ||
| │ ├── delete | ||
| │ ├── edit | ||
| │ └── list | ||
| ├── preview # Preview features | ||
| ├── ruleset # Rulesets | ||
| │ ├── check | ||
| │ ├── list | ||
| │ └── view | ||
| ├── search # Search | ||
| │ ├── code | ||
| │ ├── commits | ||
| │ ├── issues | ||
| │ ├── prs | ||
| │ └── repos | ||
| ├── secret # Secrets | ||
| │ ├── delete | ||
| │ ├── list | ||
| │ └── set | ||
| ├── ssh-key # SSH keys | ||
| │ ├── add | ||
| │ ├── delete | ||
| │ └── list | ||
| ├── status # Status overview | ||
| └── variable # Variables | ||
| ├── delete | ||
| ├── get | ||
| ├── list | ||
| └── set | ||
| ``` |
There was a problem hiding this comment.
Add a language hint to the CLI structure code fence.
The block starts with ``` but no language, which violates MD040 and may fail markdownlint. Add a language (e.g., text) to silence the warning.
💡 Suggested fix
-```
+```text
gh # Root command
├── auth # Authentication
...
└── variable # Variables
├── delete
├── get
├── list
└── set
-```
+```🧰 Tools
🪛 markdownlint-cli2 (0.20.0)
[warning] 70-70: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents
In @.agents/skills/gh-cli/SKILL.md around lines 70 - 265, The fenced ASCII CLI
structure block starting with the line "gh # Root
command" uses a bare code fence; update the opening fence from ``` to ```text to
provide a language hint (leave the block contents unchanged and keep the closing
fence as ```), which will satisfy markdownlint MD040.
- Add context to Drive API calls in FetchComments - Add blank line before comments section in converter - Escape markdown special chars in author names - Update README to reflect comments feature status
Closes #2
Adds a
--commentsflag that fetches document comments via the Google Drive Comments API and appends them as a## Commentssection at the end of the markdown output.What it does
drive.readonlyscope)Example output
Changes
internal/gdocs/comments.go— Fetch comments via Drive APIinternal/markdown/comments.go— Render comments as markdowninternal/markdown/comments_test.go— 14 test casesinternal/auth/oauth.go— Adddrive.readonlyscopecmd/gdocs-cli/main.go— Add--commentsflag and wiringREADME.md— Document the flag and scope requirementsThe new
drive.readonlyscope means existing users need to delete~/.config/gdocs-cli/token.jsonand re-authenticate with--initto grant the new permission.Summary by CodeRabbit
New Features
Documentation
Tests
Chores