Skip to content

Add optional Xquik search backend#3

Open
kriptoburak wants to merge 4 commits into
paoloanzn:mainfrom
kriptoburak:codex/add-xquik-search-backend
Open

Add optional Xquik search backend#3
kriptoburak wants to merge 4 commits into
paoloanzn:mainfrom
kriptoburak:codex/add-xquik-search-backend

Conversation

@kriptoburak

@kriptoburak kriptoburak commented Jun 21, 2026

Copy link
Copy Markdown

Summary

  • Add opt-in Xquik tweet search via --backend xquik.
  • Map Xquik tweet results into the existing timeline printer.
  • Keep the current X backend as the default path.

Validation

  • go test ./...

Duplicate and policy checks

  • Checked memory, default branch, and all-state PRs and issues for Xquik, x-twitter-scraper, and xquik.com. No duplicate found.
  • MIT license metadata present.
  • No README or badge-link changes.

Summary by CodeRabbit

  • New Features
    • Added configurable search backend selection with new Xquik backend support.
    • Users can now specify --backend flag to choose between available search backends.
    • Xquik backend supports top and latest search types for tweet searches.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kriptoburak, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 38 minutes and 29 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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b20d79fe-64cf-436a-8783-47b7c6450100

📥 Commits

Reviewing files that changed from the base of the PR and between 0e55317 and 564495a.

📒 Files selected for processing (4)
  • cmd/search.go
  • cmd/search_test.go
  • internal/api/xquik.go
  • internal/api/xquik_test.go
📝 Walkthrough

Walkthrough

Adds a new XquikClient in internal/api/xquik.go that queries a second tweet-search API via HTTP GET, maps results to models.TimelinePage, and reads credentials from environment variables. The search command gains a --backend flag (default x) and a runSearch helper that routes to either the existing api.NewClient or the new api.NewXquikClientFromEnv.

Changes

Xquik search backend integration

Layer / File(s) Summary
XquikClient types and constructors
internal/api/xquik.go
Defines xquikSearchResponse, xquikTweet, xquikAuthor internal structs and the exported XquikClient struct. Adds NewXquikClientFromEnv (reads XQUIK_API_KEY, XQUIK_API_BASE_URL) and NewXquikClient (explicit params); both normalize the base URL, trim whitespace, and set an HTTP timeout.
XquikClient.Search, toModel, and test
internal/api/xquik.go, internal/api/xquik_test.go
Search builds a GET request with q, queryType, limit, cursor params and x-api-key header, reads the full body, errors on non-2xx, decodes JSON, maps tweets via toModel (author fields, RFC3339 timestamps), and selects NextCursor via firstNonEmpty. Test spins up an httptest server to validate request params, headers, and asserts decoded tweet/pagination fields.
Search command --backend flag and routing
cmd/search.go
Adds searchBackend variable and --backend flag (default "x"). Replaces inline api.NewClient usage with runSearch, which switches on searchBackend to instantiate either the x or xquik client, enforcing that xquik only accepts top/latest search types.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 A second API to hop and explore,
With keys from the env and a cursor for more,
--backend xquik sent the rabbit to search,
No empty strings left the query to lurch.
firstNonEmpty picked the path just right—
Two backends now ready to query by night! 🌙

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding support for an optional Xquik search backend. It is concise and directly reflects the primary objective of the PR.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/search.go (1)

61-63: ⚡ Quick win

Use normalized product for xquik type gating.

Line 61 checks global searchType instead of the parsed product argument already passed to runSearch. This creates avoidable hidden coupling and can drift from parser behavior.

💡 Suggested fix
-		if searchType != "top" && searchType != "latest" {
+		if product != "Top" && product != "Latest" {
 			return models.TimelinePage{}, nil, fmt.Errorf("xquik backend supports tweet search only")
 		}
🤖 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 `@cmd/search.go` around lines 61 - 63, The xquik type gating check on line 61
references the global searchType variable instead of using the product parameter
already passed to the runSearch function. Replace the searchType variable with
the product parameter in the conditional check to use the normalized argument
and avoid hidden coupling with global state.
🤖 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 `@internal/api/xquik.go`:
- Around line 97-103: The io.ReadAll call on resp.Body reads an unbounded
response from an external backend, creating an out-of-memory risk from large or
malicious payloads. Wrap resp.Body with io.LimitReader to set a maximum size
limit before passing it to io.ReadAll. This ensures that responses exceeding the
configured limit are rejected before attempting to read them into memory,
protecting against memory exhaustion attacks.

---

Nitpick comments:
In `@cmd/search.go`:
- Around line 61-63: The xquik type gating check on line 61 references the
global searchType variable instead of using the product parameter already passed
to the runSearch function. Replace the searchType variable with the product
parameter in the conditional check to use the normalized argument and avoid
hidden coupling with global state.
🪄 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: 037f65b4-5604-4a43-8cd9-848ea0d6b7d4

📥 Commits

Reviewing files that changed from the base of the PR and between 5fa26f6 and 0e55317.

📒 Files selected for processing (3)
  • cmd/search.go
  • internal/api/xquik.go
  • internal/api/xquik_test.go

Comment thread internal/api/xquik.go Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0e55317cdb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cmd/search.go
searchCmd.Flags().IntVar(&searchCount, "count", 20, "Number of results")
searchCmd.Flags().StringVar(&searchCursor, "cursor", "", "Pagination cursor")
searchCmd.Flags().StringVar(&searchType, "type", "top", "Search type: top, latest, people, media")
searchCmd.Flags().StringVar(&searchBackend, "backend", "x", "Search backend: x or xquik")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the backend in pagination hints

When users run x-cli search ... --backend xquik, the next-page hint still omits this new flag and prints a command that defaults back to the x backend. Following that hint sends the opaque Xquik cursor to the existing GraphQL search path, so pagination either fails or fetches the wrong backend; include --backend xquik in the printed command when the non-default backend is selected.

Useful? React with 👍 / 👎.

Comment thread internal/api/xquik.go
}

func (tweet xquikTweet) toModel() *models.Tweet {
return &models.Tweet{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve Xquik tweet metrics in model mapping

The Xquik search schema returns engagement and media fields on SearchTweet (https://docs.xquik.com/openapi.yaml), but this conversion only populates id, text, author, and time. In pretty output, output.printTweetPretty suppresses zero-value stats, so tweets returned by --backend xquik display as if they have no likes, reposts, replies, views, or media even when the API returned them.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant