-
Notifications
You must be signed in to change notification settings - Fork 60
ci: send analytics to posthog #291
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
Conversation
|
Warning Rate limit exceeded@fadeev has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 21 seconds before requesting another review. ⌛ 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. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a scheduled daily trigger to the analytics workflow; refactors the repo-count step to use GitHub Code Search and emit a numeric Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Scheduler as Cron (00:00 UTC)
actor User as Manual dispatch
participant Runner as GitHub Actions Runner
participant CodeSearch as GitHub Code Search API
participant PostHog as PostHog API
Scheduler->>Runner: Trigger workflow
User-->>Runner: Optional manual dispatch
rect rgba(230,240,255,0.5)
Runner->>CodeSearch: Search code for "GatewayZEVM.sol"
CodeSearch-->>Runner: Search results (repo list)
Runner->>Runner: Count distinct repos -> set output `count`
end
alt count available AND previous step success
rect rgba(235,255,235,0.5)
Runner->>Runner: Read `secrets.POSTHOG_API_KEY`, `vars.POSTHOG_HOST` (fallback)
Runner->>PostHog: POST event "universal_contracts_count" with properties.count
PostHog-->>Runner: Response (2xx / non-2xx)
end
else Missing API key or failed count
Note over Runner: Skip PostHog step
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes ✨ Finishing Touches🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
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: 1
🧹 Nitpick comments (4)
.github/workflows/analytics.yaml (4)
4-5: Schedule looks good; consider guardrails for overlaps.The daily cron at 00:00 UTC is appropriate. Optionally add a workflow/job-level concurrency group and a job timeout to avoid overlapping runs if a previous one hangs.
Example (at workflow root or under the job):
+concurrency: + group: universal-contracts-analytics + cancel-in-progress: false + jobs: count-contracts: + timeout-minutes: 10
25-30: Tighten the run condition to ensure a numeric count.Guard against malformed output by validating the count as a non-negative number in the
if:expression.- if: ${{ success() && steps.count.outputs.count != '' }} + if: ${{ success() && steps.count.outputs.count != '' && fromJSON(steps.count.outputs.count) >= 0 }}
36-38: Sensible default host; optionally validate.Defaulting to
https://us.i.posthog.comis standard. Optionally ensurePOSTHOG_HOSTstarts withhttps://to avoid misconfiguration.Example:
- HOST="${POSTHOG_HOST:-https://us.i.posthog.com}" + HOST="${POSTHOG_HOST:-https://us.i.posthog.com}" + case "$HOST" in https://*) ;; *) echo "Invalid POSTHOG_HOST: $HOST" >&2; exit 1;; esac
39-46: Retain the/i/v0/e/endpoint per PostHog docs; augmentcurlwith--connect-timeout 5 --max-time 15and--retry 3 --retry-delay 2 --retry-connrefused, and include an ISO8601timestampplus minimal GitHub Actions context (repo,workflow,run_id,run_attempt) in the event payload.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
.github/workflows/analytics.yaml(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
- GitHub Check: test (examples/token)
- GitHub Check: test (examples/call)
- GitHub Check: test (examples/swap)
- GitHub Check: test (examples/hello)
- GitHub Check: test (examples/nft)
- GitHub Check: test (examples/call)
- GitHub Check: test (examples/token)
- GitHub Check: test (examples/nft)
- GitHub Check: test (examples/swap)
- GitHub Check: test (examples/hello)
- GitHub Check: Cursor Bugbot
- GitHub Check: slither (examples/swap, swap.sarif)
- GitHub Check: slither (examples/hello, hello.sarif)
- GitHub Check: slither (examples/call, call.sarif)
- GitHub Check: slither (examples/swap, swap.sarif)
- GitHub Check: slither (examples/call, call.sarif)
- GitHub Check: slither (examples/hello, hello.sarif)
🔇 Additional comments (2)
.github/workflows/analytics.yaml (2)
15-16: Clear step naming and stable step id.Good use of a descriptive name and stable
id: countfor downstream outputs.
31-35: Graceful skip on missing API key.Good defensive check and early exit without leaking secrets.
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: 0
♻️ Duplicate comments (1)
.github/workflows/analytics.yaml (1)
20-23: Good: pagination, URL-encoding, and headers — addresses prior undercount risk.Nice fix; this resolves the earlier pagination concern.
Also applies to: 31-47, 55-76
🧹 Nitpick comments (6)
.github/workflows/analytics.yaml (6)
31-76: Guard against 1,000-result Search API cap and secondary rate limits.GitHub Search API returns at most 1,000 results; beyond that, pagination silently truncates. Also, secondary rate limits can cause transient 403s. Add a warning when total_count ≥ 1000 and a basic jittered retry on rate-limit messages.
Apply:
fetch_repos() { local query="$1" local out="$2" local page=1 echo "Fetching repos for query: $query" while :; do local encoded encoded=$(jq -rn --arg q "$query" '$q|@uri') local resp local url="https://api.github.com/search/code?q=${encoded}&per_page=${PER_PAGE}&page=${page}" echo "Requesting page ${page}: ${url}" - resp=$(curl -sS \ + resp=$(curl -sS \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ "$url") # If the API returns an error with a message, surface it for debugging local message message=$(echo "$resp" | jq -r '.message // empty') if [ -n "$message" ]; then echo "GitHub API message: $message" >&2 + # Handle rate limits with a short backoff and retry + if echo "$message" | grep -qiE 'rate limit|secondary rate'; then + sleep $(( (RANDOM % 5) + 5 )) + continue + fi fi + # Warn if hitting the 1,000-result cap + if [ "$page" -eq 1 ]; then + local total + total=$(echo "$resp" | jq -r '.total_count // 0') + if [ "$total" -ge 1000 ]; then + echo "Warning: total_count=$total; GitHub Search API caps at 1000 results. Count may under-report." >&2 + fi + fi
63-67: Preferrepository.full_namefor stable dedupe; format URLs only when printing.Using
full_nameavoids protocol/host variations and trims log volume.- echo "$resp" | jq -r '.items[].repository.html_url' >> "$out" - local page_repos - page_repos=$(echo "$resp" | jq -r '.items[].repository.html_url' | sort -u | wc -l | tr -d ' ') + echo "$resp" | jq -r '.items[].repository.full_name' >> "$out" + local page_repos + page_repos=$(echo "$resp" | jq -r '.items[].repository.full_name' | sort -u | wc -l | tr -d ' ')If you still want URLs in logs, convert at print time:
awk -v OFS= '/' '{print "https://github.com/"$0}'.
78-83: Optional: decide whether to include forks.Including forks inflates counts. If you intend to exclude them, add
fork:falseto the query; or gate via an env flag.- BASE_QUERY='"@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM.sol" in:file' + BASE_QUERY='"@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM.sol" in:file fork:false'
84-84: Remove trailing whitespace to satisfy yamllint.Line 84 has a trailing space.
- sort -u "$TMP" + sort -u "$TMP"
90-111: Harden PostHog POST with timeouts and retries; keep logs quiet.Add sane network timeouts and limited retries to avoid flaky failures; also avoid printing the entire response.
- | curl -s -f -X POST "$HOST/i/v0/e/" -H "Content-Type: application/json" --data-binary @- + | curl -Ssf -X POST "$HOST/i/v0/e/" \ + -H "Content-Type: application/json" \ + --data-binary @- \ + --connect-timeout 5 --max-time 15 \ + --retry 3 --retry-all-errors --retry-delay 2
84-88: Consider trimming debug output to keep logs small.Printing the full unique list each run can be noisy; omit or guard behind an env flag.
- sort -u "$TMP" + if [ -n "${VERBOSE:-}" ]; then sort -u "$TMP"; fi
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
.github/workflows/analytics.yaml(2 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/analytics.yaml
[error] 84-84: trailing spaces
(trailing-spaces)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: slither (examples/call, call.sarif)
- GitHub Check: slither (examples/swap, swap.sarif)
- GitHub Check: slither (examples/hello, hello.sarif)
- GitHub Check: test (examples/call)
- GitHub Check: test (examples/swap)
- GitHub Check: test (examples/nft)
- GitHub Check: test (examples/token)
- GitHub Check: slither (examples/call, call.sarif)
- GitHub Check: slither (examples/swap, swap.sarif)
- GitHub Check: slither (examples/hello, hello.sarif)
🔇 Additional comments (1)
.github/workflows/analytics.yaml (1)
3-6: Cron schedule looks correct (UTC).Daily 00:00 UTC trigger with workflow_dispatch retained. LGTM.
Daily count universal contracts on GitHub and send data to Posthog.
Summary by CodeRabbit