Skip to content

Conversation

@fadeev
Copy link
Member

@fadeev fadeev commented Sep 1, 2025

Daily count universal contracts on GitHub and send data to Posthog.

Screenshot 2025-09-01 at 18 22 07

Summary by CodeRabbit

  • Chores
    • Added a daily scheduled workflow at 00:00 UTC; manual trigger remains available.
    • Runs a repository count via GitHub code search and exposes the numeric result to subsequent steps.
    • Sends the count to the analytics platform as an event; skips gracefully if credentials are missing and defaults to a sensible host when unspecified.
    • Improved workflow step naming and structure for clearer execution and observability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 8660e32 and 8784762.

📒 Files selected for processing (1)
  • .github/workflows/analytics.yaml (2 hunks)
📝 Walkthrough

Walkthrough

Adds a scheduled daily trigger to the analytics workflow; refactors the repo-count step to use GitHub Code Search and emit a numeric count output; and adds a conditional step to POST that count to PostHog using secrets.POSTHOG_API_KEY and vars.POSTHOG_HOST, with a default host and graceful skip if API key is absent.

Changes

Cohort / File(s) Summary
CI workflow update
.github/workflows/analytics.yaml
- Add daily schedule trigger at 00:00 UTC while keeping workflow_dispatch.
- Rename step to "Count repos using GitHub Code Search" and add id: count.
- Run a GitHub Code Search for GatewayZEVM.sol, count distinct repositories (wc -l), and set outputs.count.
- Add a conditional "Send count to PostHog" step that requires prior success and a non-empty count; reads secrets.POSTHOG_API_KEY and vars.POSTHOG_HOST (defaults to https://us.i.posthog.com), constructs JSON via jq, and posts to PostHog; skips gracefully if API key missing.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch send-analytics-to-posthog

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@fadeev fadeev marked this pull request as ready for review September 1, 2025 15:26
@fadeev fadeev requested a review from a team as a code owner September 1, 2025 15:26
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.com is standard. Optionally ensure POSTHOG_HOST starts with https:// 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; augment curl with --connect-timeout 5 --max-time 15 and --retry 3 --retry-delay 2 --retry-connrefused, and include an ISO8601 timestamp plus 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 956dabf and 80f4c2c.

📒 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: count for downstream outputs.


31-35: Graceful skip on missing API key.

Good defensive check and early exit without leaking secrets.

@fadeev fadeev marked this pull request as draft September 1, 2025 15:34
@fadeev fadeev marked this pull request as ready for review September 1, 2025 15:53
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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: Prefer repository.full_name for stable dedupe; format URLs only when printing.

Using full_name avoids 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:false to 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 80f4c2c and 8660e32.

📒 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.

@fadeev fadeev merged commit f3f9c52 into main Sep 19, 2025
23 checks passed
@fadeev fadeev deleted the send-analytics-to-posthog branch September 19, 2025 10:47
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.

3 participants